Cov txheej txheem:

Arduino TFT Drawing Program: 4 Kauj Ruam
Arduino TFT Drawing Program: 4 Kauj Ruam

Video: Arduino TFT Drawing Program: 4 Kauj Ruam

Video: Arduino TFT Drawing Program: 4 Kauj Ruam
Video: Подключаем дисплей от сотика или мобильного телефона к Ардуино 2024, Kaum ib hlis
Anonim
Arduino TFT Drawing Program
Arduino TFT Drawing Program
Arduino TFT Drawing Program
Arduino TFT Drawing Program
Arduino TFT Drawing Program
Arduino TFT Drawing Program

Cov lus qhia no qhia meej cov cai uas nkag mus rau hauv kev kos duab rau Arduino TFT screen. Txoj haujlwm no tshwj xeeb, txawm li cas los xij, vim nws tso cai rau kev txuag cov duab kos rau SD daim npav thiab thauj nws tom qab los kho ntau ntxiv!

Khoom siv

  1. Arduino Uno - thawj lossis yog clone sib xws
  2. TFT touchscreen - Kuv siv lub vijtsam Elegoo, txhais tau tias kuv xav tau Elegoo cov tsav tsheb.
  3. Micro SD nyeem ntawv pawg - siv los khaws cov ntaub ntawv teeb duab rau SD daim npav. Kuv lub vijtsam tau tsim los nyeem hauv qab cov zaub.
  4. Stylus - kuv lub vijtsam tuaj nrog ib qho. Ntiv tes ua haujlwm zoo ib yam nkaus.
  5. Micro SD daim npav - tsis pub ntau tshaj 32GB, vim exFAT kev txwv kev txwv (Arduino tuaj yeem nyeem FAT32 cov ntawv teev npe tab sis tsis exFAT. Feem ntau daim npav loj tau ua nrog exFAT.) Nov yog yam uas koj yuav muab tso rau hauv lub xov tooj nrog nthuav dav cia.
  6. Khoos phis tawj nrog Arduino IDE
  7. Programming cable - USB A rau USB B. Kuv Arduino tuaj nrog ib qho.
  8. SD daim npav adapter - siv los hloov Micro SD daim npav rau hauv ib qho SD tso rau hauv daim npav SD LOSSIS ib qho uas txuas daim npav SD mus rau USB qhov.

Kauj ruam 1: Format SD Card

Format SD Card
Format SD Card
Format SD Card
Format SD Card
  1. Nqa daim Micro SD daim ntawv thiab txuas nws rau koj lub khoos phis tawj siv koj daim npav SD daim npav
  2. Qhib File Explorer thiab nrhiav daim npav SD.
  3. Right-click nws thiab xaiv Hom ntawv.
  4. Teem cov kev xaiv raws li lub screenshot.
  5. Nyem Pib
  6. Ncua daim npav thaum tus txheej txheem tiav.

Yog tias koj tsis siv lub Windows, sim siv SD Formatter los ntawm SD koom haum.

Kauj Ruam 2: Npaj Arduino

Npaj Arduino
Npaj Arduino
Npaj Arduino
Npaj Arduino
  1. Nias koj lub vijtsam tiv thaiv mus rau Arduino, ua tib zoo saib kab kab.
  2. Ntxig daim npav SD rau hauv tus nyeem ntawv hauv qab lub vijtsam.

Kauj ruam 3: Arduino Sketch

Txawm hais tias daim ntawv teev npe tau yooj yim zoo nkauj, muaj ib tuj ntawm cov cai. Kuv yuav hla nws ib qib zuj zus ntawm no.

#suav nrog

#include #include #include #include

Elegoo_GFX, _TFTLCD, thiab TouchScreen yog txhua yam khoom siv tshwj xeeb. Yog tias koj siv lub vijtsam sib txawv, siv cov khw muag khoom muab cov tsev qiv ntawv.

SPI thiab SD tau siv los sib txuas lus nrog SD daim npav. SPI yog cov txheej txheem siv los ntawm SD daim npav tswj hwm.

#if txhais (_ SAM3X8E _) #undef _FlashStringHelper:: F (string_literal) #define F (string_literal) string_literal #endif

Qhov no kuj yog kho vajtse tshwj xeeb.

#define YP A3 // yuav tsum yog tus pin analog #txhais XM A2 // yuav tsum yog tus pin analog #define YM 9 #define XP 8

// Kov Rau Tshiab ILI9341 TP

#define TS_MINX 120 #define TS_MAXX 900 #define TS_MINY 70 #define TS_MAXY 920

#Txhais CSPIN 10

#txhais LCD_CS A3

#define LCD_CD A2 #define LCD_WR A1 #define LCD_RD A0 #define LCD_RESET A4

Txhua ntawm cov lus #define ua rau IDE hloov lub npe nrog tus nqi. Ntawm no, lawv teeb LCD thiab SD I/O pins.

// Muab cov npe rau qee qhov 16-ntsis xim qhov tseem ceeb: #define BLACK 0x0000 #define WHITE 0xFFFF #define RED 0xF800 #define BLUE 0x001F #define GREEN 0x07E0

Nov yog qee qhov xim siv hauv txoj cai. #txhais-ua lawv ua rau nyeem cov cai yooj yim dua.

#define PENRADIUS 3

Qhov no piav qhia qhov loj ntawm tus cwj mem kos duab.

#define MINPRESSURE 10#txhais MAXPRESSURE 1000

// Kom zoo dua qhov ntsuas qhov tseeb, peb yuav tsum paub qhov ua haujlwm

// nruab nrab ntawm X+ thiab X- Siv ib lub multimeter los nyeem nws // Rau qhov kuv tab tom siv, nws 300 ohms hla X phaj TouchScreen ts = TouchScreen (XP, YP, XM, YM, 300);

Elegoo_TFTLCD tft (LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

Cov lus no piav qhia qhov siab xav tau los sau npe kov, pib ua haujlwm kov, thiab pib lub vijtsam.

Cov ntaub ntawv cia; int storageSize; int stoX = 1; int stoY = 1;

Cov no yog qhov hloov pauv rau qhov khaws cia ntawm qhov program.

teeb tsa tsis muaj dab tsi (tsis muaj dab tsi) {Serial.begin (9600); Serial.println ("Xim program");

tft.reset ();

uint16_t tus cim = tft.readID ();

yog (tus cim == 0x0101) {tus cim = 0x9341; Serial.println (F ("Pom 0x9341 LCD tsav tsheb")); }

// Pib qhov screen

tft.begin (tus cim); tft.setRotation (2);

pinMode (13, NTAWV);

// Pib SD daim npav

yog (! SD.begin (CSPIN)) {Serial.println ("SD pib ua tsis tau tejyam"); rov qab; } Serial.println ("SD pib ua ntej");

// Kos rau keeb kwm yav dhau

drawBackground (); }

Lub teeb ua haujlwm pib Serial yog tias nws muaj, rov pib dua lub vijtsam, kuaj pom tus neeg tsav tsheb TFT, pib lub vijtsam, pib daim npav, thiab hu ua haujlwm los kos keeb kwm yav dhau.

Kuv yuav hla mus rau qhov tseem ceeb ntawm lub voj kev ua haujlwm. Txhua yam ntxiv tsuas yog siv los tsav lub vijtsam kov.

// Tshawb xyuas lub vijtsam nias thiab khaws nws rau qhov hloov pauv yog (p.z> MINPRESSURE && p.z <MAXPRESSURE) {// Nplai p.x = daim ntawv qhia (p.x, TS_MINX, TS_MAXX, tft.width (), 0); p.y = (tft.height () - map (p.y, TS_MINY, TS_MAXY, tft.height (), 0));

// Kos duab

yog (p.y> 21) {// Txuag cov ntaub ntawv rau SD daim npav cia = SD.open ("storage.txt", FILE_WRITE); storage.print (p.x); storage.print (","); storage.println (p.y); cia.close ();

// Dot ntawm txoj haujlwm kov

tft.fillCircle (p.x, p.y, PENRADIUS, WHITE); }

// Rho tawm khawm

yog ((p.y 198) && (p.x <219)) {deleteStorage (); }

// Thauj khawm ua

yog ((p.y 219)) {loadStorage (); }}

Yog tias pom xov xwm, teeb tsa qhov txawv ntawm qhov chaw ntawm xovxwm.

Tom qab ntawd, yog tias cov xovxwm nyob hauv thaj chaw teeb duab, khaws cov ntsiab lus rau SD daim npav hauv kev khaws cia.txt thiab kos lub voj voog ntawm qhov chaw nias, nrog rau qhov loj me thiab xim.

Tom qab ntawd, yog tias qhov xovxwm nyob ntawm qhov chaw ntawm lub pob rho tawm, khiav lub luag haujlwm uas tshem tawm cov duab khaws tseg. Yog tias koj siv lub vijtsam loj sib txawv, sim ua si nrog lub pob qhov chaw qhov tseem ceeb.

Tom qab ntawd, yog tias qhov xovxwm nyob ntawm qhov chaw khawm khawm, khiav lub luag haujlwm uas thauj cov duab khaws cia. Yog tias koj siv lub vijtsam loj sib txawv, sim ua si nrog lub pob qhov chaw qhov tseem ceeb.

Tam sim no, kuv yuav piav qhia lub luag haujlwm.

Thawj qhov haujlwm yog hu ua teeb tsa kos keeb kwm yav dhau thiab cov nyees khawm.

void drawBackground () {// Teeb tom qab tft.fillScreen (BLACK);

// Xim ntawv

tft.setTextColor (WHITE); tft.setTextSize (3); tft.setCursor (0, 0); tft.println ("Xim");

// Load khawm

tft.fillRect (219, 0, 21, 21, GREEN);

// Ntshiab khawm

tft.fillRect (198, 0, 21, 21, RED); }

Nws ua rau lub vijtsam dub, sau lo lus Xim, thiab kos cov duab plaub fab rau cov nyees khawm. Yog tias koj siv lub vijtsam loj sib txawv, sim ua si nrog khawm qhov chaw qhov tseem ceeb.

void deleteStorage () {// Rho tawm cov ntawv SD.remove ("storage.txt");

// Teem keeb kwm yav dhau

tft.fillScreen (BLACK);

// Rho tawm cov ntawv ua tiav

tft.setTextColor (WHITE); tft.setTextSize (2); tft.setCursor (0, 0); tft.println ("storage.txt deleted");

// Cia tus neeg siv nyeem nws

ncua (2000);

// Kos duab ntxiv

drawBackground (); }

Kev tshem tawm cov haujlwm tshem tawm cov ntaub ntawv khaws cia.txt, ua rau lub vijtsam dub, thiab muab cov lus ua tiav rau kev tshem tawm. Tom qab ntawd nws hu rau drawBackground ua haujlwm kom tso cai rau koj pib pleev xim lwm yam.

void loadStorage () {// Tsis txhob rov ua dua los ntawm cov ntiv tes qeeb (250);

// Txheeb xyuas cov ntaub ntawv khaws cia

yog (! SD.exists ("storage.txt")) {Serial.println ("Tsis muaj cov ntaub ntawv khaws cia.txt"); rov qab; }

// Qhib cov ntawv hauv hom nyeem nkaus xwb

cia = SD.open ("storage.txt", FILE_READ);

// Thaum muaj cov ntaub ntawv, thaum (stoY> 0) {// Hloov kho txoj haujlwm hloov pauv stoX = storage.parseInt (); stoY = storage.parseInt ();

// Kos los ntawm kev cia

tft.fillCircle (stoX, stoY, PENRADIUS, WHITE); } // Kaw cov ntaub ntawv cia.close (); }

Thaum kawg, lub luag haujlwm loadStorage tshawb xyuas cov ntaub ntawv khaws cia, qhib nws hauv hom nyeem nkaus xwb, tom qab ntawd rov ua dua lub voj no:

Tsuav yog muaj cov ntaub ntawv ntau ntxiv,

  1. Hloov kho txoj haujlwm hloov pauv nrog cov ntaub ntawv txheeb cais los ntawm storage.txt
  2. Kos ib lub voj voog ntawm qhov chaw thau khoom

Thaum lub voj ua tiav thiab tsis muaj cov ntaub ntawv ntxiv, nws kaw cov ntaub ntawv khaws cia.

Cov cai rau daim duab no tuaj yeem pom hauv qab no. Tsuas yog rub nws, qhib nws hauv Arduino, thiab xa nws mus rau koj lub rooj tsavxwm!

Kauj Ruam 4: Siv Txoj Haujlwm no

Siv Txoj Haujlwm no
Siv Txoj Haujlwm no

Tsuas yog ntsaws rau hauv koj Arduino rau lub zog siv hluav taws xob - khoos phis tawj, roj teeb, phab ntsa wart, thiab lwm yam thiab pib teeb duab. Txhawm rau lwv koj daim duab thiab nws cov ntaub ntawv khaws tseg, nias lub pob liab. Txhawm rau rub daim duab los ntawm kev khaws cia thiab ua haujlwm txuas ntxiv rau nws, nyem lub pob ntsuab. Txoj hauv kev no, koj tuaj yeem rov ua ntau zaus ntawm daim duab!

Raws li kev txuas ntxiv, sim npaj cov duab hauv koj lub computer:

  1. Txuas daim npav SD nrog cov ntaub ntawv rau hauv koj lub computer.
  2. Qhib cia.txt hauv koj cov ntawv nyiam/tus lej hloov kho.
  3. Luam tag nrho cov txiaj ntsig hauv storage.txt.
  4. Ua raws qhov txuas no mus rau qhov phiaj xwm phiaj xwm phiaj xwm.
  5. Rho tawm ob qhov piv txwv piv txwv ntawm sab laug.
  6. Muab koj cov ntaub ntawv tso rau qhov piv txwv cov ntsiab lus.

Nov yog txoj hauv kev zoo los qhia tawm koj cov duab kos - tej zaum txawm tias sim hloov qhov xim ntawm Arduino lossis hauv cov ntsiab lus -phiaj xwm!

Kev hloov kho tau txais tos, thiab kuv xav pom qee cov lus qhia hauv cov lus. Ua tsaug rau qhov saib ntawm no thiab kuv vam tias koj yuav pom kev siv zoo rau nws hauv koj tus kheej cov haujlwm!

Pom zoo: