Cov txheej txheem:
- Kauj Ruam 1: Rotary Encoders Sab Hauv
- Kauj Ruam 2: Kev nyuaj siab uas ua rau mob tiag rau ntau tus
- Kauj Ruam 3: Finite State Machine (FSM) Tshuaj
- Kauj ruam 4: Arduino Code
- Kauj ruam 5: Flawless Integration
Video: Ua tiav Arduino Rotary Solution: 5 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:27
Cov encoders teb yog tig pob qhov rooj tswj rau cov phiaj xwm hluav taws xob, feem ntau siv nrog Arduino tsev neeg microcontrollers. Lawv tuaj yeem siv los kho qhov ntsuas tsis zoo, txheeb xyuas cov ntawv, txav cov khoom ntawm lub vijtsam, teeb tsa qhov tseem ceeb ntawm txhua yam. Lawv yog cov hloov pauv ntau rau cov potentiometers, vim tias lawv tuaj yeem hloov pauv tau ntau dua thiab tsis muaj qhov kawg, lawv nce lossis txo qis ib tus nqi sib txawv ntawm ib lub sijhawm, thiab feem ntau suav nrog kev hloov pushable rau xaiv cov haujlwm zoo. Lawv tuaj nyob hauv txhua daim duab thiab qhov ntau thiab tsawg, tab sis tus nqi qis tshaj yog qhov nyuaj rau cuam tshuam nrog raws li tau piav qhia hauv qab no.
Muaj ntau ntau cov ntawv hais txog kev ua haujlwm cov ntsiab lus thiab kev siv hom ntawm Rotary encoders, thiab ntau tus lej piv txwv thiab cov tsev qiv ntawv yuav siv li cas. Qhov teeb meem tsuas yog tias tsis muaj ib tus ntawm lawv ua haujlwm 100% raug nrog tus nqi qis tshaj suav suav teb cov qauv.
Kauj Ruam 1: Rotary Encoders Sab Hauv
Ib feem teb ntawm tus encoder muaj peb tus pin (thiab ob ntxiv rau qhov yeem hloov qhov). Ib qho yog ib qho av (dub GND), ob qho ntxiv yog rau kev txiav txim siab thaum lub pob qhov rooj tig (lawv feem ntau hu ua xiav CLK thiab liab DT). Ob qho no tau txuas nrog PULLUP tus lej nkag ntawm lub microcontroller, ua rau qib siab lawv qhov kev nyeem ntawv tsis raug. Thaum lub pob qhov rooj tig mus rau tom ntej (lossis raws lub moos), ua ntej xiav CLK poob rau qib LOW, tom qab ntawd liab DT ua raws. Tig ntxiv, xiav CLK nce rov qab mus rau HIGH, tom qab ntawd zoo li GND thaj ua rau ob daim pins txuas, liab DT kuj nce rov mus rau HIGH. Yog li ua kom tiav ib daim npav FWD tag nrho (lossis raws lub moos). Ib yam mus rau lwm qhov kev taw qhia BWD (lossis rov qab-clockwise), tab sis tam sim no liab liab ua ntej, thiab xiav nce rov qab kawg li tau qhia hauv ob qib duab ib feem.
Kauj Ruam 2: Kev nyuaj siab uas ua rau mob tiag rau ntau tus
Qhov teeb meem tshwm sim rau Arduino hobbyists, qhov pheej yig Rotary encoder modules thaws hloov pauv ntxiv hauv qib tso tawm, ua rau ntxiv thiab yuam kev suav suav nyeem. Qhov no tiv thaiv kev suav tsis tau zoo thiab ua rau nws tsis tuaj yeem ua ke cov qauv no rau hauv cov phiaj xwm raug. Cov kev tawm tsam ntxiv no yog tshwm sim los ntawm kev siv tshuab txav ntawm thaj ua rau thaj pins sib txuas, thiab txawm tias siv cov peev txheej ntxiv tsis tuaj yeem tshem tawm lawv tag. Bounces tuaj yeem tshwm sim nyob txhua qhov chaw hauv cov zuam puv, thiab tau qhia los ntawm cov xwm txheej hauv lub neej tiag tiag ntawm cov duab.
Kauj Ruam 3: Finite State Machine (FSM) Tshuaj
Cov duab qhia tag nrho lub xeev qhov chaw ntawm qhov hloov pauv tau rau ob tus pin (xiav CLK thiab liab DT), ob qho tib si rau qhov raug thiab tsis raug. Raws li lub xeev lub tshuab no ua tiav cov kev daws teeb meem tuaj yeem ua haujlwm uas ib txwm ua haujlwm 100% raug. Vim tias tsis muaj kev lim sijhawm qeeb yog qhov tsim nyog hauv qhov kev daws teeb meem no, nws tseem yog qhov ua tau sai tshaj plaws. Lwm qhov txiaj ntsig ntawm kev cais cov pins 'lub xeev qhov chaw los ntawm hom ua haujlwm yog tias ib tus tuaj yeem thov ob qho kev xaiv tsa lossis cuam tshuam cov qauv rau nws tus kheej nyiam. Kev xaiv tsa lossis cuam tshuam tuaj yeem txheeb xyuas qib kev hloov pauv ntawm tus pin thiab kev sib cais ib txwm yuav xam lub xeev tshiab raws li lub xeev tam sim no thiab cov xwm txheej tseeb ntawm qib hloov pauv.
Kauj ruam 4: Arduino Code
Cov cai hauv qab no suav tus FWD thiab BWD zuam ntawm tus lej saib thiab tseem suav nrog qhov kev xaiv hloov ua haujlwm.
// Peter Csurgay 2019-04-10
// Pins ntawm cov teb mapped rau Arduino chaw nres nkoj
#define SW 21 #define CLK 22 #define DT 23
// Tus nqi tam sim no thiab yav dhau los ntawm lub txee ntsuas los ntawm cov teb
int curVal = 0; int prevVal = 0;
// Xya lub xeev ntawm FSM (lub xeev muaj lub tshuab kawg)
#define IDLE_11 0 #define SCLK_01 1 #define SCLK_00 2 #define SCLK_10 3 #define SDT_10 4 #define SDT_00 5 #define SDT_01 6 int xeev = IDLE_11;
void teeb tsa () {
Serial.begin (250000); Serial.println ("Pib …"); // Qib HIGH yuav tsis raug rau txhua tus pin pinMode (SW, INPUT_PULLUP); pinMode (CLK, INPUT_PULLUP); pinMode (DT, INPUT_PULLUP); // Ob qho CLK thiab DT yuav ua rau cuam tshuam rau txhua qib hloov pauv attachInterrupt (digitalPinToInterrupt (CLK), rotaryCLK, CHANGE); attachInterrupt (digitalPinToInterrupt (DT), rotaryDT, CHANGE); }
void voj () {
// Kev ua haujlwm ntawm qhov kev xaiv hloov ua ke rau qee qhov kev hloov pauv hloov pauv yog (digitalRead (SW) == LOW) {Serial.println ("Nias"); thaum (! digitalRead (SW)); } // Txhua qhov kev hloov pauv hauv tus lej suav tau tshwm hauv Serial Monitor yog (curVal! = PrevVal) {Serial.println (curVal); prevVal = curVal; }}
// Lub Xeev Tshuab hloov pauv rau qib CLK hloov pauv
void rotaryCLK () {yog (digitalRead (CLK) == LOW) {yog (xeev == IDLE_11) xeev = SCLK_01; lwm tus yog (xeev == SCLK_10) xeev = SCLK_00; lwm tus yog (xeev == SDT_10) xeev = SDT_00; } lwm {yog (xeev == SCLK_01) xeev = IDLE_11; lwm tus yog (xeev == SCLK_00) xeev = SCLK_10; lwm yog (xeev == SDT_00) xeev = SDT_10; lwm tus yog (xeev == SDT_01) {xeev = IDLE_11; curVal--; }}}
// Lub Xeev Tshuab hloov pauv rau DT qib hloov pauv
void rotaryDT () {yog (digitalRead (DT) == LOW) {yog (xeev == IDLE_11) xeev = SDT_10; lwm tus yog (xeev == SDT_01) xeev = SDT_00; lwm tus yog (xeev == SCLK_01) xeev = SCLK_00; } lwm {yog (xeev == SDT_10) xeev = IDLE_11; lwm tus yog (xeev == SDT_00) xeev = SDT_01; lwm tus yog (xeev == SCLK_00) xeev = SCLK_01; lwm tus yog (xeev == SCLK_10) {xeev = IDLE_11; curVal ++; }}}
Kauj ruam 5: Flawless Integration
Koj tuaj yeem tshawb xyuas hauv cov vis dis aus txuas uas FSM daws tau ua haujlwm raug thiab nrawm txawm tias muaj qhov qis qis qis qis qis nrog ntau yam cuam tshuam cuam tshuam.
Pom zoo:
Ua tiav Kev Kho dua Tshiab ntawm Cov Cim Hluav Taws Xob: 8 Cov Kauj Ruam
Ua tiav Kev Kho dua ntawm Vintage Lub Teeb Hluav Taws Xob: Kuv tau txais Eico 320 RF lub tshuab hluav taws xob teeb liab ntawm cov xov tooj cua ham sib pauv tau ntsib ob peb duas las ob peb xyoos dhau los tab sis tsis tau nyob ib puag ncig los ua dab tsi nrog nws txog tam sim no. Lub tshuab hluav taws xob no muaj tsib qhov hloov pauv tau los ntawm 150 kHz txog 36 MHz thiab nrog ha
Guia Ua tiav LCD 16x2: 4 Cov Kauj Ruam
Guia Ua tiav LCD 16x2: Qhia tawm ste um é um projeto iniciante, tsis muaj peev xwm siv us LCD um 16 × 2 para exibir o brilho ua LED.Em breve, neste projeto, controlaremos o brilho ua LED usando um potenciômetro. Nws ua rau LED teeb pom kev zoo los ntawm lub xov tooj LCD siv thiab ua haujlwm tsis zoo
Chaw Nres Tsheb NaTaLia: Arduino Solar Powered Weather Station Ua tiav Txoj Cai: 8 Kauj Ruam (nrog Duab)
Chaw Nres Tsheb NaTaLia: Arduino Solar Powered Weather Station Ua tiav Txoj Cai Txoj Cai: Tom qab 1 xyoos ntawm kev ua haujlwm tau zoo ntawm 2 qhov chaw sib txawv Kuv tab tom qhia kuv lub hnub ci siv hluav taws xob qhov chaw nres tsheb huab cua phiaj xwm phiaj xwm thiab piav qhia nws tau hloov zuj zus mus rau hauv cov kab ke uas tuaj yeem muaj sia nyob ntev npaum li cas lub sij hawm los ntawm hnub ci zog. Yog koj ua raws
$ 2 Arduino. ATMEGA328 Raws Li Ib Leeg Ib Leeg. Yooj Yim, Pheej Yig thiab Me Me. Phau Ntawv Qhia Tiav: 6 Kauj Ruam (nrog Duab)
$ 2 Arduino. ATMEGA328 Raws Li Ib Leeg Ib Leeg. Yooj Yim, Pheej Yig thiab Me Me. Phau Ntawv Qhia Ua Ntej: Hauv cov lus qhia no koj yuav kawm paub siv Arduino ATMEGA328 microcontroller nti ua lub tshuab microcontroller nyob ib leeg. Lawv raug nqi tsuas yog 2 daus las, tuaj yeem ua ib yam li koj li Arduino thiab ua rau koj cov haujlwm me me heev.Peb yuav npog tus pin teeb tsa
Ua kom tiav Arduino-based Tsheb GPS+GPRS Anti-theft System: 5 Cov Kauj Ruam (nrog Duab)
Ua tiav Arduino-based Vehicle GPS+GPRS Anti-theft System: Nyob zoo txhua tus! Kuv xav tsim kom tiav kev daws teeb meem rau GPS tsheb tiv thaiv tub sab ntaus ntawv, uas yuav yog: pheej yig li sai tau raws li ua tau raws li nws tsuas yog ua haujlwm -there's-nothing-else-to-do li ua tau li ntawd Kuv thiaj li xaus tsim Arduino-based soluti