-
-
Save electricbaka/cf363bc066ab5a92cd7b3a1e737d4520 to your computer and use it in GitHub Desktop.
モーション起動スイッチで超低消費電力IoT:FlashAirのファームウェア
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--SPI Init | |
function spi_init() | |
fa.spi("init", 1) --1.6MHz@W-04 | |
fa.spi("mode", 0) --MODE=0 | |
sleep(1000) | |
end | |
-- SPI Write | |
function spi_write(reg, data) | |
fa.spi("cs", 0) --CS : ON | |
fa.spi("write", 0x0A) --Reg Write | |
fa.spi("write", reg) | |
fa.spi("write", data) | |
fa.spi("cs", 1) --CS :OFF | |
sleep(100) | |
end | |
-- SPI Read | |
function spi_read(reg) | |
fa.spi("cs", 0) --CS : ON | |
fa.spi("write", 0x0B) --Reg Read | |
fa.spi("write", reg) | |
data = fa.spi("read") | |
fa.spi("cs", 1) --CS :OFF | |
sleep(100) | |
return data | |
end | |
---------- Main ---------- | |
-- SPI Initial Setting | |
spi_init() | |
-- ADXL362 Setting | |
spi_write(0x20, 0x50) -- Activity threshold Lower : 80 | |
spi_write(0x21, 0x00) -- Activity threshold Upper : 80 | |
spi_write(0x22, 0x00) -- Activity timer (only 1Byte) : 0 | |
spi_write(0x23, 0xFF) -- Inactivity threshold Lower : MAX(0x07FF) | |
spi_write(0x24, 0x07) -- Inactivity threshold Upper : MAX(0x07FF) | |
spi_write(0x25, 0x06) -- Inactivity timer Lower : 1sec | |
spi_write(0x26, 0x00) -- Inactivity timer Upper : 1sec | |
spi_write(0x27, 0x1F) -- Motion detection, activity/inactivity detection : LINK mode | |
spi_write(0x2B, 0xC0) -- INT2 MAP : AWAKE bit, set ActiveLow | |
spi_write(0x2D, 0x0E) -- Power Control : WAKEUP, AUTOSLEEP, Start measurement | |
-- Sleep 10sec | |
sleep(10000) | |
-- Send HTTP GET request | |
url_string = "https://***********************************************************************" | |
fa.request{ url = url_string, method = "GET" } | |
-- ADXL362 INT2 flag clear | |
spi_read(0x0B) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"https:// ***********************************************************************" はクラウドアプリのURLを記入すること