Cov txheej txheem:

WiFi LED Sawb + Kub Sensor Nrog ESP8266: 6 Cov Kauj Ruam
WiFi LED Sawb + Kub Sensor Nrog ESP8266: 6 Cov Kauj Ruam

Video: WiFi LED Sawb + Kub Sensor Nrog ESP8266: 6 Cov Kauj Ruam

Video: WiFi LED Sawb + Kub Sensor Nrog ESP8266: 6 Cov Kauj Ruam
Video: Rafah endoscopy coin removal 322 2024, Hlis ntuj nqeg
Anonim
WiFi LED Sawb + Kub Sensor Nrog ESP8266
WiFi LED Sawb + Kub Sensor Nrog ESP8266

Cov ntawv qhia no piav qhia cov kauj ruam los teeb tsa ESP8266 thiab tau txais nws tham nrog ob lub ntsuas kub thiab LED sawb, thaum tseem tuaj yeem tau txais cov tswv yim thiab xa tawm nrog MQTT dhau WiFi. Txoj haujlwm tau ua rau chav kawm raug coj los ntawm Cal Poly San Luis Obispo thaum lub caij nplooj zeeg 2016- CPE 439: Lub Sijhawm Tiag Tiag Systems. Lub hom phiaj tag nrho yog los qhia qhov yooj yim ntawm kev tsim internet-txuas "yam" nrog cov khoom siv pheej yig.

Cov Khoom Siv/Khoom Siv Yuav Tsum Tau:

  • NodeMCU ESP8266 dev board
  • WS2812B LED sawb
  • MAX31820 Kub ntsuas
  • Cov qhob cij
  • 4.7K ohm resistor
  • 220 ohm resistor
  • jumper cov xov hlau
  • micro-usb kab
  • PC (lossis VM) khiav linux (piv txwv li Ubuntu)

Assumptions/Yam yuavtsum tau kawm uantej:

  • kev paub nrog siv cov cuab yeej hais kom ua kab thiab txhim kho pob khoom ntawm debian-based distro
  • nkag siab yooj yim ntawm Makefile syntax
  • txuas xov hlau

Kauj Ruam 1: Tsim Tsim Ib puag ncig

Txhawm rau tsim txoj haujlwm, koj yuav xav tau esp-open-sdk teeb tsa ntawm koj lub tshuab. Ua raws qhov txuas thiab nyeem cov lus qhia tsim. Hauv qhov luv koj yuav ua qee qhov sudo apt-tau txais cov lus txib txhawm rau txhim kho kev vam khom, git clone-rov ua dua rau clone/rub tawm esp-open-sdk, thiab thaum kawg ua kom hais kom tsim esp-open-sdk.

Saib Kuv

Kauj Ruam 2: Tau Txais Cov Cai, Kho, thiab Tsim

Tam sim no uas esp-open-sdk tau tsim, clone qhov project repository.

git clone

Hloov mus rau hauv cov phiaj xwm phiaj xwm, tsim cov ntawv.local, thiab luam qhov piv txwv teeb tsa.

cd esp-rtos-tests

mkdir -p.local cp settings.example.mk.local/settings.mk

Tam sim no qhib.local/settings.mk nrog cov ntawv nyeem hloov pauv thiab teeb tsa cov hauv qab no:

  • OPENSDK_ROOT: Txoj hauv kev meej rau qhov chaw ntawm esp-open-sdk koj tau ua hauv qib 1
  • WIFI_SSID: SSID ntawm koj lub network WiFi
  • WIFI_PASS: Tus password ntawm koj lub network WiFi
  • PIXEL_COUNT: Tus lej ntawm koj lub WS2812B LED sawb

Nco tseg: Txij li txoj haujlwm no siv SPI los tsav cov LEDs thiab siv NodeMCU 3.3v los muab rau lawv, tej zaum koj yuav tsis tuaj yeem tsav ntau dua ~ 60 LEDs.

Nco tseg: Lwm qhov chaw tsis tas yuav hloov pauv, tab sis tuaj yeem yog qhov xav tau. Nws raug nquahu kom khaws qhov kev txiav txim ntawm txoj haujlwm ua ntej. Qhov tsawg dua qhov muaj feem thib, qhov muaj feem thib tseem ceeb ntawm txoj haujlwm.

Tam sim no tsim qhov project:

ua -C piv txwv/cpe439

Yog tias txhua yam tau teeb tsa kom raug, nws yuav tsum pib suav sau. Thaum kawg koj yuav tsum pom:

Ua tiav tsim 'firmware/cpe439.bin'

Saib Kuv

Kauj Ruam 3: Txuas Cov Khoom Kho Vajtse

Txuas Cov Khoom Kho Vajtse
Txuas Cov Khoom Kho Vajtse

Tam sim no tias cov lej tau suav ua ke, nws yog lub sijhawm los txuas peb cov khoom siv hluav taws xob.

Ua ntej, lo rau NodeMCU rau ntawm daim ntawv tais, tom qab ntawd siv cov hlua txuas los ua qhov sib txuas raws li qhia hauv daim duab.

Ob peb yam yuav tsum paub txog:

  1. Tseem ceeb: WS2812B cov ntaub ntawv kab ntawv tsis yog ob txoj kev. Yog tias koj saib ze ntawm cov cim ntawm LED sab ntawm kab txaij, koj yuav tsum pom me xub xub taw qhia ib qho. Cov zis los ntawm D7 ntawm NodeMCU yuav tsum tau mus rau hauv WS2812B tib yam nkaus li cov cim taw qhia, uas koj tuaj yeem pom hauv daim duab yog tias koj saib ze.
  2. Nyob ntawm seb yam khoom sib txuas koj li WS2812B los nrog, koj yuav tsum tau ua qee qhov kev hloov kho kom lawv txuas tau ruaj ntseg rau hauv lub khob cij. Koj kuj tseem tuaj yeem siv tus nab kuab txuas los txuas lawv mus rau lub khob cij uas muaj peev xwm txuas tau cov hlua.
  3. MAX31820 tus pin muaj lub suab me dua thiab thinner dua tus qauv 0.1 "/2.54mm dhia, ua rau lawv tsis yooj yim los txuas. tom qab ntawd siv qee lub pliers txhawm rau txhawm rau tus poj niam jumper xaus nruj nyob ib puag ncig me me MAX31820 tus pin.

Txheeb xyuas ob qho kev sib txuas ua ntej tso lub NodeMCU kom tsis txhob puas lub Cheebtsam.

Kauj ruam 4: Nyem thiab Khiav

Flashing

Nrog txhua qhov kho vajtse txuas nrog, ntsaws rau hauv koj NodeMCU thiab nyem nrog cov lus txib hauv qab no:

ua flash -C piv txwv/cpe439 ESPPORT =/dev/ttyUSB0

/dev/ttyUSB0 yog tus lej com NodeMCU yuav tsum tshwm nyob rau hauv. Yog tias koj muaj lwm cov khoom siv txuas nrog, nws tuaj yeem pom zoo li /dev /ttyUSB1 lossis qee tus lej. Txhawm rau txheeb xyuas koj tuaj yeem ua cov lus txib no ob zaug, ib zaug nrog NodeMCU tsis txuas, thiab ib zaug nrog nws ntsaws, thiab sib piv qhov sib txawv:

ls /dev /ttyUSB*

Lwm qhov teeb meem koj yuav ntsib yog tsis muaj kev tso cai nkag mus rau lub cuab yeej. Ob txoj hauv kev los kho qhov no yog:

  1. Ntxiv koj cov neeg siv rau pawg dialout:

    sudo adduser $ (whoami) dialout

  2. chmod lossis chown lub cuab yeej:

sudo chmod 666 /dev /ttyUSB0 sudo chown $ (whoami): $ (whoami) /dev /ttyUSB0Thawj txoj hauv kev yog qhov nyiam vim nws yog kev daws teeb meem tas mus li.

Khiav

Tom qab khiav lub flash hais kom ua tiav, lub cuab yeej yuav khau raj tam sim ntawd thiab pib ua haujlwm ua ke cov lej. Txhua lub sijhawm tom qab flashing koj tuaj yeem khiav cov lus txib hauv qab no los saib cov ntawv tso tawm:

python3 -m serial.tools.miniterm --eol CRLF --exit -char 003 /dev /ttyUSB0 500000 --raw -q

Txhawm rau txuag sijhawm koj tuaj yeem ntxiv qhov no rau koj ~/.bashrc cov ntaub ntawv:

alias nodemcu = 'python3 -m serial.tools.miniterm --eol CRLF --exit -char 003 /dev /ttyUSB0 500000 --raw -q'

.. uas tso cai rau koj yooj yim ntaus "nodemcu" raws li lub npe tsis raug rau qhov hais kom ua.

Yog tias txhua yam tau teeb tsa kom raug, koj cov hlua LED yuav tsum ci ntsuab, thiab ntawm cov lej koj yuav tsum pom WiFi txuas, tau txais tus IP chaw nyob, txuas rau MQTT, thiab cov lus uas kub cov ntaub ntawv raug thawb tawm.

txuas nrog MyWiFiSSID, channel 1dhcp tus neeg siv pib… wifi_task: xwm txheej = 1wifi_task: xwm txheej = 1ip: 192.168.2.23, daim npog: 255.255.255.0, gw: 192.168.2.1ws2812_spi_init okRequest temp OKwifi_task: xwm txheej = 5xQueue Quest_taskx4Queqtmus4_task: (Re) txuas rau MQTT server test.mosquitto.org… xQueueReceive +25.50xQueueSend ok ua tiav Xa MQTT txuas… MQTTv311donexQueueReceive +25.56 xQueueSend ok

Kauj ruam 5: Sib tham

Piv txwv tias koj lub cuab yeej txuas nrog WiFi thiab MQTT tus ua lag luam ua tiav, koj yuav tuaj yeem xa thiab tau txais cov ntaub ntawv los ntawm NodeMCU nrog MQTT. Yog tias koj tsis tau ua tiav, teeb tsa pob cov neeg siv khoom mos txwv:

sudo apt-tau nruab mosquitto-cov neeg siv khoom

Tam sim no koj yuav tsum tuaj yeem siv cov mosquitto_pub thiab mosquitto_sub cov haujlwm los ntawm koj lub plhaub.

Tau txais qhov hloov tshiab kub

Txhawm rau kom tau txais cov ntaub ntawv ntsuas kub peb yuav xav siv lub mosquitto_sub hais kom sau npe rau lub ncauj lus uas NodeMCU tau tshaj tawm rau.

mosquitto_sub -h test.mosquitto.org -t /cpe439 /temp

Koj yuav tsum pom cov ntaub ntawv ntsuas kub (hauv Celsius), tuaj txog hauv lub davhlau ya nyob twg.

+25.87+25.93+25.68…

Teeb lub teeb LED kab xim nyob deb

Cov lus yooj yim siv los xa RGB qhov tseem ceeb rau NodeMCU hla MQTT. Cov lus txib hom zoo li no:

r: RRRg: GGGb: BBB ~

Qhov twg RRR, GGG, BBB sib raug rau RGB qhov tseem ceeb (0-255) ntawm cov xim koj xav xa. Txhawm rau xa peb cov lus txib, peb yuav siv cov lus txib mosquitto_pub. Nov yog qee qhov piv txwv:

mosquitto_pub -h test.mosquitto.org -t /cpe439 /rgb -m 'r: 255g: 0b: 0 ~' # redmosquitto_pub -h test.mosquitto.org -t /cpe439 /rgb -m 'r: 0g: 255b: 0 ~ ' # greenmosquitto_pub -h test.mosquitto.org -t /cpe439 /rgb -m' r: 0g: 0b: 255 ~ ' # xiav

Yog tias koj xav tau kev muaj tswv yim, nrhiav tus neeg xaiv xim online zoo li qhov no, thiab kho qhov hais kom ua nrog tus nqi RGB koj xaiv.

Saib Xyuas

Cov ncauj lus hauv txoj haujlwm no tau teeb tsa rau /cpe439 /rgb thiab /cpe439 /temp ntawm pej xeem MQTT tus broker, uas txhais tau tias tsis muaj ib yam dab tsi tiv thaiv lwm tus los ntawm kev tshaj tawm lossis koom nrog rau cov ncauj lus ib yam li koj. Rau kev sim yam tawm, siv tus tswv lag luam pej xeem zoo, tab sis rau cov phiaj xwm loj dua koj yuav xav txuas nrog tus broker nrog tiv thaiv tus password, lossis khiav koj tus kheej tus broker ntawm server.

Kauj Ruam 6: Siv Cov Lus Qhia

Onewire

ESP8266 tsuas muaj 1 tus tub ntxhais, yog li ntev, thaiv cov haujlwm xws li tos 750ms rau qhov ntsuas kub kom ua qhov ntsuas kub ib txwm ua rau WiFi tsis ua haujlwm tau zoo, thiab tej zaum txawm tias muaj kev sib tsoo. Hauv FreeRTOS tus qauv, koj hu rau vTaskDelay () los tswj cov kev tos ntev no, tab sis kuj tseem muaj ntau qhov kev tos luv luv xav tau ntawm kev nyeem thiab sau ntawv uas luv dua li FreeRTOS system zuam, thiab yog li tsis tuaj yeem zam nrog vTaskDelay (). Txhawm rau kom tau txais ib puag ncig cov no, ib tus neeg tsav tsheb hauv txoj haujlwm no tau sau kom khiav tawm ntawm lub xeev-tshuab uas tau tsav los ntawm ESP8266 lub sijhawm kho vajtse, uas tuaj yeem ua rau muaj xwm txheej tsawg li txhua 10 micro-vib nas this, uas tshwm sim kom luv tshaj plaws yuav tsum muaj sijhawm nyob nruab nrab ntawm ib txoj haujlwm nyeem/sau ntawv. Feem ntau lwm qhov kev siv siv thaiv kev hu mus rau ncua_us () lossis zoo ib yam los tswj qhov no, tab sis yog tias koj tab tom ntsuas qhov ntsuas kub tas li, txhua qhov kev ncua no pib ntxiv, ua rau daim ntawv thov tsis teb sai. Lub hauv paus rau qhov feem ntawm cov cai no nyob hauv cov ntawv ntxiv/onewire.

TWS 2812B

ESP8266 tsis muaj cov txheej txheem kho vajtse xaiv rau PWM nrawm txaus los tsav cov kab hluav taws xob LED ntawm 800KHz. Txhawm rau kom tau txais qhov no, txoj haujlwm no siv tus pin SPI MOSI los tsav cov LEDs. Los ntawm kev kho lub moos tus nqi ntawm SPI, thiab hloov pauv SPI them nyiaj ib puag ncig, koj tuaj yeem ua tiav kev tswj hwm kev ntseeg tau ntawm txhua tus neeg LED. Txoj hauv kev no tsis yog tsis muaj qhov tsis xws luag- rau ib qho LEDs yuav tsum tau siv nrog 5V qhov chaw thiab qib hloov pauv yuav tsum tau ntxiv rau qhov tso tawm ntawm tus pin SPI. Tab sis 3.3V ua haujlwm. Qhov thib ob, muaj qhov tsis xwm yeem uas tshwm sim vim lub sijhawm tsis zoo siv SPI txoj hauv kev. Thiab qhov thib peb yog tam sim no koj siv tsis tau SPI rau lwm yam. Ntxiv keeb kwm yav dhau los ntawm txoj hauv kev no tuaj yeem pom ntawm no, thiab qhov chaw rau feem ntawm cov cai no nyob hauv cov ntawv ntxiv/ws2812.

Ib txoj hauv kev ntseeg tau ntau dua rau kev tsav tsheb LED cov kab xev yog siv i2s. Txawm li cas los xij txoj hauv kev no muaj ntau qhov tshwj xeeb ntawm cov hacks, yog li SPI zoo li yog qhov kev xaiv zoo dua li kev kawm ua haujlwm.

Pom zoo: