Cov txheej txheem:
- Kauj ruam 1: Nkag siab txog Firmata raws tu qauv
- Kauj Ruam 2: Cia Peb Pib
- Kauj Ruam 3: Hloov Kho FirmataExpress rau Kev Txhawb DHT
- Kauj Ruam 4: Hloov Pymata4 rau DHT Txhawb
- Kauj Ruam 5: Ua kom tiav
Video: Mus Tshaj Dhau StandardFirmata - Rov Ntsuam Xyuas: 5 Cov Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:25
Ib ntus dhau los, Kuv tau ntsib los ntawm Dr. Martyn Wheeler, tus neeg siv pymata4, rau kev qhia ntxiv kev txhawb nqa rau DHT22 Vaum/Kub sensor mus rau lub tsev qiv ntawv pymata4. Lub tsev qiv ntawv pymata4, ua ke nrog nws Arduino tus khub, FirmataExpress, tso cai rau cov neeg siv tswj hwm thiab saib xyuas lawv cov cuab yeej Arduino nyob deb. Tsis pub dhau ob peb kab ntawm email sib pauv, Dr. Wheeler tau ua tiav hauv kev hloov kho ob qho tib si pymata4 thiab FirmataExpress. Raws li qhov tshwm sim, kev txhawb nqa rau DHT22 thiab DHT11 sensors tam sim no yog tus qauv ib feem ntawm pymata4 thiab FirmataExpress.
Thaum lub Tsib Hlis xyoo 2014, Kuv tau sau ib tsab xov xwm ntxiv kev txhawb nqa rau Firmata rau cov cuab yeej siv ntxiv. Rov xav txog qhov kuv tsab xov xwm, Kuv paub ntau npaum li cas tau hloov pauv txij li thaum kuv coj tus cwj mem rau ntawv rau cov ntawv ntawd. Ntxiv rau tsab xov xwm no, Dr. Wheeler sau tseg nws cov kev siv zog, thiab koj yuav xav tshuaj xyuas qhov ntawd ib yam.
FirmataExpress yog ua raws StandardFirmata, thiab StandardFirmata cov npe txheej txheem tau hloov pauv. Ib qho ntxiv, pymata4 API kuj tseem txawv me ntsis los ntawm thawj PyMata API ntawm 2014. Kuv xav tias qhov no yuav yog lub sijhawm zoo tshaj los tshuaj xyuas thiab hloov kho kab ntawv ntawd. Siv Dr. Wheeler txoj haujlwm ua lub hauv paus, cia peb tshawb xyuas yuav ua li cas txuas ntxiv pymata4/FirmataExpress kev ua haujlwm.
Ua ntej Peb Pib - Qee Cov Ntaub Ntawv Keeb Kwm Txog Arduino/Firmata
Yog li Firmata yog dab tsi? Hais los ntawm Firmata lub vev xaib, "Firmata yog cov txheej txheem dav dav rau kev sib txuas lus nrog microcontrollers los ntawm software ntawm lub tshuab computer."
Arduino Firmata siv cov lus sib txuas los thauj ob qho lus txib thiab tshaj tawm cov ntaub ntawv ntawm Arduino microcontroller thiab PC, feem ntau siv cov lej/USB txuas txuas rau 57600 bps. Cov ntaub ntawv xa mus hla qhov txuas no yog binary, thiab cov txheej txheem tau ua tiav hauv tus neeg siv khoom/tus qauv server.
Sab server tau muab tso rau Arduino microcontroller hauv daim ntawv ntawm Arduino kos duab. Tus Qauv Txuj Ci, suav nrog Arduino IDE, tswj Arduino I/O pins, raws li tau hais los ntawm tus neeg siv khoom. Nws tseem qhia txog kev hloov pauv tus lej nkag thiab lwm yam ntaub ntawv qhia rov qab rau tus neeg siv khoom. FirmataExpress yog qhov txuas ntxiv ntawm StandardFirmata. Nws khiav ntawm qhov txuas txuas ceev ntawm 115200 bps.
Cov neeg siv Arduino siv rau kab lus no yog pymata4. Nws yog Python daim ntawv thov uas ua tiav ntawm lub PC. Nws ob qho tib si xa cov lus txib rau thiab tau txais cov ntawv ceeb toom los ntawm Arduino server. Vim tias pymata4 tau ua tiav hauv Python, nws ua haujlwm ntawm Windows, Linux (suav nrog Raspberry Pi), thiab macOS khoos phis tawj.
Vim Li Cas Siv Firmata?
Arduino microcontrollers yog cov cuab yeej zoo me me, tab sis cov txheej txheem thiab cov khoom siv nco tau me ntsis. Rau cov ntawv thov uas yog cov txheej txheem lossis lub cim xeeb nrawm, feem ntau muaj kev xaiv me me tab sis tso tawm cov peev txheej xav tau mus rau PC rau daim ntawv thov kom ua tiav.
Tab sis qhov ntawd tsis yog qhov laj thawj nkaus xwb rau kev siv StandardFirmata. Thaum txhim kho qhov hnyav ntawm daim ntawv thov Arduino, lub PC tuaj yeem muab cov cuab yeej thiab kev muaj peev xwm daws teeb meem tsis ncaj qha rau ntawm Arduino microcontroller. Siv tus neeg siv "tsau" thiab cov neeg rau zaub mov pab kaw cov ntawv thov nyuaj rau lub PC, uas yog tswj tau yooj yim dua. Thaum daim ntawv thov ua tiav, nws tuaj yeem txhais ua ib qho kev cai, ib leeg kheej kheej Arduino kos duab.
Vim Li Cas Siv pymata4?
Ua nws tus kws sau ntawv, tau kawg, kuv muaj kev ntxub ntxaug. Qhov ntawd tau hais, nws tsuas yog Python-based Firmata cov neeg siv uas tau txuas ntxiv tsis tu ncua ntau xyoo dhau los. Nws muab kev nkag siab thiab yooj yim siv API. Ntxiv rau StandardFirmata raws cov duab kos, Nws txhawb Firmata hla WiFi rau cov khoom siv zoo li ESP-8266 thaum siv StandardFirmataWifI kos duab.
Tsis tas li, pymata4 tau tsim los kom yooj yim txuas ntxiv los ntawm tus neeg siv los txhawb kev ntsuas ntxiv thiab tus ua haujlwm tsis tam sim no txhawb los ntawm StandardFirmata.
Kauj ruam 1: Nkag siab txog Firmata raws tu qauv
Arduino Firmata kev sib txuas lus raws tu qauv tau muab los ntawm MIDI cov txheej txheem, uas siv ib lossis ntau dua 7-bytes los sawv cev rau cov ntaub ntawv.
Firmata tau tsim los kom siv tau-txuas ntxiv. Cov txheej txheem uas muab qhov kev nthuav dav no yog Qhov System Tshwj Xeeb (SysEx) cov txheej txheem xa xov.
Hom ntawv ntawm SysEx cov lus, raws li tau hais tseg los ntawm Firmata raws tu qauv, tau qhia hauv cov lus piav qhia saum toj no. Nws pib nrog START_SYSEX byte nrog tus nqi ruaj khov ntawm hexadecimal 0xF0, thiab ua raws los ntawm qhov tshwj xeeb SysEx hais kom ua byte. Tus nqi ntawm cov lus txib byte yuav tsum yog nyob ntawm thaj tsam ntawm hexadecimal 0x00-0x7F. Qhov hais kom ua byte yog tom qab ntawd tus lej tsis qhia meej ntawm 7-ntsis cov ntaub ntawv bytes. Thaum kawg, cov lus tau xaus nrog END_SYSEX byte, nrog tus nqi ruaj khov ntawm hexadecimal 0xF7.
Firmata Data Encoding/Decoding
Txij li cov neeg siv cov ntaub ntawv ib feem ntawm SysEx cov lus suav nrog ib kab ntawm 7-bytes, koj yuav xav li cas ib tus sawv cev tus nqi ntau dua 128 (0x7f)? Firmata cim cov txiaj ntsig no los ntawm kev sib cais lawv mus rau ntau qhov 7-ntsis byte ntu ua ntej cov ntaub ntawv raug hla hla cov ntaub ntawv txuas. Qhov tsawg kawg tseem ceeb byte (LSB) ntawm cov ntaub ntawv cov ntaub ntawv raug xa ua ntej, ua raws los ntawm cov khoom tseem ceeb ntawm cov ntaub ntawv los ntawm kev pom zoo. Qhov tseem ceeb tshaj plaws byte (MSB) ntawm cov khoom siv yog cov ntaub ntawv kawg xa.
Qhov no Ua Haujlwm Li Cas?
Cia peb hais tias peb xav koom nrog tus nqi 525 rau hauv cov ntaub ntawv ntawm SysEx cov lus. Txij li tus nqi ntawm 525 pom tseeb ntau dua li tus nqi ntawm 128, peb yuav tsum tau faib lossis cais nws mus rau hauv 7-ntsis byte "chunks."
Nov yog li cas thiaj ua tiav.
Tus nqi ntawm 525 hauv lej yog sib npaug rau tus lej hexadecimal ntawm 0x20D, tus lej 2-byte. Kom tau txais LSB, peb npog qhov txiaj ntsig los ntawm AND'ing nws nrog 0x7F. Kev siv "C" thiab Python tau qhia hauv qab no:
// "C" kev siv los cais LSB
int max_distance_LSB = max_distance & 0x7f; // npog qhov qis dua byte # Python siv los cais LSB max_distance_LSB = max_distance & 0x7F # npog qhov qis dua
Tom qab npog, max_distance_LSB yuav muaj 0x0d. 0x20D & 0x7F = 0x0D.
Tom ntej no, peb yuav tsum cais MSB rau tus nqi 2-byte no. Txhawm rau ua qhov no, peb yuav hloov tus nqi 0x20D mus rau sab xis, 7 qhov chaw.
// "C" kev siv los cais MSB ntawm 2 byte tus nqi
int max_distance_MSB = max_distance >> 7; // hloov qhov kev txiav txim siab byte # Python siv los cais MSB ntawm 2 byte tus nqi max_distance_MSB = max_distance >> 7 # ua haujlwm kom tau txais lub byte sab saud Tom qab hloov pauv, max_distance_MSB yuav muaj tus nqi 0x04.
Thaum cov ntaub ntawv "chunkified" marshaled tau txais, nws yuav tsum tau rov ua dua tshiab rau hauv tus nqi nkaus xwb. Nov yog yuav ua li cas cov ntaub ntawv tau rov qab ua ob qho tib si "C" thiab Python
// "C" kev siv los rov ua dua 2 byte, // 7 ntsis qhov tseem ceeb rau hauv ib tus nqi int max_distance = argv [0] + (argv [1] << 7); # Python kev siv los rov ua dua 2 byte, # 7 qhov tseem ceeb rau hauv ib tus nqi max_distance = cov ntaub ntawv [0] + (cov ntaub ntawv [1] << 7)
Tom qab kev sib sau ua ke, tus nqi ib zaug sib npaug 525 zauv lossis 0x20D hexadecimal.
Cov txheej txheem kev sib dhos/rov sib dhos no tuaj yeem ua los ntawm tus neeg siv khoom lossis server.
Kauj Ruam 2: Cia Peb Pib
Txhawb nqa lub cuab yeej tshiab xav tau kev hloov pauv rau ob tus neeg nyob hauv Arduino thiab PC tus neeg nyob hauv Python. Dr. Wheeler txoj haujlwm yuav raug siv los qhia qhov kev hloov kho tsim nyog.
Tej zaum cov kauj ruam tseem ceeb tshaj plaws yog txiav txim siab seb koj puas xav koom nrog lub tsev qiv ntawv txhawb nqa cov cuab yeej tam sim no rau hauv Arduino sab ntawm qhov sib npaug lossis sau koj tus kheej. Nws tau pom zoo tias yog koj tuaj yeem nrhiav lub tsev qiv ntawv uas twb muaj lawm, nws yooj yim dua siv nws dua li sau koj tus kheej los ntawm kos.
Txog DHT cov cuab yeej txhawb nqa, Dr. Wheeler raws nws txoj cai txuas ntxiv ntawm DHTNew library. Zoo heev, Dr. Wheeler faib kev ua haujlwm ntawm DHT Lub tsev qiv ntawv tshiab hla Arduino thiab pymata4 sab ntawm qhov sib npaug los muab qhov thaiv me me ntawm Arduino sab.
Yog tias peb saib DHTNew, nws ua tiav txhua yam hauv qab no:
- Pets xaiv tus pin tus qauv tso zis.
- Clocks tawm cov cim teeb tsa kom rov qab tau qhov tseeb ntawm cov av noo thiab qhov kub thiab txias.
- Tshawb xyuas thiab tshaj tawm ib qho yuam kev.
- Suav tib neeg nyeem tau qhov ntsuas kub thiab qhov av noo los ntawm cov ntaub ntawv nyoos khaws cia.
Txhawm rau ua kom muaj txiaj ntsig zoo li sai tau ntawm FirmataExpress sab, Dr. Wheeler tshem tawm cov ntaub ntawv hloov pauv ib txwm los ntawm Arduino mus rau pymata4.
Kauj Ruam 3: Hloov Kho FirmataExpress rau Kev Txhawb DHT
FirmataExpress Directory Tree
Hauv qab no yog txhua cov ntaub ntawv uas suav nrog FirmataExpress chaw cia khoom. Tsob ntoo no zoo ib yam rau ntawm StandardFiramata, tsuas yog qee qhov ntawm cov ntawv teev npe cuam tshuam rau lub npe chaw cia khoom.
Cov ntaub ntawv uas xav tau kev hloov kho yog cov uas muaj lub hnub qub (*) nyob ib sab ntawm lawv.
FirmataExpress
├── * Boards.h
├── piv txwv
Ata ata FirmataExpress
├── ├── boardx
Firm ├── * FirmataExpress.ino
IC IC LICENSE.txt
Cov ntaub ntawv Makefile
├── * FirmataConstants.h
├── * FirmataDefines.h
├── FirmataExpress.cpp
├── FirmataExpress.h
├── FirmataMarshaller.cpp
├── FirmataMarshaller.h Cov
├── FirmataParser.cpp
└── FirmataParser.h
Cia saib ntawm txhua daim ntawv thiab cov kev hloov pauv uas tau ua.
Boards.h
Cov ntaub ntawv no muaj cov ntsiab lus pin-type macro rau txhua qhov ntawm pawg pawg txhawb nqa. Nws txhais cov lej siab tshaj plaws ntawm cov cuab yeej txhawb nqa thaum ntau dua ib lub cuab yeej xav tau kev txhawb nqa.
Txog DHT cov cuab yeej, txog li 6 lub cuab yeej tuaj yeem txuas nrog ib lub sijhawm thiab tus nqi no tau txhais raws li:
#ifndef MAX_DHTS
#define MAX_DHTS 6 #endif
Tsis tas li, tus pin-type macros tuaj yeem xaiv tau txhais rau lub cuab yeej tshiab, txawm yog rau txhua hom board lossis tsuas yog cov uas txaus siab rau koj. Cov macros no tau siv feem ntau rau kev tshaj tawm lub hom phiaj thiab tsis siv rau kev tswj hwm cov khoom siv. Cov macros no txhais ob tus pin uas txhawb nqa lub cuab yeej:
#define IS_PIN_DHT (p) (IS_PIN_DIGITAL (p) && (p) - 2 <MAX_DHTS)
Ntxiv rau qhov macro los txheeb xyuas tus lej tus lej hloov dua siab tshiab.
#define PIN_TO_DHT (p) PIN_TO_DIGITAL (p)
FirmataConstants.h
Cov ntaub ntawv no muaj tus lej xov tooj firmware, uas koj tuaj yeem xav hloov kho kom taug qab cov version twg koj tau thauj mus rau koj li Arduino. Nws kuj tseem muaj cov ntawv Firmata qhov tseem ceeb, suav nrog Firmata SysEx lus.
Koj yuav tsum tau muab cov lus tshiab lossis teeb tsa cov lus rau koj lub cuab yeej hauv cov ntawv no. Txog DHT, ob tsab ntawv tau ntxiv. Ib qho teeb tsa tus pin ua tus "DHT" tus pin, thiab lwm qhov, ua tus tshaj xov xwm, thaum xa cov ntaub ntawv DHT tshiab rov qab rau tus neeg siv khoom.
static const int DHT_CONFIG = 0x64;
static const int DHT_DATA = 0x65;
Hom tus pin kuj tau teev tseg hauv daim ntawv no. Rau DHT, tus pin tus qauv tshiab tau tsim:
zoo li qub const int PIN_MODE_DHT = 0x0F; // tus pin teeb tsa rau DHT
Thaum ntxiv tus lej pin tshiab, TOTAL_PIN_MODES yuav tsum tau hloov kho:
zoo li qub const TOTAL_PIN_MODES = 17;
FirmataDefines.h
Cov ntaub ntawv no yuav tsum tau hloov kho kom pom cov lus tshiab ntxiv rau FirmataConstants.h:
#ifdef DHT_CONFIG #undef DHT_CONFIG #endif #define DHT_CONFIG firmata:: DHT_CONFIG // DHT thov #ifdef DHT_DATA #undef DHT_DATA #endif #define DHT_DATA firmata:: DHT_DATA // DHT teb #ifdef PIN_MODE_DHTEN #DATH PIN_MODE_DHTN:: PIN_MODE_DHT
FirmataExpress.ino
Hauv kev sib tham no, peb yuav npog "cov ntsiab lus siab" ntawm kev hloov pauv rau daim duab Arduino no.
Txhawm rau FirmataExpress txhawb nqa txog rau rau DHT cov cuab yeej ib txhij, 3 arrays tau tsim los txhawm rau taug qab ntawm txhua lub cuab yeej txuas tus lej tus lej, nws WakeUpDelay tus nqi, thiab hom ntaus ntawv, uas yog DHT22 lossis DHT11:
// DHT sensors
int numActiveDHTs = 0; // tus lej DHT txuas nrog uint8_t DHT_PinNumbers [MAX_DHTS]; uint8_t DHT_WakeUpDelay [MAX_DHTS]; uint8_t DHT_TYPE [MAX_DHTS];
Vim tias ob hom cuab yeej xav tau kwv yees li 2 vib nas this ntawm kev nyeem, peb yuav tsum ua kom ntseeg tau tias peb nyeem txhua DHT tsuas yog ib zaug hauv 2-thib ob lub sijhawm. Qee yam khoom siv, xws li DHT cov cuab yeej thiab HC-SR04 qhov ntsuas qhov deb, tsuas yog siv tau ib ntus. Qhov no tso cai rau lawv lub sijhawm los cuam tshuam nrog lawv ib puag ncig.
uint8_t nextDHT = 0; // ntsuas rau hauv dht rau ntaus ntawv tom ntej uas yuav tsum tau nyeem
uint8_t currentDHT = 0; // Khaws taug qab seb lub sensor twg ua haujlwm. int dhtNumLoops = 0; // Lub hom phiaj tus naj npawb ntawm lub sijhawm hla lub voj b4 nkag mus rau DHT int dhtLoopCounter = 0; // Loop txee
Kho thiab Nyeem Ntawv DHT Ntaus Ntawv
Thaum FirmataExpress tau txais SysEx hais kom teeb tsa tus pin rau DHT kev ua haujlwm, nws ua pov thawj tias cov lej DHT ntau tshaj plaws tsis tau tshaj. Yog tias DHT tshiab tuaj yeem txhawb nqa, DHT arrays tau hloov kho tshiab. Yog tias hom DHT tsis paub, SysEx txoj hlua xov tau tsim thiab xa rov qab mus rau pymata4
rooj plaub DHT_CONFIG: int DHT_Pin = argv [0]; int DHT_type = argv [1]; yog (numActiveDHTs <MAX_DHTS) {yog (DHT_type == 22) {DHT_WakeUpDelay [numActiveDHTs] = 1; } lwm tus yog (DHT_type == 11) {DHT_WakeUpDelay [numActiveDHTs] = 18; } lwm {Firmata.sendString ("YAM: UNKNOWN SENSOR TYPE, VALID SENSORS YOG 11, 22"); tawg; } // ntsuas qhov ntsuas DHT_PinNumbers [numActiveDHTs] = DHT_Pin; DHT_TYPE [numActiveDHTs] = DHT_type; setPinModeCallback (DHT_Pin, PIN_MODE_DHT);
FirmataExpress tom qab ntawd sim tham nrog DHT cov cuab yeej. Yog tias muaj qhov ua yuam kev, nws tsim SysEx cov lus nrog cov ntaub ntawv yuam kev thiab xa SysEx lus rov rau pymat4. Qhov hloov pauv _bits tuav cov ntaub ntawv xa rov qab los ntawm DHT cov cuab yeej rau kev ua tiav ntxiv los ntawm pymata4 yog xav tau.
Firmata.write (START_SYSEX);
Firmata.write (DHT_DATA); Firmata.write (DHT_Pin); Firmata.write (DHT_type); rau (uint8_t i = 0; i> 7 & 0x7f); } Firmata.write (abs (rv)); Firmata.write (1); Firmata.write (END_SYSEX);
Yog tias cov ntaub ntawv raug xa rov qab, tus naj npawb ntawm DHTs nquag tau nce ntxiv. Qhov sib txawv uas ua raws li muaj pes tsawg lub voj iterations kom ua tiav ua ntej tshawb xyuas DHT tom ntej rau cov ntaub ntawv tseem tau hloov kho. Qhov kev hloov pauv no lees paub tias tsis muaj teeb meem pes tsawg DHTs raug ntxiv rau hauv kab ke, lawv txhua tus yuav tau nyeem hauv 2 lub sijhawm thib ob.
int rv = readDhtSensor (numActiveDHTs);
yog (rv == DHTLIB_OK) {numActiveDHTs ++; dhtNumLoops = dhtNumLoops / numActiveDHTs; // txhua yam zoo}
Yog tias ib lossis ntau DHT cov cuab yeej tau teeb tsa hauv lub voj ua haujlwm ntawm daim duab, tom qab ntawv DHT ntaus ntawv tom ntej yog nyeem. Xijpeem cov ntaub ntawv siv tau lossis nws qhov xwm txheej yuam kev raug xa rov qab mus rau pymata4 hauv daim ntawv ntawm SysEx lus:
yog (dhtLoopCounter ++> dhtNumLoops) {yog (numActiveDHTs) {int rv = readDhtSensor (nextDHT)); uint8_t current_pin = DHT_PinNumbers [nextDHT]; uint8_t current_type = DHT_TYPE [nextDHT]; dhtLoopCounter = 0; currentDHT = nextDHT; yog (nextDHT ++> = numActiveDHTs - 1) {nextDHT = 0; } yog (rv == DHTLIB_OK) {// TEST CHECKSUM uint8_t sum = _bits [0] + _bits [1] + _bits [2] + _bits [3]; yog (_bits [4]! = sum) {rv = -1; }} // xa cov lus rov nrog qhov xwm txheej yuam kev Firmata.write (START_SYSEX); Firmata.write (DHT_DATA); Firmata.write (current_pin); Firmata.write (current_type); rau (uint8_t i = 0; i <sizeof (_bits) - 1; ++ i) {Firmata.write (_bits ); // Firmata.write (_bits ;} Firmata.write (abs (rv)); Firmata.write (0); Firmata.write (END_SYSEX);}}
Txoj cai siv los sib txuas lus nrog DHT cov cuab yeej tau txais ncaj qha los ntawm DHTNew library:
int readDhtSensor (int qhov ntsuas) {
// INIT BUFFERVAR kom tau txais cov ntaub ntawv uint8_t daim npog = 128; uint8_t idx = 0; // EMPTY BUFFER // memset (_bits, 0, sizeof (_bits)); rau (uint8_t i = 0; i 5 BYTES rau (uint8_t i = 40; i! = 0; i--) {loopCnt = DHTLIB_TIMEOUT; thaum (digitalRead (tus pin) == LOW) {yog (--loopCnt == 0) rov qab DHTLIB_ERROR_TIMEOUT;} uint32_t t = micros (); loopCnt = DHTLIB_TIMEOUT; thaum (digitalRead (tus pin) == HIGH) {yog (--loopCnt == 0) rov qab DHTLIB_ERROR_TIMEOUT;} yog ((micros ()-t)> 40) {_bits [idx] | = mask;} mask >> = 1; if (mask == 0) // next byte? {Mask = 128; idx ++;}} return DHTLIB_OK;}
Kauj Ruam 4: Hloov Pymata4 rau DHT Txhawb
private_constants.h
Txhawm rau txhawb nqa DHT, peb yuav tsum ntxiv ob tus pin-type tshiab thiab SysEx lus rau cov ntawv no:
# pin modules INPUT = 0x00 # pin set as input OUTPUT = 0x01 # pin set as output ANALOG = 0x02 # analog pin in analogInput mode PWM = 0x03 # digital pin in PWM output mode SERVO = 0x04 # digital pin in Servo output mode I2C = 0x06 # tus pin suav nrog hauv I2C teeb STEPPER = 0x08 # txhua tus pin hauv hom stepper SERIAL = 0x0a PULLUP = 0x0b # Txhua tus pin hauv kev rub tawm hom SONAR = 0x0c # Txhua tus pin hauv SONAR hom TONE = 0x0d # Txhua tus pin hauv suab hom PIXY = 0x0e # tshwj tseg rau pixy lub koob yees duab hom DHT = 0x0f # DHT sensor IGNORE = 0x7f # DHT SysEx cov lus txib DHT_CONFIG = 0x64 # dht teeb tsa hais kom ua DHT_DATA = 0x65 # dht sensor teb
Qhov ntxiv tus pin hom thiab SysEx cov lus txib yuav tsum phim cov txiaj ntsig hauv FirmataConstants.h ntxiv rau FirmataExpress.
pem 4.py
Pymata4 siv phau ntawv txhais lus Python txhawm rau cuam tshuam sai sai rau Firmata cov lus nrog tus xa xov. Lub npe ntawm phau ntawv txhais lus no yog report_dispatch.
Hom ntawv rau phau ntawv txhais lus nkag yog:
{MessageID: [message_handler, tus naj npawb ntawm cov ntaub ntawv bytes los ua tiav]}
Ib qho nkag tau ntxiv rau phau ntawv txhais lus los daws cov lus DHT:
{PrivateConstants. DHT_DATA: [self._dht_read_response, 7]}
7 bytes ntawm cov ntaub ntawv hauv kab lus yog Arduino tus lej lej tus lej, hom DHT ntaus ntawv (22 lossis 11), thiab 5 bytes ntawm cov ntaub ntawv nyoos.
Txoj kev _dht_read_response tshawb xyuas rau txhua qhov qhia tsis raug. Yog tias tsis muaj qhov qhia tsis raug, cov av noo thiab qhov kub tau suav nrog siv cov txheej txheem los ntawm Arduino DHTNew tsev qiv ntawv tshiab.
Cov txiaj ntsig suav tau tshaj tawm los ntawm tus neeg siv kev pabcuam hu rov qab. Lawv kuj tseem khaws cia rau sab hauv tus pin_data cov ntaub ntawv qauv. Tus nqi kawg tau tshaj tawm yuav rov qab los ntawm kev pov npav pin_data siv txoj kev dht_read.
Kho lub DHT Tshiab Ntaus Ntawv
Thaum ntxiv cov cuab yeej DHT tshiab, txheej txheej set_pin_mode_dht hu ua. Txoj kev no hloov kho tus pin_data rau cov koob digital. Nws kuj tseem tsim thiab xa ntawv DHT_CONFIG SysEx rau FirmataExpress.
Kauj Ruam 5: Ua kom tiav
Raws li peb tau pom, ntxiv Firmata txhawb nqa rau lub cuab yeej tshiab xav kom koj hloov kho Arduino FirmataExpress server code thiab Python-based pymata4 tus thov kev pabcuam. FirmataExpress code tuaj yeem nyuaj rau debug. Ib txoj hauv kev hu ua printData tau ntxiv rau FirmataExpress los pab daws qhov teeb meem. Txoj hauv kev no tso cai rau koj xa cov ntaub ntawv tseem ceeb los ntawm FirmataExpress thiab yuav luam tawm ntawm pymata4 console.
Txoj haujlwm no xav kom ob tus pointer mus rau ib tus cim thiab tus nqi uas koj xav pom. Yog tias cov ntaub ntawv tus nqi muaj nyob hauv qhov sib txawv hu ua argc, koj tuaj yeem hu rau printData nrog cov hauv qab no.
printData ((char*) "argc =", argc);
Yog tias koj muaj lus nug, tsuas yog tawm lus tawm, thiab kuv yuav zoo siab los teb.
Zoo siab coding!
Pom zoo:
Tus Neeg Tuaj Ntsuam Xyuas Siv Arduino ntawm TinkerCad: 3 Cov Kauj Ruam
Tus Neeg Tuaj Ntsuam Xyuas Siv Arduino ntawm TinkerCad: Ntau zaus peb yuav tsum tau saib xyuas tus neeg/tib neeg mus ntsib qee qhov xws li chav sib tham, chav sib tham lossis khw khw lossis tuam tsev. Txoj haujlwm no tuaj yeem siv los suav thiab tso saib tus naj npawb ntawm cov neeg tuaj saib nkag hauv ib chav sib tham lossis rooj sab laj
Ntsuam Xyuas Koj Lub Plawv Tus Kheej Nyob Ntawm Koj Lub Ntiv Tes: Photoplethysmography Mus Kom Txiav Txim Siab Lub Plawv: 7 Kauj Ruam
Ntsuas Koj Lub Plawv Tus Kheej Nyob Ntawm Koj Qhov Ntiv Tes: Photoplethysmography Mus Kom Txiav Txim Siab Lub Plawv: Ib daim duab photoplethysmograph (PPG) yog ib qho txheej txheem kho qhov yooj yim thiab siv tus nqi qis uas feem ntau siv los ntsuas kev hloov pauv ntshav hauv microvascular txaj ntawm cov nqaij. Nws feem ntau yog siv tsis cuam tshuam rau kev ntsuas ntawm cov tawv nqaij, feem ntau
Siv Cov Txheej Txheem Ua Yeeb Yam Zoo Tshaj Plaws los Tswj Cov Ntaub Ntawv Zoo Tshaj WiFi: 4 Cov Kauj Ruam (nrog Duab)
Siv Cov Txheej Txheem Ua Yeeb Yam Zoo Tshaj Plaws los Tswj Cov Ntaub Ntawv Ntshiab Dhau WiFi: Koj puas tau xav sim nrog kev tswj lub ntsej muag? Ua tej yam txav nrog nthwv dej ntawm koj txhais tes? Tswj suab paj nruag nrog kev sib tw ntawm koj lub dab teg? Cov lus qhia no yuav qhia koj li cas! Complex Arts Sensor Board (complexarts.net) yog ntau yam microc
Dhau mus ua ntej HORIZON nrog LoRa RF1276: 12 Cov Kauj Ruam
Dhau mus ua ntej HORIZON Nrog LoRa RF1276: Kuv tau pom RF1276 Transceiver kom xa qhov ua tau zoo tshaj plaws raws li cov teeb liab ntau thiab zoo. Raws li kuv thawj lub davhlau kuv tuaj yeem mus txog 56km nrug ntawm -70dB teeb liab theem nrog lub hlis me me nthwv dej kav hlau txais xov
Yuav Ua Li Cas Thiaj Li Tshaj Lij Tshaj Lij Tshaj Lij Tshaj Tawm Hauv Circuit Board: Phau Ntawv Qhia Ua tiav: 10 Kauj Ruam (nrog Duab)
Yuav Ua Li Cas Thiaj Li Tshaj Lij Tshaj Lij Tshaj Tawm Hauv Circuit Board: Phau Ntawv Qhia Tiav: Nyob zoo txhua tus, hnub no kuv yuav qhia koj yuav ua li cas thiaj ua tau PCB zoo, txhawm rau txhim kho koj cov phiaj xwm hluav taws xob. Cia peb pib