Cov txheej txheem:

NODEMCU LUA ESP8266 Nrog MCP23008 8 Bit Port Expander IC: 6 Kauj Ruam
NODEMCU LUA ESP8266 Nrog MCP23008 8 Bit Port Expander IC: 6 Kauj Ruam

Video: NODEMCU LUA ESP8266 Nrog MCP23008 8 Bit Port Expander IC: 6 Kauj Ruam

Video: NODEMCU LUA ESP8266 Nrog MCP23008 8 Bit Port Expander IC: 6 Kauj Ruam
Video: ESP8266 NodeMCU Interface - MCP23017 i/o expender with LED Example! 2024, Kaum ib hlis
Anonim
NODEMCU LUA ESP8266 Nrog MCP23008 8 Qhov Chaw Nres Nkoj Expander IC
NODEMCU LUA ESP8266 Nrog MCP23008 8 Qhov Chaw Nres Nkoj Expander IC

MCP23008 yog 8-Bit I/O Expander nrog Serial Interface thiab ua haujlwm nruab nrab ntawm 1.8 thiab 5.5 volts, yog li ntawd zoo tagnrho rau ESP8266, Arduino, Raspberry Pi, PIC Chips thiab ntau dua.

Yog tias koj tau pom kuv lwm Cov Lus Qhia ntawm MCP23017, koj yuav xav tsis thoob vim li cas kuv tseem tab tom ua ib qho rau MCP23008, vim nws yog qhov tseeb me me ntawm qhov qub.

Qhov laj thawj yog tias nws cov ntawv sau npe sib txawv ob qho tib si hauv lub npe thiab tus lej thiab kuv xav qhia seb yuav siv lub tsev qiv ntawv npaj ua qauv li cas. Tsis yog txhua tus muaj kev paub zoo thaum siv NodeMCU lua, yog li kuv xav qhia qhov kev ua haujlwm zoo li no thiab siv MCP23008 li cas.

Lub tsev qiv ntawv thiab cov haujlwm muaj nyob ntawm github.com.

Cov ntawv rau MCP23008 muaj los ntawm Microchip.

Kauj Ruam 1: Txuas MCP23008

Txuas xov tooj MCP23008
Txuas xov tooj MCP23008

MCP23008 IC yog tus qauv yooj yim thiab tsim lub rooj tsavxwm yog qhov yooj yim rau nws. Koj tseem tuaj yeem teeb tsa Circuit Court ntawm lub rooj mov ci.

Pin Txuas ntawm kuv lub rooj tsavxwm

  • Pin 18 (VDD) to 3v3
  • Pin 9 (VSS) to GND
  • Pin 7 (NC) to GND (Tsis tsim nyog)
  • Pin 1 (SCL) to ESP GPIO2
  • Pin 2 (SDA) to ESP GPIO0
  • Pin 5 (A0) to GND
  • Pin 4 (A1) to GND
  • Pin 3 (A2) to GND
  • Pin 6 (RESET) rau 3v3

Txuas cov pins los nyeem rau Gnd ntawm Chaw nres nkoj A (pins 10 - 17)

Nco tseg: ntawm no txhua qhov chaw nyob txuas nrog Gnd siv MCP23008 ntawm chaw nyob 0x20 ntawm I2C chaw nyob npav.

Yog tias koj siv chaw nyob 0x21 ces A0 yuav txuas nrog 3.3V, nrog A1 & A2 txuas nrog Gnd.

Ib yam li yog siv chaw nyob 0x22 ces A1 yuav tsum txuas nrog 3.3V nrog A0 thiab A2 txuas nrog Gnd.

lwm yam …

Kauj Ruam 2: Tsim Pawg Thawj Coj

Tsim Pawg Thawj Coj
Tsim Pawg Thawj Coj

Kuv siv 25 mm x 64 mm (9 kab x 25 qhov) Vero strip board los tsim kuv lub rooj tsavxwm. Nws yog qhov nruj me ntsis, tab sis raws li feem ntau ntawm cov pins koj xav tau nyob ntawm ob sab ntawm IC, nws tsim nyog rau yam nws yuav tsum tau ua.

Kuv tau siv 8 tus pin thiab 8 lub taub hau ntsaws rau chaw nres nkoj A kom kuv tuaj yeem ntsaws rau hauv kuv cov qauv ntau yam ntxiv rau lwm txoj hlua rau cov haujlwm sib txawv. Kuv tau ntxiv Gnd ntxiv thiab 3.3V tus pin raws li kuv pom muaj ib txwm tsis txaus ntawm cov no thaum txuas cov qauv ua ke.

Kauj Ruam 3: Siv Lub Tsev Qiv Ntawv Qub

Siv Lub Tsev Qiv Ntawv Qub
Siv Lub Tsev Qiv Ntawv Qub

Cov tsev qiv ntawv cov qauv ib txwm muaj kev xaiv ntawm cov txheej txheem ib txwm muaj, cov haujlwm thiab cov hloov pauv uas tuaj yeem nkag mus los ntawm lwm txoj haujlwm. Qhov haujlwm nws tus kheej tsis ua haujlwm, tab sis nws lub luag haujlwm tuaj yeem nkag mus los ntawm kev hu xov tooj. Nws txhais tau tias koj tuaj yeem muaj koj cov txheej txheem ib txwm nyob hauv lub tsev qiv ntawv thiab hu lawv thaum twg koj xav tau, ua qhov program hu me me. Nws dhau los muaj txiaj ntsig ntau yog tias koj muaj ntau qhov haujlwm sib txawv uas siv tib txoj haujlwm ib txwm ua, koj tsis tas yuav suav nrog cov kev ua haujlwm niaj hnub hauv txhua qhov haujlwm.

Nco tseg: qhov program mcp23008.lua yuav tsum tau rub rau hauv ESP8266 nco zoo li lwm cov haujlwm.

Kuv tau suav nrog github.com cov haujlwm ntawm no nrog rau qhov program yooj yim (test.lua) los qhia tias lub tsev qiv ntawv ua haujlwm.

Muaj tsawg kawg 2 txoj hauv kev suav nrog lub tsev qiv ntawv hauv koj qhov program.

xav tau ("mcp23008")

mcp23008.begin (0x0, gpio2, gpio0, i2c. SLOW)

los yog

mcp = xav tau ("mcp23008")

mcp.begin (0x0, gpio2, gpio0, i2c. SLOW)

Ob qho ntawm qhov saum toj no ua tib yam nkaus, tab sis txoj kev thib ob tso cai rau koj siv koj tus kheej qhov txawv txav tsis txhob siv lub npe program.

Kauj Ruam 4: Kitt Tsheb Txoj Haujlwm

Kitt Tsheb Program
Kitt Tsheb Program

Kuv tau suav nrog KittCar23008.lua program thiab KittLib.lua uas siv lub tsev qiv ntawv los qhia qhov sib txawv ntawm kev sau cov haujlwm li cas. Ob txoj haujlwm ua tib yam nkaus.

Lub 8 LED ntsaws rau hauv yog muaj los ntawm Ebay ua cov khoom siv thiab paub tias yog 8 Channel Flowing Water Light LED DIY Kit, 99p los ntawm Tuam Tshoj. Koj yuav tsum tau solder koj tus kheej.

Nco tseg: Yog tias koj muaj teeb meem sim ua KittLib.lua program, sim txuas MCP23008 RESET tus pin rau Gnd ib ntus. Kuv paub qhov no yuav ua rau luv luv Circuit Court (raws li nws tau txuas nrog 3.3V) thiab koj yuav tsum rov pib dua txhua yam ntxiv. Nws kuj tseem ua haujlwm los ntawm kev txuas rau Gnd los ntawm 10 ohm resistor, tej zaum yog txoj hauv kev zoo dua los ua nws.

Kuv kuj pom tias KittLib.lua yuav khiav tsis muaj teeb meem tom qab khiav test.lua (Tsis txhob nug kuv vim li cas?)

Kuv tau sim ntau txoj hauv kev los daws qhov teeb meem KittLib.lua, tab sis tam sim no tsis tuaj yeem pom ib qho laj thawj vim li cas nws thiaj li tsoo. Dose leej twg muaj tswv yim?

Kuv tsis tau sau tag nrho cov program no kuv tus kheej, yog li kuv tsis tuaj yeem hais tias yog vim li cas thiaj muaj teeb meem, txawm hais tias tom qab saib cov coding, zoo li tsis muaj dab tsi pom tseeb tseeb.

Kauj Ruam 5: 7 Segment LED

7 Ntu LED
7 Ntu LED

Raws li nrog KittCar.lua txoj haujlwm saum toj no, Kuv tau suav nrog ib leeg thiab ib lub tsev qiv ntawv nyob rau qhov kev zov me nyuam kom tsav 7 ntu LED zaub.

Ib zaug ntxiv, ob txoj haujlwm ua tib yam nkaus, tab sis qhia ua li cas siv lub tsev qiv ntawv qauv sau los ntawm koj tus kheej lossis lwm tus.

Kauj Ruam 6: Xaus

Xaus
Xaus

Kuv tau sim ua kom pom tias yuav siv tus lej lej li cas hauv Lua ib puag ncig, thiab siv nws rau IC tshwj xeeb tib lub sijhawm.

Txawm hais tias kuv tau muaj teeb meem ua qhov no, Kuv xav tias muaj txaus los qhia tias cov qauv no ua haujlwm li cas thiab qhia txog kev thov lub neej tiag tiag.

Pom zoo: