This document summarizes an experiment connecting various components to the terminals of a FlashAir W-04 device. It describes how the device's terminals can be used for SPI, I2C, and GPIO functions without needing to reinitialize when switching between them. It provides code examples to light an LED strip, sound a buzzer, read a switch, and an attempted but failed touch sensor reading. In conclusion, terminal sharing on the W-04 allows controlling components like LEDs and buzzers, but touch sensors require more examination.
Terminal sharing and GPIO experiments with the FlashAir W-04
1. Terminal share of
FlashAir W-04
W-04で
端子共有してみた
By さや(Saya)
FlashAir Developers Summit 2018 2018/2/24(sat)
2. Abut me
Pen name:Saya
Twitter :@La_zlo
I will scatter seeds by following my heart.
The content of this presentation is based on
hobby's challenge and simple test, and there
is no guarantee. Also, it is not an
presentation representing my organization.
Lightning Talk
3. W-04 has 5 general-
purpose terminals
-What shall we connect?
-What combination can be used
simultaneously?
-How can I control it?
I checked the behavior
of the terminals
4. Relations of terminal and the Lua functions
Reference)
·Simple SD specification (https://www.sdcard.org/downloads/pls/index.html)
·Lua function reference (https://www.flashair-developers.com/en/documents/api/lua/)
·Doujinshi of FlashAir (https://www.flashair-developers.com/en/documents/books/)
·Behavior analysis of W-04
· fa.spi() and fa.i2c(), set to a specific IO state when "init“ is executed.
· Switching from fa.pio() to fa.spi(), "init“ is NOT requires.
· Switching from fa.pio() to fa.i2c(), "init" is required.
FlashAir W-04 (V4.00.01)
fa.pio
GPIO SPI "init" I2C "init" Terminal handling
5 CLK I RSV RSV - RSV - Pull-down is preferable
2 CMD I 0x01 DO O(L) SCL I
7 DAT0 I 0x02 CLK O(*1) SDA I
8 DAT1 I 0x04 CS O(H) RSV I
9 DAT2 I 0x08 DI *2 I RSV O(H)
1 CD/DAT3 I (pull-up) 0x10 RSV *3 O(L) RSV I Avoid pull-down
4 2.7-3.6V
6 GND
3 GND
*1: "O (L)" when "mode" is 0 or 3, "O (H)" when "mode" is 1 or 2 H: High
*2: If I / O is "O", "L" is output by "write" or "read". L: Low
*3: If I / O is "O", "H" is output by "write" or "read".
after
power on
fa.spi fa.i2c
VCC
VSS2
VSS1
Pin
No.
SD standard FlashAir original function
Remarks
SD
interfase
5. Is it possible to transition
without changing the state of IO?
Power on
I2C mode
SPI modePIO mode
fa.spi(“init”,xx)fa.pio(xx,yy)
fa.pio(xx,yy)
fa.spi(“init”,xx)
fa.spi(“write”,xx)
fa.spi(“read”,xx)
fa.pio(xx,yy) fa.spi(“init”,xx)
fa.i2c{mode=“init”, …)
Card mode
Card access
SD I/F wait
6. Example of case size gadget
Soramame-18 connections
Shining, Sounding, Sensing
+3.3V
7. Wiring plan of Soramame-18
4 general-purpose terminals to use
SD standard Gadget
fa.pio assumption LED strip tact sw
Piezo
Sounder
register
GPIO SPI "init" IO setting APA102C TS-001 20mmφ 1Morm
5 CLK RSV RSV - - - - - -
2 CMD 0x01 DO O(L) O(L) DI - ◎ ○
7 DAT0 0x02 CLK O(*1) O(L) or I CI - - -
8 DAT1 0x04 CS O(H) O(H) - - - -
9 DAT2 0x08 DI *2 I I - - ○ ○
1 CD/DAT3 0x10 RSV *3 O(L) O(L) or I - ○ - -
4 - VCC 10kΩ - -
3 - GND ○ - -
6 - - - - -
VSS1
VSS2
Pin
No.
FlashAir original function Parts
SD
interfase
fa.spi
VCC
8. Lua script
■Light LED strip
■Sound buzzer
■Read the state of a switch
■Try a touch sensor
9. APA102C
Light LED strip
Full color LED lit with SPI function
No sound if it is
set as input
SPI
control
s={}
s[1] = 0x00000000
for i=1, 5 do
s[i+1] =
<brightness+BGR>
end
s[7] = 0xFFFFFFFF
fa.spi("mode",0)
fa.spi("bit",32)
fa.spi("init",1)
fa.pio(0x07,0x04)
fa.spi("write",s)
10. Sound buzzer
Vibrate piezoelectric sounder
with SPI function
output
“L”
s=string.rep(
"xAA", <sound length>)
fa.spi("mode",0)
fa.spi("bit",8)
fa.spi("init",<interval>)
fa.pio(0x0F,0x04)
fa.spi("write",s)
LED will not respond
unless you send
0x00000000
11. Read the state of a switch
Confirm switch status
with PIO function
s, t = fa.pio(0x07,0x04)
k = bit32.btest(t,0x10)
0: SW ON
1: SW OFF
12. Try a touch sensor
SMeasure response time with SPI
function ⇒Failed
fa.spi("mode",0)
fa.spi("bit",32)
fa.spi("init",1)
fa.pio(0x07,0x04)
t = fa.spi(
"write", 0x80000000)
n=0
while(t>0) do
n=n+1; t=bit32.lshift(t,1)
end
print(n)
[Reference] Arduino touch senser by KOUSAKU
(http://kousaku-kousaku.blogspot.jp/2008/10/arduino.html)
set as
input
LED will not respond
unless you send
0x00000000
13. Video Demo
Link to Twitter
https://twitter.com/search?f=videos
&q=from%3ALa_zlo%20%23FlashAir
14. Conclusion
■Switching from fa.pio() to
fa.spi() requires NO "init“
■ Terminal sharing with W-04
・Light LED strip
・Sound buzzer
・ Read the state of a switch
■Re-examination required
・ Try a touch sensor