Cov txheej txheem:

Kev Lom Zem Nrog OLED Zaub thiab Arduino: 12 Kauj Ruam (nrog Duab)
Kev Lom Zem Nrog OLED Zaub thiab Arduino: 12 Kauj Ruam (nrog Duab)

Video: Kev Lom Zem Nrog OLED Zaub thiab Arduino: 12 Kauj Ruam (nrog Duab)

Video: Kev Lom Zem Nrog OLED Zaub thiab Arduino: 12 Kauj Ruam (nrog Duab)
Video: qhia txog kev mus noj zaub mov tom lab by Kwm Lis (Nuj Nphlaib) 2024, Hlis ntuj nqeg
Anonim
Kev lom zem Nrog OLED Zaub thiab Arduino
Kev lom zem Nrog OLED Zaub thiab Arduino

Kuv paub zoo tias koj tau hnov dua txog OLED thev naus laus zis. Nws yog qhov tshiab thiab muaj qhov ua tau zoo dua qub LCD thev naus laus zis. Hauv qhov kev qhia no peb xav tshuaj xyuas cov kauj ruam uas yuav tsum tau ua kom pom cov ntaub ntawv ntawm ib qho ntawm cov xim ib txwm pom OLED cov qauv muaj nyob rau ntawm kev ua lag luam. Kuv yuav sim piav qhia qhov muaj peev xwm muab los ntawm Adafruit lub tsev qiv ntawv sib tham los tso saib cov ntaub ntawv ntawm tus qauv no.

Kauj Ruam 1: Dab tsi OLED Cov Qauv Peb Yuav Siv?

Dab tsi OLED Cov Qauv Peb Yuav Siv?
Dab tsi OLED Cov Qauv Peb Yuav Siv?
Dab tsi OLED Cov Qauv Peb Yuav Siv?
Dab tsi OLED Cov Qauv Peb Yuav Siv?
Dab tsi OLED Cov Qauv Peb Yuav Siv?
Dab tsi OLED Cov Qauv Peb Yuav Siv?

OLED cov qauv muaj nyob rau ntau qhov ntau thiab tsawg thiab cov yam ntxwv. Qhov peb yuav siv hauv qhov kev qhia no yog xim mono 128x64 OLED module. Hom qauv no muaj nyob hauv qhov ntau thiab tsawg hauv qab no (Txhawm rau kom koj pom ntawm cov duab):

  • 128x64 ua
  • 128x32 ua
  • 96x16 ua
  • 6 4x 48
  • 64x32 ua

Raws li tag nrho cov qauv no txhawb I2C cov txheej txheem raws li lub ntsiab lus rau kev sib txuas lus, cov cai thiab thaiv ntawm txhua tus ntawm lawv yog qhov tseeb. Qhov sib txawv tsuas yog koj yuav tsum txiav txim siab qhov loj me ntawm cov zaub ntawm koj cov cai kom cov ntsiab lus uas koj yuav tso tawm, haum rau nws.

Kauj Ruam 2: I2C hauv Nutshell

I2C hauv qhov ceev
I2C hauv qhov ceev

Kev sib koom ua ke sib txuas (IIC) uas ib txwm hu ua I2C (I squared C) tsim los ntawm Philips ntawm 80s ua cov npav sib pauv siv los hloov cov ntaub ntawv nruab nrab ntawm lub hauv paus ua haujlwm (CPU) lossis microcontroller unit (MCU) ntawm lub cuab yeej thiab peripheral chips. Nws yog lub hauv paus phiaj rau kev thov TV. Vim nws qhov yooj yim, nws tau dhau los ua neeg nyiam tias tom qab ib ntus nws tau dhau los ua ib qho ntawm cov txheej txheem tseem ceeb ntawm kev hloov pauv cov ntaub ntawv rau CPUs thiab MCUs thiab cov khoom siv sab nraud uas tsis tsim nyog ib feem ntawm tib lub PCB pawg thawj coj thiab txuas nrog nws los ntawm xaim (piv txwv li cov sensors, display modules, thiab lwm yam).

I2C suav nrog tsheb npav sib txuas ua los ntawm ob lub xov hlau uas txhawb nqa cov ntaub ntawv xa mus los ntawm tus tswv thiab ntau yam khoom siv qhev. Feem ntau tus tswv node yog tus saib xyuas kev tswj hwm lub npav - uas yog qhov ua tau tiag tiag los ntawm kev tsim lub teeb liab sib txuas ntawm kab xov tooj (SCL). Nws yog lub teeb liab uas yuav raug xa mus tas li los ntawm tus tswv thaum hloov pauv thiab txhua lwm cov nodes txuas nrog lub tsheb npav yuav siv nws los sib txuas lawv cov kev sib txuas lus thiab txheeb xyuas lub tsheb npav nrawm. Cov ntaub ntawv raug xa tawm ntawm tus tswv thiab qhev los ntawm kab ntawv xov tooj (SDA) kab. Cov kis tau tus mob tuaj yeem siab txog 3.4 Mbps. Txhua lub cuab yeej uas xav hloov pauv cov ntaub ntawv ntawm I2C yuav tsum muaj qhov chaw nyob tshwj xeeb thiab tuaj yeem ua haujlwm raws li tus xa khoom lossis tus txais khoom nyob ntawm qhov ua haujlwm ntawm lub cuab yeej. Piv txwv li OLED zaub module yog tus txais uas lees txais qee cov ntaub ntawv thiab qhia lawv, thaum ntsuas kub yog lub tshuab xa xov uas xa qhov ntsuas kub ntawm I2C tsheb npav. Feem ntau tus kws tshaj lij yog lub cuab yeej uas pib ua cov ntaub ntawv hloov chaw ntawm lub tsheb npav thiab tsim lub moos cim qhia kom tso cai hloov chaw. Thaum lub sijhawm hloov pauv no, txhua lub cuab yeej hais los ntawm tus tswv no suav tias yog qhev thiab nyeem cov ntaub ntawv ntawd.

Thaum lub node xav xa qee cov ntaub ntawv, thawj zaug byte ntawm cov ntaub ntawv yuav tsum yog qhov chaw nyob ntawm tus txais thiab tom qab ntawv cov ntaub ntawv tiag tiag tuaj tom qab. Qhov no txhais tau tias txhawm rau xa cov ntaub ntawv mus rau cov khoom siv siv I2C (piv txwv li I2C OLED zaub module) peb yuav tsum xub pom nws qhov chaw nyob I2C thiab qhov no yog qhov peb yuav ua ua ntej ntawm cov kauj ruam tom ntej.

Yog tias koj xav paub ntau ntxiv txog cov ntsiab lus thiab kev xav txog I2C npav, koj tuaj yeem siv cov lus hais hauv qab no:

www.i2c-bus.org

learn.sparkfun.com/tutorials/i2c

Kauj Ruam 3: Yuav Tsum Muaj Cov Qauv thiab Cheeb Tsam

Yuav tsum tau Modules thiab Cheebtsam
Yuav tsum tau Modules thiab Cheebtsam
Yuav tsum tau Modules thiab Cheebtsam
Yuav tsum tau Modules thiab Cheebtsam
Yuav tsum tau Modules thiab Cheebtsam
Yuav tsum tau Modules thiab Cheebtsam

Ntawm no koj tuaj yeem pom cov npe ntawm cov khoom uas koj xav tau kom ua tiav cov lus qhia no:

eBay txuas:

  • 1 x Arduino Uno:
  • 1 x OLED module 128x64:
  • 4 x Dupont cable:
  • 1 x Mini solderless breadboard:

Amazon.com txuas:

  • 1 x Arduino Uno:
  • 1 x OLED module 128x64:
  • 4 x Dupont cable:
  • 1 x Mini solderless breadboard:

Kauj Ruam 4: Txuas OLED Display Module rau Arduino

Txuas OLED Display Module rau Arduino
Txuas OLED Display Module rau Arduino
Txuas OLED Display Module rau Arduino
Txuas OLED Display Module rau Arduino
Txuas OLED Display Module rau Arduino
Txuas OLED Display Module rau Arduino
Txuas OLED Display Module rau Arduino
Txuas OLED Display Module rau Arduino

Ib qho lus ceeb toom tseem ceeb txog I2C cov cuab yeej siv yog tias txoj hauv kev koj yuav tsum txuas lawv rau Arduino zoo ib yam. Qhov no vim tias Arduino khiav nws I2C kev sib txuas lus nkaus xwb ntawm cov pins tshwj xeeb. Hauv qhov kev qhia no kuv siv Arduino Uno. Arduino Uno siv tus pin A5 li SCK thiab A4 ua SDA. Yog li peb tuaj yeem txuas OLED cov qauv coj mus rau Arduino Uno raws li qhia hauv cov duab pom. Raws li koj yuav pom hauv daim duab kuv tau coj los ntawm kuv tus lej OLED zaub, qhov txuas rau VCC thiab GND txawv dua li qhov pom pom. Nco ntsoov xyuas cov ntawv lo ntawm tus pin ntawm koj cov qauv kom paub tseeb tias koj txuas nws nrog txoj hauv kev.

Peb xav tau tsuas yog 4 tus pin uas yuav tsum tau txuas nrog hauv qab no:

Arduino VCC -> OLED Module VCC

Arduino GND -> OLED Module GND

Arduino 4 -> OLED Module SDA

Arduino 5 -> OLED Module SCK

Kauj Ruam 5: Nrhiav Qhov Chaw Nyob ntawm Cov Qauv Zaub

Nrhiav Qhov Chaw Nyob ntawm Cov Qauv Zaub
Nrhiav Qhov Chaw Nyob ntawm Cov Qauv Zaub

Ua thawj kauj ruam ntawm kev txuas mus rau I2C cov cuab yeej siv tau, koj yuav tsum muaj qhov chaw nyob ntawm tus qauv. Txhawm rau ua li ntawd, tom qab txuas lub module rau koj Arduino, koj yuav tsum tsuas yog xa cov lej txuas, mus rau koj Arduino. Txoj cai no suav nrog Cov tsev qiv ntawv Wire uas yog lub tsev qiv ntawv suav nrog Arduino IDE uas ua haujlwm I2C kev sib txuas lus. Nws sim tshuaj xyuas cov khoom siv I2C txuas nrog thiab xa lawv qhov chaw nyob ntawm chaw nres nkoj txuas mus rau koj lub computer. Yog li koj tuaj yeem nkag mus rau nws cov txiaj ntsig ntawm Serial Monitor cuab yeej hauv Arduino IDE. Thawj qhov muaj nyob ntawm Arduino Chaw Ua Si). Tsis tas li koj tuaj yeem saib nws hauv txoj kev nyeem tau yooj yim dua hauv kuv li Online Arduino Editor. Tsis txhob cia siab tias yuav muaj dab tsi tshwm sim ntawm qhov screen thaum tus lej no tau ua haujlwm.

Raws li koj tuaj yeem pom ntawm daim duab, kuv tus qauv raug khi rau qhov chaw 0x3C. Feem ntau txhua yam khoom siv hauv kab khoom tshwj xeeb (piv txwv li txhua 128x64 OLED modules) muaj tib qhov chaw nyob.

Qhov ntxiv ntawm I2C cov cuab yeej raug txwv los ntawm 1 txog 126. Txoj cai no yooj yim sim txuas mus rau txhua lub cuab yeej ua haujlwm (yam tsis tau xa cov ntaub ntawv) thiab tom qab ntawv xyuas seb puas muaj qhov yuam kev qhia los ntawm lub tsev qiv ntawv txuas ntawm txuas mus rau qhov chaw nyob. Yog tias tsis muaj qhov yuam kev, tom qab ntawd luam tawm qhov chaw nyob raws li muaj cov qauv siv los txuas. Tsis tas li nws yuav tsum tau sau tseg tias thawj 15 qhov chaw nyob tau tshwj tseg, yog li nws dhia hla lawv thiab tsuas yog luam cov uas nyob saum toj no. Nco ntsoov tias qhov chaw nyob ntawm I2C cov qauv no nyuaj-coded ntawm lub cuab yeej thiab nws hloov tsis tau. Yog li nws yuav yog lub tswv yim zoo los sau nws rau qee qhov lossis muab daim ntawv lo rau ntawm tus qauv thaum koj yuav muab nws rov qab rau hauv koj lub chaw tso khoom lab kom lub sijhawm tom ntej, khiav lub tshuab luam ntawv yuav tsis tsim nyog. Txawm li cas los nws tsis yog txheej txheem nyuaj;)

Kauj Ruam 6: Txhim Kho Tsev Qiv Ntawv Yuav Tsum Ua Los Qhia Cov Ntaub Ntawv ntawm OLED Module

Txhim Kho Cov Tsev Qiv Ntawv Yuav Tsum Ua Zaub Cov Ntaub Ntawv ntawm OLED Module
Txhim Kho Cov Tsev Qiv Ntawv Yuav Tsum Ua Zaub Cov Ntaub Ntawv ntawm OLED Module
Txhim Kho Cov Tsev Qiv Ntawv Yuav Tsum Ua Los Qhia Cov Ntaub Ntawv ntawm OLED Module
Txhim Kho Cov Tsev Qiv Ntawv Yuav Tsum Ua Los Qhia Cov Ntaub Ntawv ntawm OLED Module

Lub tsev qiv ntawv Hlau tuaj yeem tswj kev sib txuas lus qib qis nrog I2C cov cuab yeej. Thaum koj xav txuas mus rau ib lub cuab yeej tshwj xeeb txhawm rau nyeem/sau cov ntaub ntawv los ntawm/rau nws, ib txwm koj yuav siv lub tsev qiv ntawv muab los ntawm lub tuam txhab uas tau xub tsim cov qauv ntawd. Lub tsev qiv ntawv no saib xyuas txhua yam I2C kev sib txuas lus cov ntsiab lus nrog muab cov qauv thiab cia peb mob siab rau ntau dua ntawm peb txoj kev lag luam uas nyob rau hauv rooj plaub no tau nthuav tawm cov ntaub ntawv raws li peb xav tau.

Adafruit, lub tuam txhab uas tsim cov khoom qub ntawm cov qauv kev qhia no, muab cov tsev qiv ntawv hu ua Adafruit SSD1306 los tso saib cov ntaub ntawv ntawm cov duab no ib leeg. Yog li ua ntej pib coding, peb tau teeb tsa lub tsev qiv ntawv no los ntawm Tus Thawj Saib Xyuas Tsev Qiv Ntawv (nkag tau los ntawm Sketch> suav nrog Lub Tsev Qiv Ntawv> Tswj Tsev Qiv Ntawv… ntawv qhia zaub mov) hauv Arduino IDE. Kuj tseem muaj lwm lub tsev qiv ntawv hu ua Adafruit GFX Lub Tsev Qiv Ntawv uas ua haujlwm qis dua cov duab nraaj thiab tau siv sab hauv los ntawm Adafruit SSD1306. Koj yuav tsum muaj ob qho kev teeb tsa ntawm koj li Arduino IDE raws li koj tuaj yeem pom ntawm daim duab.

Kauj Ruam 7: Pib Pib Zaub Module

Initializing Zaub Module
Initializing Zaub Module

Kev teeb duab ntawm cov duab tso tawm tau qhwv hauv chav kawm npe hu ua Adafruit_SSD1306. Lub ntsiab lus ntawm chav kawm no yog nyob hauv Adafruit lub tsev qiv ntawv, yog li peb yuav tsum xub suav nrog lub tsev qiv ntawv ntawd. Tom qab ntawd peb yuav tsum tau muab ib qho piv txwv ntawm chav kawm no ua ntej. Tus tsim ntawm chav kawm no siv tus lej chaw nres nkoj uas cov zaub tuaj yeem rov pib dua uas yog tus pin 4 (txuas nrog SCK). Ib feem ntawm txoj cai yuav tsum nyob ntawm qhov pib ntawm cov ntawv (tawm ntawm teeb () thiab lub voj () ua haujlwm).

#suav nrog

Adafruit_SSD1306 zaub (4);

Tam sim no sab hauv teeb tsa () muaj nuj nqi peb yuav tsum hu ua qhov pib ua haujlwm ntawm cov khoom tso tawm los ntawm kev dhau peb qhov chaw nyob I2C raws li hauv qab no (SSD1306_SWITCHCAPVCC yog tus nqi tas li qhia qhov hom ntawm lub zog siv rau lub tsev qiv ntawv):

void teeb tsa () {

display.begin (SSD1306_SWITCHCAPVCC, 0x3C); display.display (); } void loop () {} // loop tuaj yeem khoob tam sim no

Tam sim no cov khoom pom tau npaj tiav thiab peb tuaj yeem hu nws cov haujlwm (piv txwv li display.write (), display.drawLine, thiab lwm yam). Cov ntawv tseem ceeb yog tias thaum twg los xij peb kos ib yam dab tsi los ntawm kev hu rau peb cov khoom tso tawm, peb yuav tsum hu rau display.display () muaj nuj nqi los ua qhov kev kos duab tshwm sim ntawm qib kho vajtse. Qhov no feem ntau yog los ntawm qhov tseeb tias kev kos duab ua haujlwm uas peb hu, tsuas yog hloov kho "hauv kev nco" sawv cev ntawm cov zaub rau qhov laj thawj ua tau zoo. Nws yeej caches cov kev hloov pauv hauv kev nco. Yog li peb yuav tsum nco ntsoov hu xov tooj () ua haujlwm thaum peb ua tiav ib yam dab tsi ntawm qhov screen.

display.write (…); // khaws hloov tshiab hauv kev nco

display.drawLine (…); // khaws hloov tshiab hauv kev nco. display.display (); // yaug txhua qhov kev hloov pauv rau cov khoom kho vajtse

Yog tias koj sim xa koj cov cai hauv theem no, koj yuav pom tias lub logo Adafruit Industries yuav tshwm. Koj yuav xav tsis thoob leej twg tau nug nws kom kos qhov ntawd! Qhov tseeb no yog qhov Adafruit lub tsev qiv ntawv ua. Nws pib ua cim xeeb ntawm tus qauv (qhov cim xeeb sawv cev ntawm cov khoom kho vajtse) nrog lub logo ntawm lub tuam txhab no. Yog tias koj tsis xav pom qhov ntawd thaum lub sijhawm pib, koj tuaj yeem sim hu rau display.clearDisplay () ua haujlwm zoo ua ntej hu rau display.display () hauv koj cov haujlwm teeb tsa. Lub luag haujlwm no, raws li nws lub npe qhia, tshem tawm cov zaub kom tiav.

#suav nrog

Adafruit_SSD1306 zaub (4); teeb tsa tsis muaj dab tsi () {display.begin (SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay (); display.display (); } void voj () {}

Raws li cov ntaub ntawv ntawm Adafruit_SSD1306 lub tsev qiv ntawv, koj tuaj yeem siv cov haujlwm sib txawv los ntawm chav kawm no los kos rau ntawm cov khoom lossis ncaj qha tswj cov pixels rau nws. Hauv ntu tom ntej peb yuav sim nthuav qhia qhov piv txwv rau txhua tus ntawm lawv kom koj tuaj yeem muaj tswv yim txog txoj kev nws ua haujlwm li cas. Feem ntau ntawm cov piv txwv no yuav tso tawm tsuas yog cov ntsiab lus zoo li qub, yog li peb tsuas tuaj yeem tso lawv hauv peb cov teeb tsa () muaj nuj nqi (tom qab pib ua haujlwm code). Los ntawm kev ua li ntawd nws yuav khiav ib zaug thiab tseem nyob ntawd.

Kauj Ruam 8: Muab Cov Ntawv Yooj Yim

Zaub Ntawv Yooj Yim
Zaub Ntawv Yooj Yim
Zaub Ntawv Yooj Yim
Zaub Ntawv Yooj Yim
Zaub Ntawv Yooj Yim
Zaub Ntawv Yooj Yim

Txhawm rau tso saib cov ntawv, peb tuaj yeem siv qhov yooj yim display.println () ua haujlwm ntawm lub tsev qiv ntawv. Nws lees txais cov ntawv raws li txoj hlua thiab sim ua kom pom nws. Nws yog ib qho tseem ceeb kom paub tias peb yuav tsum qhia lub tsev qiv ntawv nyob qhov twg ntawm cov zaub peb yuav nthuav qhia cov ntawv. Txhua lub pixel ntawm cov zaub muaj kev sib koom tes uas tau teev tseg nrog X thiab Y. X nce los ntawm sab laug mus rau sab xis thiab Y nce los ntawm sab saum toj mus rau hauv qab. Lub kaum sab laug sab saud ntawm qhov screen yog (X = 0, Y = 0) thiab kaum sab xis yog (X = 127, Y = 63). Kuv tau sau tseg qhov kev tswj hwm ntawm cov ces kaum ntawm thawj daim duab. Peb tuaj yeem siv lub display.setCursor () ua haujlwm kom qhia qhov twg ntawm cov zaub peb tab tom yuav tso tawm cov ntawv.

Lwm cov cuab yeej ntawm cov ntawv yog nws cov xim. Peb tuaj yeem hais qhia xim siv display.setTextColor () raws li pom ntawm cov qauv hauv qab no.

display.clearDisplay ();

display.setTextColor (WHITE); display.setCursor (35, 30); display.println ("Nyob Zoo Ntiaj Teb!"); display.display ();

Peb kuj tseem tuaj yeem siv display.write () ua haujlwm los tso saib ib tus cim. Nws lees txais tus lej cim ua uint8_t yam thiab qhia tus yam ntxwv sib raug rau tus lej ntawd ntawm txoj hlua. Raws li qhov piv txwv, yog tias peb xav pom tib txoj hlua siv txoj haujlwm no, peb tuaj yeem siv cov ntawv hauv qab no:

display.clearDisplay ();

display.setTextColor (WHITE); display.setCursor (35, 30); display.write (72); display.write (101); display.write (108); display.write (108); display.write (111); display.write (32); display.write (87); display.write (111); display.write (114); display.write (108); display.write (100); display.write (33); display.display ();

Nws kuj tseem tuaj yeem kos cov ntawv hauv cov xim dub nrog keeb kwm yav dhau dawb. Txhawm rau ua li ntawd, koj yuav tsum hu rau display.setTextColor ua haujlwm raws li hauv qab no:

display.clearDisplay ();

// Teem cov xim rau dub nrog rau tom qab dawb tso saib.setTextColor (BLACK, WHITE); display.setCursor (25, 30); display.println ("Cov ntawv hloov pauv!"); display.display ();

Koj kuj tseem muaj qhov kev xaiv teeb tsa qhov loj me ntawm cov ntawv siv display.setTextSize () muaj nuj nqi. Nws lees txais tus lej naj npawb raws li qhov loj me. Qhov ntau dua tus lej, cov ntawv yuav loj dua. Qhov loj me me yog 1 uas yog qhov loj me ntawm cov ntawv. Cov cai hauv qab no sim sau tsab ntawv "A" hauv 6 qhov sib txawv:

display.clearDisplay ();

display.setTextColor (WHITE); display.setCursor (0, 0); display.setTextSize (1); display.print ("A"); display.setTextSize (2); display.print ("A"); display.setTextSize (3); display.print ("A"); display.setTextSize (4); display.print ("A"); display.setTextSize (5); display.print ("A"); display.setTextSize (6); display.print ("A"); display.display ();

Kauj Ruam 9: Teeb Duab Yooj Yim

Teeb duab yooj yim
Teeb duab yooj yim
Teeb duab yooj yim
Teeb duab yooj yim
Teeb duab yooj yim
Teeb duab yooj yim

Teeb duab yooj yim xws li duab plaub, lub voj voog, daim duab peb sab, kab lossis kab lus yog yooj yim heev thiab muaj lub luag haujlwm tshwj xeeb rau txhua tus.

Teeb duab kab

Txhawm rau kos kab koj tuaj yeem hu rau display.drawLine (startX, startY, endX, endY, xim). Piv txwv li cov cai hauv qab no kos kab kab pheeb ces kaum hauv lub vijtsam kom lawv zoo li X loj:

display.clearDisplay ();

display.drawLine (0, 0, display.width () - 1, display.height () - 1, WHITE); display.drawLine (display.width () - 1, 0, 0, display.height () - 1, WHITE); display.display ();

Koj tuaj yeem nkag mus rau qhov dav thiab qhov siab ntawm cov zaub siv display.width () thiab display.height () ua haujlwm. Los ntawm kev ua li ntawd koj cov cai yuav ywj siab los ntawm lub vijtsam loj.

Teeb duab plaub

Txoj haujlwm los kos lub duab plaub yog display.drawRect (upperLeftX, upperLeftY, dav, qhov siab, xim). Nov yog cov cai uas kos peb lub duab plaub ntawm qee qhov chaw tsis raug:

display.clearDisplay ();

display.drawRect (100, 10, 20, 20, WHITE); display.fillRect (10, 10, 45, 15, WHITE); display.drawRoundRect (60, 20, 35, 35, 8, WHITE); display.display ();

Los ntawm kev hu xov tooj display.fillRect (sab saudLeftX, qaumLeftY, dav, siab, WHITE) koj tuaj yeem kos lub duab plaub uas puv los ntawm cov xim tshwj xeeb. Tsis tas li qhov haujlwm thib peb hauv qhov piv txwv no yog display.drawRoundRect (upperLeftX, upperLeftY, dav, qhov siab, kaum Radius, xim) uas raws li koj tuaj yeem pom hauv daim duab yog siv los kos cov duab plaub nrog puag ncig. Nws lees txais qhov ntsuas ntxiv ua ntej xim uas yog tus lej naj npawb qhia txog kaum lub kaum sab xis. Qhov loj dua tus nqi puag ncig lub ces kaum. Nws kuj tseem muaj qhov sib txuam ua tiav lub npe hu ua display.drawFillRoundRect uas kuv xav tias koj tuaj yeem kwv yees nws ua dab tsi.

Teeb duab lub voj voog

Txoj haujlwm yog display.drawCircle (centerX, centerY, radius, color). Nov yog ib qho piv txwv uas kos lub ntsej muag luag ntxhi:

display.drawCircle (60, 30, 30, WHITE);

display.fillCircle (50, 20, 5, WHITE); display.fillCircle (70, 20, 5, WHITE);

Ib yam li cov duab plaub, koj tuaj yeem siv cov duab ua haujlwm.cillCircle los kos lub voj voog uas muaj cov xim muab.

Teeb duab peb tog

Ahh, dua ib txoj haujlwm hu ua display.drawTriangle (poin1X, point1Y, point2X, point2Y, point3X, point3Y, xim) thiab coj los tso saib.fillTriangle uas kos daim duab peb sab.

display.drawTriangle (24, 1, 3, 55, 45, 55, WHITE);

display.fillTriangle (104, 62, 125, 9, 83, 9, WHITE);

Kos tus taw tes

Koj tseem tuaj yeem pleev xim qhov tshwj xeeb (uas yog hu ua pixel) ntawm qhov screen ntawm display.drawPixel (pixelX, pixelY, xim) ua haujlwm.

display.drawPixel (20, 35, WHITE);

display.drawPixel (45, 12, WHITE); display.drawPixel (120, 59, WHITE); display.drawPixel (97, 20, WHITE); display.drawPixel (35, 36, WHITE); display.drawPixel (72, 19, WHITE); display.drawPixel (90, 7, WHITE); display.drawPixel (11, 29, WHITE); display.drawPixel (57, 42, WHITE); display.drawPixel (69, 34, WHITE); display.drawPixel (108, 12, WHITE);

Kauj Ruam 10: Teeb Duab

Teeb duab
Teeb duab
Teeb duab
Teeb duab

Teeb duab yog txawv thiab nyuaj me ntsis. Raws li cov qauv duab yog monocolour, peb yuav tsum xub hloov peb cov duab rau hom ntawv hu ua mono xim bitmap (tseem hu ua dub thiab dawb). Hauv cov txheej txheem zoo li no, txhua lub pixel ntawm daim duab tau nthuav tawm nrog 0 lossis 1. Lub 1s sawv cev rau qhov muaj xim thiab 0s txhais tau tias yog qhov chaw khoob. Koj tuaj yeem pom qhov piv txwv ntawm Arduino lub logo hauv hom ntawv no nyob rau sab saum toj ntawm ntu no. Lub luag haujlwm los kos duab bitmap yog display.drawBitmap (topLeftX, topLeftY, imageData, dav, siab, xim). ImageData parameter yog cov lej ntawm cov lej hauv bytes. Txhua byte muaj 8 khoom, yog li txhua byte muaj cov ntaub ntawv ntawm 8 pixels ntawm daim duab. Los ntawm kev qhia qhov dav thiab qhov siab ntawm daim duab, kos duab ua haujlwm yuav paub los ntawm qhov me ntsis ntawm kab tom ntej ntawm pixels pib.

Cov tshuaj uas kuv tau xaiv los hloov kuv cov duab rau hom ntawv no yog thawj zaug siv online ntawm "duab rau ASCII hloov pauv" (piv txwv li https://my.asciiart.club) los hloov kuv daim duab rau txheej ASCII cov cim thiab tom qab ntawd hloov cov cim siv rau qhov chaw khoob los ntawm 0 thiab lwm tus los ntawm 1. Qhov ntawd yog qhov koj pom hauv qab no. Koj tuaj yeem xav txog txhua 0 thiab 1 ua lub pixel ntawm cov zaub. Yog li qhov loj me ntawm daim duab yuav tsum tsis pub tshaj peb cov duab loj uas yog 128x64.

Nco tseg: Siv cov txheej txheem ASCII no tsis yog qhov kev pom zoo vim tias vim qhov sib piv ntawm cov cim koj cov duab yuav hloov pauv (cov cim tsis yog lub xwmfab). Kuv sim cov txheej txheem no tsuas yog vim nws ua kom yooj yim dua los hloov cov duab rau hom ntawv xav tau. Txwv tsis pub nws yuav muaj peev xwm ua tiav qhov txiaj ntsig zoo tshaj plaws los ntawm qee qhov kev siv lossis siv qee cov ntawv thov siv hluav taws xob uas ua tsis tiav ntawm cov lus ntawm cov ntawv no.

00000000000000000000011111111111111111111110000000000000000000000000000000000000011111111111111111111111111111100000000000000000 0000000000000111111111111111111111111111111111111110000000000000 0000000000011111111111111111111111111111111111111111100000000000 0000000001111111111111111111111111111111111111111111111000000000 0000000111111111111111111111111111111111111111111111111110000000 0000011111111111111111111111111111111111111111111111111111100000 0000111111111111111111111111111111111111111111111111111111110000 0001111111111111111111111111111111111111111111111111111111111000 0011111111111111111111111111111111111111111111111111111111111100 0111111111111111000000011111111111111111100000001111111111111110 0111111111110000000000000001111111111000000000000000111111111110 1111111111000000001111000000001111000000001111000000001111111111 1111111110000011111111111100000110000011111111111100000111111111 1111111100000111111111111111000000001111111001111110000011111111 1111111100001111100000011111100000011111100000011111000011111111 1111111100001111100000011111100000011111100000011111000011111111 1111111100000111111111111111000000001111111001111110000011111111 1111111110000011111111111100000110000011111111111100000111111111 1111111111000000001111000000001111000000001111100000001111111111 0111111111110000000000000000111111110000000000000000111111111110 0111111111111111000000001111111111111111000000001111111111111110 0011111111111111111111111111111111111111111111111111111111111100 0001111111111111111111111111111111111111111111111111111111111000 0000111111111111111111111111111111111111111111111111111111110000 0000011111111111111111111111111111111111111111111111111111100000 0000000111111111111111111111111111111111111111111111111110000000 0000000011111111111111111111111111111111111111111111111100000000 0000000000011111111111111111111111111111111111111111100000000000 0000000000000111111111111111111111111111111111111110000000000000 0000000000000000111111111111111111111111111111110000000000000000 0000000000000000000001111111111111111111111000000000000000000000

Tam sim no peb yuav tsum faib txhua kab los ntawm 8, sawv cev rau byte thiab khaws cia rau hauv ib qho array raws li hauv qab no:

zoo li qub tsis kos npe char PROGMEM arduino_logo = {

B00000000, B00000000, B00000111, B11111111, B11111111, B11100000, B00000000, B00000000, B00000000, B00000000, B00000000, B01111111, B11111111, B11111111, B11111110, B00000000, B00000000,… // txuas mus txog qhov kawg ntawm daim duab};

Tom qab ntawd peb tuaj yeem kos nws ntawm cov zaub los ntawm kev hu rau drawBitmap ua haujlwm.

display.drawBitmap (32, 16, arduino_logo, 64, 32, WHITE);

Kauj ruam 11: Teeb meem

Nov yog qhov kev qhia ntev thiab yog li nws muaj qhov tshwm sim ntau yam uas tsis raug. Nov yog cov npe ntawm qee qhov ua yuam kev uas koj yuav ntsib thaum teeb OLED cov qauv rau koj txoj haujlwm (qee qhov tshwm sim rau kuv thaum npaj qhov kev qhia no).

Tsis muaj dab tsi tshwm sim txhua

Qhov no tuaj yeem tshwm sim rau ntau qhov laj thawj yog li kuv qhia kom txheeb xyuas cov npe hauv qab no uas tau txiav txim uas yuav tshwm sim hauv koj qhov haujlwm:

I2C chaw nyob tej zaum tsis yog lawm

Nco ntsoov tias koj tau teeb tsa qhov chaw nyob uas koj tau txais hauv i2c-scanner code hauv display.begin () muaj nuj nqi thaum teeb tsa koj cov khoom pom.

SCL thiab SDA muaj kev sib txuas tsis raug

Qhov no tau tshwm sim rau kuv. Yog tias koj siv Arduino Uno ces koj yuav tsum txheeb xyuas koj cov kev sib txuas ntxiv kom paub tseeb tias lawv tau txuas nrog tib yam li kuv li. Yog tias koj siv lwm tsab Arduino (piv txwv li Mega, Leonardo, thiab lwm yam), koj yuav tsum paub tias lawv yuav muaj lawv li I2C teeb tsa rau lwm tus pin. Koj tuaj yeem tshawb xyuas nws ntawm cov ntaub ntawv ntawm Wire library.

Koj tab tom kos ib yam dab tsi ntawm thaj chaw pom

Nov yog teeb meem software. Nws yog qhov ntau heev thaum siv kev kos duab ua haujlwm los xam qee qhov kev ua haujlwm tsis raug thiab yog li koj daim duab yuav hloov pauv lossis hauv qhov xwm txheej tsis zoo nws yuav ploj mus ntawm qhov xwm txheej. Txheeb xyuas koj cov kev suav thiab sim ua ib qib los ntawm kev kos duab los saib seb muaj dab tsi tshwm sim.

Cov ntawv tsis tau tshwm sim txhua

Koj tsis nco qab teeb cov xim ntawm cov ntawv lossis koj tau teeb nws rau tus nqi tsis raug

Koj yuav tsum hu rau setTextColor ua ntej kos cov ntawv. Txwv tsis pub koj tsis muaj qhov yuam kev, tab sis koj yuav pom tsis muaj dab tsi ntawm cov zaub. Tsis tas li koj yuav tau teeb cov ntawv xim ib yam li xim tom qab.

Koj siv tus font loj heev

Yog tias koj teeb cov ntawv me me rau tus nqi loj heev, nws tuaj yeem ua tau tias cov cim tau tawm ntawm thaj chaw pom.

Muaj qhov yuam kev suav sau txog qhov loj me

Qhov no kuj tau tshwm sim rau kuv thiab kuv xav tias nws yuav tshwm sim rau koj feem ntau. Nws yog vim cov zaub me me qhov tseem ceeb uas tau hais tseg hauv kab ntawv header Adafruit_SSD1306.h uas peb suav nrog nyob rau sab saum toj ntawm peb tsab ntawv. Cov ntaub ntawv no nyob ntawm {your-project-folder} libraries / Adafruit_SSD1306 / Adafruit_SSD1306.h. Yog tias koj qhib cov ntawv no koj yuav pom tias muaj cov lus tawm tswv yim raws li hauv qab no uas nws piav qhia tias koj yuav tsum tsis pom zoo tsuas yog qhov tas li uas sawv cev rau koj li OLED zaub module loj. Txog 128x64 cov qauv qhia, kab #define SSD1306_128_64 yuav tsum tsis suav nrog.

/*=====================================================================

SSD1306 Cov Lus Qhia ------------------------------------------------ ---------------------- Tus tsav tsheb tau siv ntau yam lus (128x64, 128x32, thiab lwm yam). Xaiv cov zaub uas tsim nyog hauv qab no los tsim qhov tsim nyog framebuffer, thiab lwm yam. SSD1306_128_64 128x64 pixel display SSD1306_128_32 128x32 pixel display SSD1306_96_16 --------------------------- --------------------------------------------* / #define SSD1306_128_64 / / #define SSD1306_128_32 // #define SSD1306_96_16 /*======================================================= ===============================*/

Kauj Ruam 12: Yuav Ua Dab Tsi Ntxiv?

OLED zaub raws li cov qauv tso tawm tuaj yeem muab sijhawm zoo rau koj los muab kev sib tham zoo rau koj cov haujlwm nyiam. Koj tuaj yeem sim ua raws cov tswv yim no ua qhov pib ua kom pom cov ntaub ntawv muaj txiaj ntsig ntawm nws lossis pab cov neeg siv kom paub tias muaj dab tsi tshwm sim lossis yog nws/nws xav tau ua qee yam. Nws yuav pom meej dua rau cov neeg siv los nyeem cov lus ntawm cov zaub dua li txhais lub xeev ntawm txoj haujlwm/khoom siv ntawm qee qhov LEDs.

Dab tsi koj tuaj yeem ua raws li qhov pib tuaj yeem yog:

  • Nyeem qhov ntsuas kub thiab ntsuas nws ntawm OLED module. Koj tuaj yeem ntxiv qhov ntsuas lossis ntsuas cua rau nws thiab tsim kom muaj qhov chaw ua haujlwm huab cua zoo.
  • Sim kos ib yam dab tsi ntawm cov zaub module siv lub joystick module ua khoom siv.
  • Sim kos cov yeeb yaj kiab ntawm cov zaub los ntawm ib theem zuj zus ntawm kev kos/ncua kev hu lossis Arduino cuam tshuam
  • Zaub koj lub cim kev cai ntawm koj li kev pib ua haujlwm (tsis yog Adafruit Logo)

Tsis txhob hnov qab qhia rau kuv ntawm cov lus pom, koj yuav ua dab tsi (lossis koj twb tau ua tiav lawm) siv OLED zaub module.

Pom zoo: