Cov txheej txheem:

DS1803 Dual Digital Potentiometer Nrog Arduino: 5 Kauj Ruam
DS1803 Dual Digital Potentiometer Nrog Arduino: 5 Kauj Ruam

Video: DS1803 Dual Digital Potentiometer Nrog Arduino: 5 Kauj Ruam

Video: DS1803 Dual Digital Potentiometer Nrog Arduino: 5 Kauj Ruam
Video: Цифровые потенциометры и модуль на AD5245 2024, Kaum ib hlis
Anonim
DS1803 Dual Digital Potentiometer Nrog Arduino
DS1803 Dual Digital Potentiometer Nrog Arduino

Kuv nyiam qhia kev siv DS1803 cov lauj kaub digital nrog Arduino. Qhov IC no muaj ob lub tshuab ntsuas hluav taws xob uas tuaj yeem tswj tau ob lub xov hlau sib txuas, rau qhov no kuv siv lub tsev qiv ntawv wire.h.

Qhov IC no tuaj yeem hloov pauv qhov qub potmeter analog. Hauv txoj kev no koj tuaj yeem tswj tau piv txwv li lub suab nrov lossis lub zog xa khoom.

Hauv cov lus qhia no kuv tswj qhov ci ntawm ob lub LED los qhia kev ua haujlwm.

Arduino suav cov mem tes ntawm lub cav hloov pauv thiab tso tus nqi hauv cov lauj kaub sib txawv [0] thiab lauj kaub [1]. Thaum koj thawb qhov hloov pauv ntawm tus lej cim, koj tuaj yeem hloov ntawm lub lauj kaub [0] thiab lauj kaub [1].

Tus nqi tiag ntawm lub lauj kaub tau nyeem rov qab los ntawm DS1803 thiab muab tso rau hauv qhov sib txawv potValue [0] thiab potValue [1] thiab nthuav tawm ntawm LCD.

Kauj Ruam 1: Kev sib txuas ntawm DS1803

Kev sib txuas ntawm DS1803
Kev sib txuas ntawm DS1803

Ntawm no koj tuaj yeem pom kev sib txuas ntawm DS1803. H yog sab siab ntawm lub hwj chim, L sab qis thiab W lub wiper. SCL thiab SDA yog cov tsheb npav sib txuas.

Nrog kev txuas A0, A1 thiab A2 koj tuaj yeem muab DS1803 nws tus kheej chaw nyob, ua li no koj tuaj yeem tswj hwm ntau yam khoom siv ntawm ib lub npav. Hauv kuv qhov piv txwv kuv tau muab DS1803 adres 0 los ntawm kev txuas txhua tus pin rau hauv av.

Kauj ruam 2: Hais kom Byte

Hais kom Byte
Hais kom Byte

Txoj kev DS1803 ua haujlwm tuaj yeem siv rau hauv cov lus txib byte. Thaum koj xaiv "sau potentiometer-0" ob qho potentiometers raug xaiv, thaum koj tsuas xav hloov kho potentiometer-0, koj tsuas yog yuav tsum xa thawj cov ntaub ntawv byte. "Sau potentiometer-1" tsuas yog kho potmeter-1. "Sau rau ob lub potentiometers" muab ob lub potentiometers tib tus nqi.

Kauj Ruam 3: Tswj DS1803

Tswj ntawm DS1803
Tswj ntawm DS1803

Kev tswj hwm byte (daim duab 3) muaj lub cim ntaus cim, qhov no nyob ib txwm zoo ib yam. Hauv kuv qhov piv txwv A0, A1 thiab A2 yog 0 vim tias peb xaiv adres los ntawm kev tso tag nrho A-pins rau hauv av. Qhov kawg R/W yuav raug teeb tsa 0 lossis 1 los ntawm cov lus txib "Wire.beginTransmission" thiab "Wire.requestFrom" hauv Arduino. Hauv daim duab 5 koj tuaj yeem pom tag nrho xov tooj. Kev nyeem xov tooj cua tau qhia hauv daim duab 4.

Kauj ruam 4: Teeb

Teeb
Teeb

Lub voj voog no qhia yuav ua li cas txuas txhua yam. Nokia LCD muaj nrog kev sib txuas sib txawv, nco ntsoov tias koj txuas koj li txoj cai. Tsis tas li ntawd lub cav encoder teb nws cov ntawv sib txawv, qee qhov muaj nyob ntawm tus pin nruab nrab lwm tus tsis. Kuv tau tso me ntsis lim network (470 Ohm resistor nrog 100nF cap) txhawm rau lim A thiab B cov teeb liab tso tawm ntawm tus encoder. Kuv xav tau lub lim dej no vim tias qhov tso tawm tau muaj suab nrov ntau. Kuv kuj tau tso lub sijhawm ncua deb hauv kuv qhov haujlwm kom tshem tawm qee lub suab nrov. Rau qhov seem kuv xav tias lub voj voog yog qhov tseeb. LCD tuaj yeem xaj ntawm Adafruit

Kauj Ruam 5: Txoj Haujlwm

Rau kev siv 2-xaim tsheb npav kuv suav nrog Wire.h lub tsev qiv ntawv. Txhawm rau siv LCD Kuv suav nrog Adafruit lub tsev qiv ntawv uas koj tuaj yeem rub tawm los ntawm https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library tseem muaj Adafruit_GFX.h lub tsev qiv ntawv muaj nyob ntawm no https:// github. com/adafruit/Adafruit-GFX-Lub Tsev Qiv Ntawv.

#suav nrog

#suav nrog

#suav nrog

Adafruit_PCD8544 zaub = Adafruit_PCD8544 (7, 6, 5, 4, 3);

Ntawm no koj tuaj yeem pom txhua qhov sib txawv. Tswj byte thiab hais kom ua byte raws li tau hais ua ntej. Lub deBounceTime tuaj yeem hloov kho raws li lub suab nrov ntawm koj tus lej cim.

byte lauj kaub [2] = {1, 1}; byte controlByte = B0101000; // 7 khoom, byte commandByte = B10101001; // 2 qhov kawg yog xaiv lub ntsuas ntsuas. byte potValue [2]; int kuv = 0; int deBounceTime = 10; // Kho tus nqi no nyob ntawm lub suab nrov const int encoder_A = 8; const int encoder_B = 9; const int buttonPin = 2; unsigned ntev newDebounceTime = 0; unsigned ntev oldTime; boolean nias = 0; boolean suav = 1;

Hauv kev teeb tsa kuv txhais cov pins zoo thiab muab cov ntawv zoo li qub tso rau ntawm LCD

teeb tsa tsis muaj dabtsis () {Wire.begin (); Serial.begin (9600); pinMode (encoder_A, INPUT); pinMode (encoder_B, INPUT); pinMode (buttonPin, INPUT); newDebounceTime = millis ();

display.begin ();

display.setContrast (50); display.clearDisplay (); display.setTextSize (1); display.setTextColor (BLACK); display.setCursor (0, 10); display.println ("POT 1 ="); display.setCursor (0, 22); display.println ("POT 2 ="); display.display ();

}

Hauv lub voj kuv xub tshawb xyuas yog tias ncua sijhawm ntau dua 500ms, yog tias yog lub LCD tau hloov kho tshiab. Yog tias tsis yog lub pob ntawm tus encoder raug tshuaj xyuas. Yog tias nias lub toggleBuffer tau hu. Tom qab qhov no tau txheeb xyuas qhov encoder. Yog tias cov tswv yim 0 tsawg (kev ntsuas ntsuas pom) Kuv tshawb xyuas B, yog tias cov tswv yim B yog 0 Kuv nce lub lauj kaub , lwm tus kuv txo qis. Tom qab qhov no tus nqi yuav raug xa mus rau DS1803 ntawm wire.write.

void voj () {

ncua ();

yog (digitalRead (buttonPin) == 1 && (nias == 0)) {toggleBuffer ();} yog (digitalRead (buttonPin) == 0) {nias = 0;}

yog (digitalRead (encoder_A) == 0 && suav == 0 && (millis () - newDebounceTime> deBounceTime)) {yog (digitalRead (encoder_B) == 0) {lauj kaub ++; yog (lauj kaub > 25) {lauj kaub = 25;}} ntxiv {lauj kaub -; if (lauj kaub <1) {lauj kaub = 1;}} suav = 1; newDebounceTime = millis ();

Wire.beginTransmission (controlByte); // pib kis

Wire.write (commandByte); // xaiv potmeters Wire.write (lauj kaub [0] * 10); // xa 1st byte ntawm cov ntaub ntawv potmeter Wire.write (lauj kaub [1] * 10); // xa thib ob byte ntawm cov ntaub ntawv ntsuas lub xov tooj Wire.endTransmission (); // tsis txhob xa lwm tus yog tias (digitalRead (encoder_A) == 1 && digitalRead (encoder_B) == 1 && suav == 1 && (millis () - newDebounceTime> deBounceTime)) {suav = 0; newDebounceTime = millis (); }}

tsis muaj dab tsi toggleBuffer () {nias = 1; yog (kuv == 0) {kuv = 1;} lwm tus {kuv = 0;}}

Ua ntej kuv tshem thaj chaw uas kuv yuav tsum sau qhov txawv. Kuv ua qhov no los kos ib lub duab plaub hauv cheeb tsam no. Tom qab ntawd kuv sau qhov hloov pauv rau ntawm qhov screen.

void writeToLCD () {Wire.requestFrom (controlByte, 2); potValue [0] = Wire.read (); // nyeem thawj potmeter byte potValue [1] = Wire.read (); // nyeem thib ob potmeter byte display.fillRect (40, 0, 40, 45, WHITE); // pom qhov txawv txav ntawm lub vijtsam LCD.setCursor (40, 10); display.print (potValue [0]); // sau tus lej thib 1 rau tus lej LCD.setCursor (40, 22); display.print (potValue [1]); // sau tus lej thib ob rau tus lej LCD.setCursor (60, (10 + i * 12)); display.print ("<"); display.display (); }

void interval () {// ncua sij hawm timer los sau cov ntaub ntawv rau LCD yog ((millis () - oldTime)> 500) {writeToLCD (); oldTime = millis (); }}

Pom zoo: