Se afișează postările cu eticheta ILI9341. Afișați toate postările
Se afișează postările cu eticheta ILI9341. Afișați toate postările

luni, 20 martie 2023

Statie meteo pe afisaj tactil de 2.8" cu ILI9341

     Un proiect interesant, ce merita reprodus, este aceasta statie meteo ce foloseste si partea de comanda tactila, in stilul telefonului (doar ca ecranul senzorial este o generatie mai veche si nu e asta usor de folosit ca aceea a unuia de la un telefon).

   Proiectul se gaseste la github.com/ThingPulse/esp8266-weather-station-color si un kit se poate cumpara de aici !

   Multe detalii se gasesc si in articolul ESP8266 Colored Weather Station

dar si in articolul Statie meteo cu Esp8266 pe TFT 2,8 240X320 ILI9341

   Schema de conectare este foarte simpla

asa ca am facut montajul pe un bradboard.
   Dupa incarcarea programului (ce implica instalarea librariilor, necesare introducerea datelor de utilizator pentru datele meteo de la openweathermap.org)  pe ecran apare un mesaj sa calibram ecranul tactil, adica sa apasam in 2 colturi, unde apare o bulina, dua care vedem informatiile meteo si ora, in format de 24 ore
iar daca apasam pe ora, apare formatul de 12 ore
  Apasand pe mijloc, apar informatii despre sistem
prognoza pe zilele urmatoare
si apoi despre datele curente
  Am facut 2 filmuletele:
  Dupa asta am cautat niste proiecte de carcase ce se pot realiza la imprimanta 3D, si am ales 2:
TFT 2.8" ESP8266 NodeMCU Case
   A doua carcasa e mai usor de folosit, prima implica scoaterea pinilor de la afisaj.

PS: am gasit in instructiunile kit-ului si care sunt zonele de apasare pe ecran:

sâmbătă, 11 martie 2023

Ceas NTP pe afisaj grafic cu driver ILI9341 si Wemos D1 (ESP8266) - partea a 2-a

    Am adaugat ceasului din articolul anterior si posibilitatea selectiei orei de vara/iarna, pentru asta am adaugat un comutator

  Daca pinul D6 este conectat la masa (GND), avem selectata ora de iarna (cea normala)
iar daca pinul D6 este conectat la +3,3V, avem selectata ora de vara
programul modificat este TFT_Clock_analog_digital_v1.ino si modul de functionare al ceasului se vede in cele 2 filmulete:
    Dupa cum scriam si in articolul precedent, am gasit un ceas similar, in articolul TUTORIAL 8: ESP8266 INTERNET CLOCK
caruia i-am adaptat biblioteca folosita de mine anterior, inclusiv selectie ora de vara sau de iarna, asa ca programul devine InternetClock_ILI9341_1.ino
- ora de vara
- ora de iarna

   Am facut si 2 filmulete:

Ceas NTP pe afisaj grafic cu driver ILI9341 si Wemos D1 (ESP8266)

    Am achizitionat un afisaj de 2,8" (diagonala de 7,1cm) si driver ILI9341. In anul 2014 lucrasem cu un afisaj cu diagonala mai mica (2,2"= 5,6cm) si acelasi driver (ILI9341), controlandu-l cu Arduino Uno, Mega sau Due (vedeti articolele).

  De data asta, am vrut sa fac un ceas NTP care sa fie controlat de un ESP8266 (placa Wemos D1 mini), asa ca am apelat la mai multe biblioteci de pe net, dar am ajuns sa fiu multumit de rezultatele obtinute doar cu biblioteca lui Bodmer TFT_eSPI.

  Schema de conectare este foarte simpla

iar primul program mai complex, pentru a-mi usura munca pentru ceasul NTP a fost pentru un pseudoceas cu o prezentare de ceas analogic si unul digital: TFT_Clock_analog_digital_v0.ino., dupa cum se vede si in filmulele:
   Dupa aceea, am adaptat programul sa am un ces NTP real, programul devenind TFT_Clock_analog_digital_v0a.ino iar ceasul poate fi vazut in functiune in filmuletele:

    Am gasit un ceas similar, in articolul TUTORIAL 8: ESP8266 INTERNET CLOCK
caruia i-am adaptat biblioteca folosia de mine anterior, asa ca prograamul devine InternetClock_ILI9341_0.ino

sâmbătă, 13 septembrie 2014

Arduino Due si afisajul QVGA de 2,2" (5,6cm) comandat de ILI9341

   Dupa ce am constatat ca datele pe afisajul color cu driver ILI9341 se "misca" greu, am achizitionat si o placa de dezvoltare Arduino Due,
care seamana foarte mult cu Arduino Mega.
   Fata de generata anterioara, care lucra la frecventa de 16MHz, 32k de memorie de lucru la Uno, respectiv 256k memorie de lucru la Mega si tensiunile de comanda de 5V, Due foloseste un procesor AT91SAM3X8E  pe 32 de biti, care lucreza la 84MHz, 512k memorie pentru aplicatii, iar tensiunile de lucru sunt de 3,3V.
   Prima treba care am facut-o a fost sa inlocuiesc programul Arduino IDE cu versiunea care recunoaste pe Arduino Due si aceasta este Arduino Ide 1.5.7 Beta.
   Dupa scurte teste de incarcare si clipire de LED-uri, am trecut la inlocuirea placii Arduino Mega de la statia meteo cu senzorul DS18B20 si DHT11, pe care am prezentat-o in articolul anterior. Am eliminat si interfata logica realizata cu integratul CD4050, deoarece, atat placa Arduino Due, cat si afisajul cu driver ILI9341 lucreaza la 3,3V.
   Am testat intai exemple cu libraria grafica ucglib, facand si un filmulet numit test afisaj 2,2" cu ILI9341 si libraria ucglib cu Arduino Due
   A trebuit sa update-z si libraria pentru senzorii din seria DHT, pentru a lucru cu Due, chiar pe site-ul lui Arduino, aceasta se gaseste in articolul Class for DHTxx sensors (xx = 11-21-22-33-44).
   Am adaugat si senzorul de presiune BMP180 pentru a avea o ministatie meteo cat mai completa, obtinand pe ecran ceva de genul:
iar filmul care prezinta acest montaj se numeste ministatie meteo cu DHT11, DS18B20 si BMP180 pe ecran TFT de 2.2" cu ILI9341 pe un Arduino Due
   Schema de conectare este asemanatoare celei din articolul precedent, doar ca este eliminat integratul de interfatare (CD4050), si se tine cont ca esta un conector SPI dedicat (langa procesor, deasupra inscriptiei DUE). Senzorul de umiditate cu DHT11 este conectat la pinul D37 fiind alimentat la 3,3V ca si senzorul BMP180, care este conectat prin protocol i2c la SDA (D20) si SCL (D21).
   Sketch-ul ultimei variante este: 
/*
original sketch by niq_ro from http://nicuflorica.blogspot.com using ucglib library
version for 2.2" TFT with ILI9341  - 2014.07.29, Craiova - Romania
use Universal uC Color Graphics Library from https://code.google.com/p/ucglib/
*/
#include <SPI.h>
#include "Ucglib.h"
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 6 , /*cs=*/ 5, /*reset=*/ 4); // at Uno
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); // at Mega
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 52, /*data=*/ 51, /*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); //at Mega
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 76, /*data=*/ 75, /*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); //at Mega
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); //at Mega or Due
/*

Due  |Mega | Uno | TFT - ILI9341
----------------------
D22  | D22 | D4  | RESET
D24  | D24 | D5  | CS
D26  | D26 | D6  | D/C
 ?   | ?   | LED (via 220 ohms resistor at 5V)
MOSI | D51 | D11 | MOSI
MISO | D50 | D12 | MISO
SCK  | D52 | D13 | SCK
-----------------------------
with CD4050 adapter or 10k resistor, power supply and logical levels is 3.3V
schematic: http://nicuflorica.blogspot.ro/2014/07/afisaj-grafic-color-qvga-de-22-cu.html
*/

#include <dht.h> 
// from http://playground.arduino.cc/Main/DHTLib
dht DHT;

// https://github.com/adafruit/Adafruit-BMP085-Library
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;

float t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;
float t13, t23;
int h11, h12;
int p1, p2;

void setup() {
delay(1000);
bmp.begin();

ucg.begin(UCG_FONT_MODE_TRANSPARENT);
ucg.clearScreen();
ucg.setFont(ucg_font_ncenR14r);
ucg.setColor(255, 0, 255);
ucg.setColor(1, 255, 0,0);

  ucg.setRotate90();
  ucg.setColor(255, 255, 255); // culoare alba
  ucg.drawFrame(0,0,320,240); //   
  ucg.setFont(ucg_font_courB24); // 20 pixel height
  ucg.setColor(255, 0, 0); // culoare rosie
  ucg.setPrintPos(60,30);
  ucg.print("Ministatie");
  ucg.setColor(0, 255, 0); // culoare verde
  ucg.setColor(0, 255, 0);
  ucg.setColor(0, 0, 255); // culoare albastru
  ucg.setPrintPos(17, 60);
  ucg.print("meteo cu DHT11");
  ucg.setPrintPos(55, 90);
  ucg.setColor(5, 255, 0); // culoare verde
  ucg.print("si BMP180");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 0); // culoare galbena
  ucg.setPrintPos(25,120);
  ucg.print("ecran grafic 2,2'' (5,6cm)");
  ucg.setFont(ucg_font_courB24); // 20 pixel height 
  ucg.setColor(0, 255, 255); // culoare bleo
  ucg.setPrintPos(10,150);
  ucg.print("QVGA cu ILI9341");
  ucg.setColor(255, 0, 255); // culoare mov
  ucg.setPrintPos(20,180);
  ucg.print("versiune 4.4.0");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 255); // culoare alb
  ucg.setPrintPos(60,210);
  ucg.print("realizat de niq_ro");

delay(5000);
ucg.clearScreen();
t13=40.0;
h12=40.0;
p2 = 900;
}

void loop() {
 // BMP180 part 
 int p1 = bmp.readPressure()/101.325;
 p1 = p1 * 0.760;
     
 // DHT11 part
 int chk = DHT.read11(37);
 delay(1000);
// timeout;
 int h11 = DHT.humidity; 
 if (DHT.humidity < 0) h11 = 0;

// BMP180 part 2
t12 = bmp.readTemperature();
int t15 = t12;
float t16 = 10*t15;
t16 = t16/10;

t16 = t12;
if (t16 != t13) 
{
temperaturi(t16, t13, 20, 0); // temperature, old temperature, x,y
termometre(t16, 20);
}

if (h11 != h12) 
{
// umiditate(h11, h12, 115, 90); // humidity, old humidity, x, y
 umiditate(h11, h12, 40, 180); // humidity, old humidity, x, y
 barca (h11, h12);
}


if (p1 != p2) 
{
 presiune(p1, p2, 100, 60); // pressure, old pressure, x, y
// barca (h11, h12);
}



//}
delay (2000); 
t13=t16;
h12=h11;
p2=p1;
} // final de program, se revine de la inceput

void temperaturi(float t3, float t4, int ics, int igrec)
{
int t5 = t3;
int t6 = t4;
ucg.setFont(ucg_font_courB24);    
if (t3*t4 < 0)
{ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
 ucg.drawHLine(ics+7, qy + igrec , 105);
}
}
int t51 = t5/10;
int t61 = t6/10;
ucg.setColor(0, 0, 0); 
if (t51 != t61)
{
for (int qy = 39 ; qy < 60; qy++) 
{
ucg.drawHLine(ics+28, qy + igrec , 21);
}
}
t5 = t3 - t51*10;
t6 = t4 - t61*10;
if (t5 != t6)
{
for (int qy = 39 ; qy < 60; qy++) 
{
ucg.drawHLine(ics+49, qy + igrec , 21);
}
} 
for (int qy = 39 ; qy < 60; qy++) 
{
 ucg.drawHLine(ics+91, qy + igrec , 21);
}
ucg.setColor(255, 0, 0);  
ucg.setPrintPos(10 + ics, 30 + igrec);
//ucg.print("t  :"); 
ucg.print("temperatura:"); 
ucg.setPrintPos(10 + ics, 60 + igrec);
if (t3 > 10.0) ucg.print("+");
else
 if (t3>0.0) ucg.print(" +");
else
 if (t3<0.0)
{
 t3=-t3;
 if (t3 > 10.0) ucg.print("-");
else
 if (t3 > 0.0) ucg.print(" -");
}  
if (t3==0.0) ucg.print("  ");
ucg.print(t3,1); 
ucg.print(" C"); 
ucg.setFont(ucg_font_fur17r); 
ucg.setPrintPos(30 + ics, 35 + igrec);
//if (igrec == 0) ucg.print("int"); 
//else ucg.print("ext"); 
ucg.setPrintPos(115 + ics, 50 + igrec);
ucg.print("o"); 

ucg.setPrintPos(75 + ics, 60 + igrec);
ucg.print(",");


}

void termometre (float t, int ics1)
{
ucg.setColor(255, 255, 255);  
ucg.drawFrame(ics1-4,10,9,200); 
ucg.drawCircle(ics1,220,10,UCG_DRAW_ALL);  
for (int a = 0; a < 10; a++)
{
ucg.drawLine(ics1-5,20+20*a,ics1-7,20+20*a);
ucg.drawLine(ics1+5,20+20*a,ics1+7,20+20*a);
}
ucg.drawLine(ics1-10,140,ics1+10,140);  
ucg.setFont(ucg_font_courB24);    
ucg.setPrintPos(13 + ics1, 149);
ucg.print("0 C"); 
ucg.setFont(ucg_font_fur17r); 
ucg.setPrintPos(37 + ics1, 135);
ucg.print("o"); 
int lin = 140 - 2*t;
ucg.setColor(0, 0, 0);  // black 
ucg.drawBox(ics1-2,21, 5, lin+5);
ucg.setColor(255, 0, 0);  
ucg.drawDisc(ics1,220,8,UCG_DRAW_ALL);  
ucg.drawBox(ics1-2,lin, 5, 210-lin);
}

void umiditate(int h3, int h4, int zet, int igrec1)
{
  ucg.setFont(ucg_font_courB24); // 20 pixel height   

// sterg semnul ??
int h51 = h3/10;
int h61 = h4/10;

ucg.setColor(0, 0, 0); 

// sterg zeci daca e cazul
if (h51 != h61)
{
//ucg.setColor(255, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
//  ucg.drawHLine(zet+28, qy + igrec1 , 21);
  ucg.drawHLine(zet+40, qy + igrec1, 42);
}
}
  int h5 = h3 - h51*10;
  int h6 = h4 - h61*10;

// sterg unitati daca e cazul
//if ((t5 != t6) || (t5-t6>0.2))
if (h5 != h6)
{
//ucg.setColor(0, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(zet+79, qy + igrec1 , 21);
}
} 

 ucg.setColor(0, 255, 255);  
 ucg.setPrintPos(zet, 30 + igrec1);
 ucg.print("umiditate:"); 


//ucg.setFont(ucg_font_fub42n); // 20 pixel height   
ucg.setPrintPos(40 + zet, 60 + igrec1);
//if (h3 > 10) ucg.print("+");
if (h3 > 10) ucg.print(" ");
else
{
//ucg.setColor(255, 255, 255); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(zet+40, qy + igrec1 , 42);
}
if (igrec1 <30) ucg.setColor(255, 255, 0);  
else ucg.setColor(0, 255, 255); 
ucg.setPrintPos(61 + zet, 60 + igrec1);
//ucg.print("+");
ucg.print(" ");
}
 ucg.print(h3); 
 ucg.print("%"); 
}


void barca (int h, int h2) // new humidity, old humidity.,
{
int xx = 280; 
int yy = 230;

//sterg barca
//ucg.setColor(100,100,100);  
ucg.setColor(0,0,0);  
ucg.drawBox(xx-25, yy-20-h2, 50, 30);


//sterg apa
//ucg.setColor(125, 125, 125);  
ucg.setColor(0, 0, 0);  
ucg.drawBox(xx-35, yy+10-h2, 70, h2-h);

//desenez apa
ucg.setColor(0, 255, 255);  
ucg.drawBox(xx-35, yy+10-h, 70, h);

//desenz barcuta;
//desenez carena
ucg.setColor(255, 255, 0);  
ucg.drawBox(xx-20, yy-h, 40, 10);
ucg.drawTriangle(xx-25, yy-h, xx-20, yy-h, xx-20, yy+10-h);
ucg.drawTriangle(xx+25, yy-h, xx+20, yy-h, xx+20, yy+10-h);
//desenez catarg
ucg.drawBox(xx-1, yy-20-h, 2, 20);
//desenez velele
ucg.setColor(0, 0, 255); // vela albastra  
ucg.drawTriangle(xx+2, yy-20-h, xx+2, yy-h, xx+20, yy-h);
ucg.setColor(255, 0, 0); // vela rosie  
ucg.drawTriangle(xx-2, yy-15-h, xx-2, yy-h, xx-20, yy-h);
}

void presiune (int p3, int p4, int zeti, int igreci)
{
  ucg.setFont(ucg_font_courB24); // 20 pixel height   

// sterg semnul ??
int p51 = p3/10;
int p61 = p4/10;

//ucg.setColor(0, 0, 0); 
ucg.setColor(100, 0, 0); 

// sterg zeci daca e cazul
if (p51 != p61)
{
//ucg.setColor(255, 255, 255); 
ucg.setColor(0, 0, 0); 
for (int qy3 = 39 ; qy3 < 60; qy3++) 
{
//  ucg.drawHLine(zet+28, qy + igrec1 , 21);
//  ucg.drawHLine(zeti+40, qy3 + igreci, 42);
  ucg.drawHLine(zeti+61, qy3 + igreci, 42);
}
}
  int p5 = p3 - p51*10;
  int p6 = p4 - p61*10;

// sterg unitati daca e cazul
//if ((t5 != t6) || (t5-t6>0.2))
if (p5 != p6)
{
//ucg.setColor(0, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy4 = 39 ; qy4 < 60; qy4++) 
{
//  ucg.drawHLine(zeti+79, qy4 + igreci , 21);
  ucg.drawHLine(zeti+100, qy4 + igreci , 21);
}
} 

 ucg.setColor(255, 255, 0);  
 ucg.setPrintPos(zeti, 30 + igreci);
 ucg.print("presiune:"); 


//ucg.setFont(ucg_font_fub42n); // 20 pixel height   
ucg.setPrintPos(40 + zeti, 60 + igreci);
//if (h3 > 10) ucg.print("+");
if (p3 > 10) ucg.print(" ");
else
{
//ucg.setColor(255, 255, 255); 
ucg.setColor(0, 0, 0); 
for (int qy5 = 39 ; qy5 < 60; qy5++) 
{
//  ucg.drawHLine(zeti+40, qy5 + igreci , 42);
  ucg.drawHLine(zeti+61, qy5 + igreci , 42);
}
ucg.setColor(255, 255, 0); 
ucg.setPrintPos(61 + zeti, 60 + igreci);
//ucg.print("+");
ucg.print(" ");
}
 ucg.print(p3); 
 ucg.print("mm Hg"); 
}
   Filmuletul, care prezinta modul de functionare, este ministatie meteo cu DHT11 si BMP180 pe ecran TFT de 2.2" cu ILI9341 pe un Arduino Due
15.9.2014     Pentru a aparea confuzii la modul de conectare al afisajului si senzorilor, pe forumul Arduino la http://forum.arduino.cc/index.php/topic,132130.0.html este prezentata placa de dezvoltare Arduino Due, foarte explicit:
   In programul Fritzing.org se gaseste si placa Arduino Due, din care am facut o captura de ecran si am subliniat conectorul SPI folosit pentru controlul afisajului:
   Am desenat si partea de conectare a afisajului cu driver ILI9341, folosindu-ma de imaginea dinainte:
iar conectarea senzorilor la placa Arduino Due se face astfel:


20.09.2014
   Pentru prietenul meu, Adrian Roman, am modificat sketch-ul pentru a folosi doar informatiile de la senzorul DHT11 (am eliminat partea de BMP180):
   Sketck-ul simplificat este:
/*
original sketch by niq_ro from http://nicuflorica.blogspot.com using ucglib library
version for 2.2" TFT with ILI9341  - 2014.07.29, Craiova - Romania
use Universal uC Color Graphics Library from https://code.google.com/p/ucglib/
*/
#include <SPI.h>
#include "Ucglib.h"
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 6 , /*cs=*/ 5, /*reset=*/ 4); // at Uno
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); // at Mega
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 52, /*data=*/ 51, /*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); //at Mega
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 76, /*data=*/ 75, /*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); //at Mega
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); //at Mega and Due
/*

Due  |Mega | Uno | TFT - ILI9341
----------------------
D22  | D22 | D4  | RESET
D24  | D24 | D5  | CS
D26  | D26 | D6  | D/C
 ?   | ?   | LED (via 220 ohms resistor at 5V)
MOSI | D51 | D11 | MOSI
MISO | D50 | D12 | MISO
SCK  | D52 | D13 | SCK
-----------------------------
with CD4050 adapter or 10k resistor, power supply and logical levels is 3.3V
schematic: http://nicuflorica.blogspot.ro/2014/07/afisaj-grafic-color-qvga-de-22-cu.html
*/

#include <dht.h> 
// from http://playground.arduino.cc/Main/DHTLib
dht DHT;

float t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;
float t13, t23;
int h11, h12;

void setup() {
delay(1000);

ucg.begin(UCG_FONT_MODE_TRANSPARENT);
ucg.clearScreen();
ucg.setFont(ucg_font_ncenR14r);
ucg.setColor(255, 0, 255);
ucg.setColor(1, 255, 0,0);

  ucg.setRotate90();
  ucg.setColor(255, 255, 255); // culoare alba
  ucg.drawFrame(0,0,320,240); //   
  ucg.setFont(ucg_font_courB24); // 20 pixel height
  ucg.setColor(255, 0, 0); // culoare rosie
  ucg.setPrintPos(60,30);
  ucg.print("Ministatie");
  ucg.setColor(0, 255, 0); // culoare verde
  ucg.setColor(0, 255, 0);
  ucg.setColor(0, 0, 255); // culoare albastru
  ucg.setPrintPos(17, 60);
  ucg.print("meteo cu DHT11");
//  ucg.setPrintPos(55, 90);
//  ucg.setColor(5, 255, 0); // culoare verde
//  ucg.print("si BMP180");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 0); // culoare galbena
  ucg.setPrintPos(25,120);
  ucg.print("ecran grafic 2,2'' (5,6cm)");
  ucg.setFont(ucg_font_courB24); // 20 pixel height 
  ucg.setColor(0, 255, 255); // culoare bleo
  ucg.setPrintPos(10,150);
  ucg.print("QVGA cu ILI9341");
  ucg.setColor(255, 0, 255); // culoare mov
  ucg.setPrintPos(20,180);
  ucg.print("versiune 4.5.0");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 255); // culoare alb
  ucg.setPrintPos(60,210);
  ucg.print("realizare niq_ro");

delay(5000);
ucg.clearScreen();
t13=40.0;
h12=40.0;
}

void loop() {
     
 // DHT11 part
 int chk = DHT.read11(37);
 delay(1000);
// timeout;
 int h11 = DHT.humidity; 
 if (DHT.humidity < 0) h11 = 0;

 int t12 = DHT.temperature;
int t15 = t12;
float t16 = 10*t15;
t16 = t16/10;

t16 = t12;
if (t16 != t13) 
{
temperaturi(t16, t13, 20, 0); // temperature, old temperature, x,y
termometre(t16, 20);
}

if (h11 != h12) 
{
// umiditate(h11, h12, 115, 90); // humidity, old humidity, x, y
 umiditate(h11, h12, 40, 180); // humidity, old humidity, x, y
 barca (h11, h12);
}




//}
delay (30000); 
t13=t16;
h12=h11;
} // final de program, se revine de la inceput

void temperaturi(float t3, float t4, int ics, int igrec)
{
int t5 = t3;
int t6 = t4;
ucg.setFont(ucg_font_courB24);    
if (t3*t4 < 0)
{ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
 ucg.drawHLine(ics+7, qy + igrec , 105);
}
}
int t51 = t5/10;
int t61 = t6/10;
ucg.setColor(0, 0, 0); 
if (t51 != t61)
{
for (int qy = 39 ; qy < 60; qy++) 
{
ucg.drawHLine(ics+28, qy + igrec , 21);
}
}
t5 = t3 - t51*10;
t6 = t4 - t61*10;
if (t5 != t6)
{
for (int qy = 39 ; qy < 60; qy++) 
{
ucg.drawHLine(ics+49, qy + igrec , 21);
}
} 
for (int qy = 39 ; qy < 60; qy++) 
{
 ucg.drawHLine(ics+91, qy + igrec , 21);
}
ucg.setColor(255, 0, 0);  
ucg.setPrintPos(10 + ics, 30 + igrec);
//ucg.print("t  :"); 
ucg.print("temperatura:"); 
ucg.setPrintPos(10 + ics, 60 + igrec);
if (t3 > 10.0) ucg.print("+");
else
 if (t3>0.0) ucg.print(" +");
else
 if (t3<0.0)
{
 t3=-t3;
 if (t3 > 10.0) ucg.print("-");
else
 if (t3 > 0.0) ucg.print(" -");
}  
if (t3==0.0) ucg.print("  ");
ucg.print(t3,1); 
ucg.print(" C"); 
ucg.setFont(ucg_font_fur17r); 
ucg.setPrintPos(30 + ics, 35 + igrec);
//if (igrec == 0) ucg.print("int"); 
//else ucg.print("ext"); 
ucg.setPrintPos(115 + ics, 50 + igrec);
ucg.print("o"); 

ucg.setPrintPos(75 + ics, 60 + igrec);
ucg.print(",");


}

void termometre (float t, int ics1)
{
ucg.setColor(255, 255, 255);  
ucg.drawFrame(ics1-4,10,9,200); 
ucg.drawCircle(ics1,220,10,UCG_DRAW_ALL);  
for (int a = 0; a < 10; a++)
{
ucg.drawLine(ics1-5,20+20*a,ics1-7,20+20*a);
ucg.drawLine(ics1+5,20+20*a,ics1+7,20+20*a);
}
ucg.drawLine(ics1-10,140,ics1+10,140);  
ucg.setFont(ucg_font_courB24);    
ucg.setPrintPos(13 + ics1, 149);
ucg.print("0 C"); 
ucg.setFont(ucg_font_fur17r); 
ucg.setPrintPos(37 + ics1, 135);
ucg.print("o"); 
int lin = 140 - 2*t;
ucg.setColor(0, 0, 0);  // black 
ucg.drawBox(ics1-2,21, 5, lin+5);
ucg.setColor(255, 0, 0);  
ucg.drawDisc(ics1,220,8,UCG_DRAW_ALL);  
ucg.drawBox(ics1-2,lin, 5, 210-lin);
}

void umiditate(int h3, int h4, int zet, int igrec1)
{
  ucg.setFont(ucg_font_courB24); // 20 pixel height   

// sterg semnul ??
int h51 = h3/10;
int h61 = h4/10;

ucg.setColor(0, 0, 0); 

// sterg zeci daca e cazul
if (h51 != h61)
{
//ucg.setColor(255, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
//  ucg.drawHLine(zet+28, qy + igrec1 , 21);
  ucg.drawHLine(zet+40, qy + igrec1, 42);
}
}
  int h5 = h3 - h51*10;
  int h6 = h4 - h61*10;

// sterg unitati daca e cazul
//if ((t5 != t6) || (t5-t6>0.2))
if (h5 != h6)
{
//ucg.setColor(0, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(zet+79, qy + igrec1 , 21);
}
} 

 ucg.setColor(0, 255, 255);  
 ucg.setPrintPos(zet, 30 + igrec1);
 ucg.print("umiditate:"); 


//ucg.setFont(ucg_font_fub42n); // 20 pixel height   
ucg.setPrintPos(40 + zet, 60 + igrec1);
//if (h3 > 10) ucg.print("+");
if (h3 > 10) ucg.print(" ");
else
{
//ucg.setColor(255, 255, 255); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(zet+40, qy + igrec1 , 42);
}
if (igrec1 <30) ucg.setColor(255, 255, 0);  
else ucg.setColor(0, 255, 255); 
ucg.setPrintPos(61 + zet, 60 + igrec1);
//ucg.print("+");
ucg.print(" ");
}
 ucg.print(h3); 
 ucg.print("%"); 
}


void barca (int h, int h2) // new humidity, old humidity.,
{
int xx = 280; 
int yy = 230;

//sterg barca
//ucg.setColor(100,100,100);  
ucg.setColor(0,0,0);  
ucg.drawBox(xx-25, yy-20-h2, 50, 30);


//sterg apa
//ucg.setColor(125, 125, 125);  
ucg.setColor(0, 0, 0);  
ucg.drawBox(xx-35, yy+10-h2, 70, h2-h);

//desenez apa
ucg.setColor(0, 255, 255);  
ucg.drawBox(xx-35, yy+10-h, 70, h);

//desenz barcuta;
//desenez carena
ucg.setColor(255, 255, 0);  
ucg.drawBox(xx-20, yy-h, 40, 10);
ucg.drawTriangle(xx-25, yy-h, xx-20, yy-h, xx-20, yy+10-h);
ucg.drawTriangle(xx+25, yy-h, xx+20, yy-h, xx+20, yy+10-h);
//desenez catarg
ucg.drawBox(xx-1, yy-20-h, 2, 20);
//desenez velele
ucg.setColor(0, 0, 255); // vela albastra  
ucg.drawTriangle(xx+2, yy-20-h, xx+2, yy-h, xx+20, yy-h);
ucg.setColor(255, 0, 0); // vela rosie  
ucg.drawTriangle(xx-2, yy-15-h, xx-2, yy-h, xx-20, yy-h);
}
/
   Filmuletul, care prezinta modul de afisare, se numeste ministatie meteo cu DHT11 pe ecran TFT de 2.2" cu ILI9341 pe un Arduino Due
iar altul care prezinta cele 2 versiuni, intr-o "romgleza" se numeste weather station with Arduino Due on ILI9341 2.2" TFT display
21.09.2014
   Am mai facut un film, la lumina zilei, tot in "engleza mea", numit weather station with Arduino Due on ILI9341 2.2" TFT display (2)

vineri, 1 august 2014

Afisaj grafic color QVGA de 2,2" cu integrat ILI9341 conectat la Arduino (4)

Ministatie meteo cu DHT11

   Senzorul DTH11 ofera informatii despre temperatura si umiditate, dar nu cu o prea mare precizie, totusi pentru experimente este ok (domeniu de temperatura 0..50oC cu precizie de +2oC, respectiv umiditate 20..90%RH cu o precizie de +5%RH). L-am mai prezentat la inceputurile mele cu Arduino: Ministatie meteo cu senzorul DHT11 si.. Arduino
   Exista o varianta mai buna decat DHT11, ca domeniu de masura si precizie, e vorba de DHT22: domeniu de temperatura -40..125oC cu precizie de +0,5oC, respectiv umiditate 0..100%RH cu o precizie de +2%RH.
   Revenind la partea de afisare pe ecran grafic color, am folosit montajul de la partea de termometru dublu cu senzori de temperatura DS18B20 (prezentat in articolul anterior), adaptandu-l la modul de conectare al modulului cu senzor DHT11:
   Am facut si un filmulet numit ministatie meteo cu DHT11 pe ecran TFT de 2.2" cu ILI9341:
   Sketch-ul folosit de mine este:
/*
// original sketch by niq_ro from http://nicuflorica.blogspot.com for analog clock using ucglib library
// version for 2.2" TFT with ILI9341  - 2014.07.29, Craiova - Romania
// or http://www.tehnic.go.ro
// or http://arduinotehniq.blogspot.com/

Universal uC Color Graphics Library
  https://code.google.com/p/ucglib/
  Copyright (c) 2014, olikraus@gmail.com
  All rights reserved.
*/
#include <SPI.h>
#include "Ucglib.h"
// Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 6 , /*cs=*/ 5, /*reset=*/ 4); //gordons
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 52, /*data=*/ 51, /*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); //at Mega
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 6 , /*cs=*/ 5, /*reset=*/ 4); // at Uno
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); // at Mega

/*
http://gordonsprojects.blogspot.ro/2014/04/arduino-tft-serial-spi-22-ili9341.html
Mega | Uno | TFT - ILI9341
----------------------
D22  | D4  | RESET
D24  | D5  | CS
D26  | D6  | D/C
 ?   | ?   | LED (via 220 ohms resistor at 5V)
D51  | D11 | MOSI
D50  | D12 | MISO
D52  | D13 | SCK
-----------------------------
with CD4050 adapter or 10k resistor, power supply and logical levels is 3.3V
schematic: http://nicuflorica.blogspot.ro/2014/07/afisaj-grafic-color-qvga-de-22-cu.html
*/

#include "DHT.h"
#define DHTPIN A0     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);


void subrutina(void) {
  ucg.setRotate90();
  // graphic commands to redraw the complete screen should be placed here  
  
  // pictez un chenar
  ucg.setColor(255, 255, 255); // culoare alba
  ucg.drawFrame(0,0,320,240); // 

  ucg.setFont(ucg_font_courB24); // 20 pixel height
  ucg.setColor(255, 0, 0); // culoare rosie
  ucg.setPrintPos(60,30);
  ucg.print("Ministatie");
  ucg.setColor(0, 255, 0); // culoare verde
  ucg.setColor(0, 255, 0);
  ucg.setColor(0, 0, 255); // culoare albastru
  ucg.setPrintPos(20, 60);
  ucg.print("meteo cu DHT11");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 0); // culoare galbena
  ucg.setPrintPos(25,90);
  ucg.print("ecran grafic 2,2'' (5,6cm)");
  ucg.setFont(ucg_font_courB24); // 20 pixel height 
  ucg.setColor(0, 255, 255); // culoare bleo
  ucg.setPrintPos(10,120);
  ucg.print("QVGA cu ILI9341");
  ucg.setColor(255, 0, 255); // culoare mov
  ucg.setPrintPos(40,150);
  ucg.print("versiune 3.0");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 255); // culoare alb
  ucg.setPrintPos(60,200);
  ucg.print("realizat de niq_ro");

}

// variables 
// variabile 
int t1, t2;
int t10, t20;
int t11, t21;
int t12, t22;
int t13, t23;
int h11, h12;

void setup(void) {
  dht.begin();
  //  Serial.begin(9600);      // open the serial port at 9600 bps:   
  delay(1000);
  ucg.begin(UCG_FONT_MODE_TRANSPARENT);
//ucg.begin(UCG_FONT_MODE_SOLID);
  ucg.clearScreen();


//  ucg.clearScreen(); 
  ucg.setFont(ucg_font_ncenR14r);
  ucg.setColor(255, 0, 255);
  ucg.setColor(1, 255, 0,0);
  subrutina(); // unde e mesajul de intampinare
  delay(5000);
  ucg.clearScreen();

// initial value  
t12=40.0;
t12=40.0;

  
}

void loop(void) {

  // DHT11 part
 int h11 = dht.readHumidity();
 int t11 = dht.readTemperature();

//-------------------------------------------------------

if (t11 != t12) 
{
 texte(t11, t12, 20, 0); // temperature, x, y
 termometre(t11, 20);
}

if (h11 != h12) 
{
 texte(h11, h12, 100, 90); // humidity, x, y
 sticla(h11, h12);
}




 delay (2000); 
 // store old value
t12=t11;
h12=h11;

} // final de program, se revine de la inceput



void texte(int t3, int t4, int ics, int igrec)
{
  int t5 = t3;
  int t6 = t4;
   ucg.setFont(ucg_font_courB24); // 20 pixel height   
// ucg.clearScreen(); 
if (t3*t4 < 0)
{ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(ics+7, qy + igrec , 105);
}
}

// sterg semnul ??
int t51 = t5/10;
int t61 = t6/10;

ucg.setColor(0, 0, 0); 

// sterg zeci daca e cazul
if (t51 != t61)
{
//ucg.setColor(255, 255, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(ics+28, qy + igrec , 21);
}
}
  t5 = t3 - t51*10;
  t6 = t4 - t61*10;

// sterg unitati daca e cazul
//if ((t5 != t6) || (t5-t6>0.2))
if (t5 != t6)
{
//ucg.setColor(0, 255, 255); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(ics+49, qy + igrec , 21);
}
} 

if (igrec <30) 
{
 ucg.setColor(255, 255, 0);  
 ucg.setPrintPos(10 + ics, 30 + igrec);
 ucg.print("temperatura:"); 
}
else 
{
 ucg.setColor(0, 255, 255);  
 ucg.setPrintPos(15 + ics, 30 + igrec);
 ucg.print("umiditate:"); 
}
// ucg.setPrintPos(10 + ics, 30 + igrec);
// ucg.print("temperatura:"); 

//ucg.setFont(ucg_font_fub42n); // 20 pixel height   
ucg.setPrintPos(10 + ics, 60 + igrec);
if (t3 > 10) ucg.print("+");
else 
{
//ucg.setColor(255, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(ics+10, qy + igrec , 21);
}
if (igrec <30) ucg.setColor(255, 255, 0);  
else ucg.setColor(0, 255, 255); 
ucg.setPrintPos(31 + ics, 60 + igrec);
ucg.print("+");
}
//if (t3==0.0) ucg.print("  ");

// ucg.print(t12,1); 
 ucg.print(t3,1); 
// ucg.print("23.6"); 

if (igrec <30) 
{
 ucg.print(" C"); 
 ucg.setFont(ucg_font_fur17r); // 17 pixel height
/* ucg.setPrintPos(30 + ics, 35 + igrec);
 if (igrec == 0) ucg.print("int"); 
 else ucg.print("ext"); 
*/
 ucg.setPrintPos(75 + ics, 50 + igrec);
 ucg.print("o"); 
}
else ucg.print("%"); 
}


void termometre (int t, int ics1)
{
  ucg.setColor(255, 255, 255);  
//  ucg.setColor(r2, g2, b2);  
  ucg.drawFrame(ics1-4,10,9,200); // desenez corp termometru
//  ucg.drawDisc(ics1,220,10,UCG_DRAW_ALL);  // desenez partea de jos, cu mercur
  ucg.drawCircle(ics1,220,10,UCG_DRAW_ALL);  // desenez partea de jos, cu mercur
for (int a = 0; a < 5; a++)
{
  ucg.drawLine(ics1-5,15+35*a,ics1-7,15+35*a);
  ucg.drawLine(ics1+5,15+35*a,ics1+7,15+35*a);
}
  ucg.drawLine(ics1-10,190,ics1+10,190);  // zero degree

ucg.setFont(ucg_font_courB24); // 20 pixel height   
ucg.setPrintPos(15 + ics1, 199);
ucg.print("0 C"); 

ucg.setFont(ucg_font_fur17r); // 17 pixel height
ucg.setPrintPos(39 + ics1, 185);
 ucg.print("o"); 

// temperature "lengh"
//int lin = 140 - 2*t;
int lin = 190-3.5*t;

ucg.setColor(0, 0, 0);  // black 
//ucg.drawBox(ics1-2,20, 5, 190); // erase 
ucg.drawBox(ics1-2,21, 5, lin+5);

// temperature gaphics
if (ics1 <30) ucg.setColor(255, 255, 0);  
else ucg.setColor(0, 0, 255);  

ucg.drawDisc(ics1,220,8,UCG_DRAW_ALL);  // desenez partea de jos, cu mercur

//ucg.setColor(255, 255, 0);  
// ucg.drawLine(ics1-10,lin,ics1+10,lin); // just for control 
ucg.drawBox(ics1-2,lin, 5, 210-lin);
}  

void sticla (int h, int h2)
{
  int xmax = 319;
  int ymax = 239;
  int raza = 98; 
//  h = 45; // pentru teste
  ucg.setColor(255, 255, 255);  
  ucg.drawCircle(319,239,100,UCG_DRAW_UPPER_LEFT);  // desenez arc de cerc in stanga sus

  ucg.setColor(0, 0, 255);  
  ucg.drawHLine(220, 239, 100); // desenez linia de 0% (orizontala)
  ucg.setColor(255, 0, 0);  
  ucg.drawVLine(319, 140, 100); // desenez linia de 100% (verticala)
  
  //calculez coordonate
  int xa=100*cos(2*h2*0.9*3.14/360);
  int ya=100*sin(2*h2*0.9*3.14/360);  
  int xn=100*cos(2*h*3.14*0.9/360);
  int yn=100*sin(2*h*3.14*0.9/360);  
  //sterg indicatia anterioara
  ucg.setColor(0, 0, 0);  
  ucg.drawLine(xmax-xa, ymax-ya, xmax, ymax); // 
  //desenez indicatia noua
  ucg.setColor(0, 255, 255);  
  ucg.drawLine(xmax-xn, ymax-yn, xmax, ymax); // 
   Avand in vedere ca folosesc Arduino Mega nu mai am restrictii la marimea programului, asa ca pana o sa cumpar un senzor performant DHT22, o sa sa masor temperatura cu senzorul DS18B20 si umiditatea cu DHT11.
   Schema de conectare a celor 2 senzori este combinatia schemelor anterioare:

Ministatie meteo cu DHT11 si DS18B20

   Am combinat sketch-ul anterior cu cel de la masurarea cu DS18B20 obtinand:
   Schema de conectare este o combinatie a celei anterioare si a celei de la DS18B20, iar sketch-ul folosit este:
/*
original sketch by niq_ro from http://nicuflorica.blogspot.com using ucglib library
version for 2.2" TFT with ILI9341  - 2014.07.29, Craiova - Romania
use Universal uC Color Graphics Library from https://code.google.com/p/ucglib/
*/
#include <SPI.h>
#include "Ucglib.h"
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 6 , /*cs=*/ 5, /*reset=*/ 4); // at Uno
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); // at Mega
/*
Mega | Uno | TFT - ILI9341
----------------------
D22  | D4  | RESET
D24  | D5  | CS
D26  | D6  | D/C
 ?   | ?   | LED (via 220 ohms resistor at 5V)
D51  | D11 | MOSI
D50  | D12 | MISO
D52  | D13 | SCK
-----------------------------
with CD4050 adapter or 10k resistor, power supply and logical levels is 3.3V
schematic: http://nicuflorica.blogspot.ro/2014/07/afisaj-grafic-color-qvga-de-22-cu.html
*/

#include <OneWire.h>
OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)  
int ics =0; //count number of sensor

#include "DHT.h"
#define DHTPIN A0     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);

float t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;
float t13, t23;
int h11, h12;

void setup(void) {
delay(1000);
dht.begin();
ucg.begin(UCG_FONT_MODE_TRANSPARENT);
ucg.clearScreen();
ucg.setFont(ucg_font_ncenR14r);
ucg.setColor(255, 0, 255);
ucg.setColor(1, 255, 0,0);

  ucg.setRotate90();
  ucg.setColor(255, 255, 255); // culoare alba
  ucg.drawFrame(0,0,320,240); //   
  ucg.setFont(ucg_font_courB24); // 20 pixel height
  ucg.setColor(255, 0, 0); // culoare rosie
  ucg.setPrintPos(60,30);
  ucg.print("Ministatie");
  ucg.setColor(0, 255, 0); // culoare verde
  ucg.setColor(0, 255, 0);
  ucg.setColor(0, 0, 255); // culoare albastru
  ucg.setPrintPos(20, 60);
  ucg.print("meteo cu DHT11");
  ucg.setPrintPos(60, 90);
  ucg.setColor(0, 255, 0); // culoare verde
  ucg.print("si DS18B20");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 0); // culoare galbena
  ucg.setPrintPos(25,120);
  ucg.print("ecran grafic 2,2'' (5,6cm)");
  ucg.setFont(ucg_font_courB24); // 20 pixel height 
  ucg.setColor(0, 255, 255); // culoare bleo
  ucg.setPrintPos(10,150);
  ucg.print("QVGA cu ILI9341");
  ucg.setColor(255, 0, 255); // culoare mov
  ucg.setPrintPos(40,180);
  ucg.print("versiune 4.0");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 255); // culoare alb
  ucg.setPrintPos(60,210);
  ucg.print("realizat de niq_ro");

delay(5000);
ucg.clearScreen();
t13=40.0;
h12=40.0;
}

void loop(void) {
 // DHT11 part
 int h11 = dht.readHumidity();
  
 //DS18B20 part 
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius;
if ( !ds.search(addr)) {
    ds.reset_search();
    ics=0;
    return;
  }
ics++; 

ds.reset();
ds.select(addr);
ds.write(0x44, 1);        // start conversion, with parasite power on at the end
delay(1000);     // maybe 750ms is enough, maybe not
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
  data[i] = ds.read();
  }
  // Convert the data to actual temperature
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
t12 = (float)raw / 16.0;

int t15 = t12;
float t16 = 10*t15;
t16 = t16/10;

t16 = t12;
if (t16 != t13) 
{
temperaturi(t16, t13, 20, 0); 
termometre(t16, 20);
}

if (h11 != h12) 
{
 umiditate(h11, h12, 115, 90); // humidity, x, y
 sticla(h11, h12);
}

//}
delay (2000); 
t13=t16;
h12=h11;
} // final de program, se revine de la inceput

void temperaturi(float t3, float t4, int ics, int igrec)
{
int t5 = t3;
int t6 = t4;
ucg.setFont(ucg_font_courB24);    
if (t3*t4 < 0)
{ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
 ucg.drawHLine(ics+7, qy + igrec , 105);
}
}
int t51 = t5/10;
int t61 = t6/10;
ucg.setColor(0, 0, 0); 
if (t51 != t61)
{
for (int qy = 39 ; qy < 60; qy++) 
{
ucg.drawHLine(ics+28, qy + igrec , 21);
}
}
t5 = t3 - t51*10;
t6 = t4 - t61*10;
if (t5 != t6)
{
for (int qy = 39 ; qy < 60; qy++) 
{
ucg.drawHLine(ics+49, qy + igrec , 21);
}
} 
for (int qy = 39 ; qy < 60; qy++) 
{
 ucg.drawHLine(ics+91, qy + igrec , 21);
}
if (igrec <30) ucg.setColor(255, 0, 0);  
else ucg.setColor(0, 0, 255);  
ucg.setPrintPos(10 + ics, 30 + igrec);
//ucg.print("t  :"); 
ucg.print("temperatura:"); 
ucg.setPrintPos(10 + ics, 60 + igrec);
if (t3 > 10.0) ucg.print("+");
else
 if (t3>0.0) ucg.print(" +");
else
 if (t3<0.0)
{
 t3=-t3;
 if (t3 > 10.0) ucg.print("-");
else
 if (t3 > 0.0) ucg.print(" -");
}  
if (t3==0.0) ucg.print("  ");
ucg.print(t3,1); 
ucg.print(" C"); 
ucg.setFont(ucg_font_fur17r); 
ucg.setPrintPos(30 + ics, 35 + igrec);
//if (igrec == 0) ucg.print("int"); 
//else ucg.print("ext"); 
ucg.setPrintPos(115 + ics, 50 + igrec);
ucg.print("o"); 
}

void termometre (float t, int ics1)
{
ucg.setColor(255, 255, 255);  
ucg.drawFrame(ics1-4,10,9,200); 
ucg.drawCircle(ics1,220,10,UCG_DRAW_ALL);  
for (int a = 0; a < 10; a++)
{
ucg.drawLine(ics1-5,20+20*a,ics1-7,20+20*a);
ucg.drawLine(ics1+5,20+20*a,ics1+7,20+20*a);
}
ucg.drawLine(ics1-10,140,ics1+10,140);  
ucg.setFont(ucg_font_courB24);    
ucg.setPrintPos(13 + ics1, 149);
ucg.print("0 C"); 
ucg.setFont(ucg_font_fur17r); 
ucg.setPrintPos(37 + ics1, 135);
ucg.print("o"); 
int lin = 140 - 2*t;
ucg.setColor(0, 0, 0);  // black 
ucg.drawBox(ics1-2,21, 5, lin+5);
if (ics1 <30) ucg.setColor(255, 0, 0);  
else ucg.setColor(0, 0, 255);  
ucg.drawDisc(ics1,220,8,UCG_DRAW_ALL);  
ucg.drawBox(ics1-2,lin, 5, 210-lin);
}

void umiditate(int h3, int h4, int zet, int igrec1)
{
  ucg.setFont(ucg_font_courB24); // 20 pixel height   

// sterg semnul ??
int h51 = h3/10;
int h61 = h4/10;

ucg.setColor(0, 0, 0); 

// sterg zeci daca e cazul
if (h51 != h61)
{
//ucg.setColor(255, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
//  ucg.drawHLine(zet+28, qy + igrec1 , 21);
  ucg.drawHLine(zet+10, qy + igrec1, 42);
}
}
  int h5 = h3 - h51*10;
  int h6 = h4 - h61*10;

// sterg unitati daca e cazul
//if ((t5 != t6) || (t5-t6>0.2))
if (h5 != h6)
{
//ucg.setColor(0, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(zet+49, qy + igrec1 , 21);
}
} 

 ucg.setColor(0, 255, 255);  
 ucg.setPrintPos(zet, 30 + igrec1);
 ucg.print("umiditate:"); 


//ucg.setFont(ucg_font_fub42n); // 20 pixel height   
ucg.setPrintPos(10 + zet, 60 + igrec1);
if (h3 > 10) ucg.print("+");
else
{
//ucg.setColor(255, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(zet+10, qy + igrec1 , 42);
}
if (igrec1 <30) ucg.setColor(255, 255, 0);  
else ucg.setColor(0, 255, 255); 
ucg.setPrintPos(31 + zet, 60 + igrec1);
ucg.print("+");
}
 ucg.print(h3); 
 ucg.print("%"); 
}

void sticla (int h, int h2)
{
  int xmax = 319;
  int ymax = 239;
  int raza = 98; 
//  h = 45; // pentru teste
  ucg.setColor(255, 255, 255);  
  ucg.drawCircle(319,239,100,UCG_DRAW_UPPER_LEFT);  // desenez arc de cerc in stanga sus

  ucg.setColor(0, 0, 255);  
  ucg.drawHLine(220, 239, 100); // desenez linia de 0% (orizontala)
  ucg.setColor(255, 0, 0);  
  ucg.drawVLine(319, 140, 100); // desenez linia de 100% (verticala)
  
  //calculez coordonate
  int xa=100*cos(2*h2*0.9*3.14/360);
  int ya=100*sin(2*h2*0.9*3.14/360);  
  int xn=100*cos(2*h*3.14*0.9/360);
  int yn=100*sin(2*h*3.14*0.9/360);  
  //sterg indicatia anterioara
  ucg.setColor(0, 0, 0);  
  ucg.drawLine(xmax-xa, ymax-ya, xmax, ymax); // 
  //desenez indicatia noua
  ucg.setColor(0, 255, 255);  
  ucg.drawLine(xmax-xn, ymax-yn, xmax, ymax); // 
}  
   Ulterior am modificat sketch-ul inlocuind indicatorul acele pe sfert de cerc cu o "baterie":
iar filmul care prezinta modul de afisare si anumite cazuri se numeste ministatie meteo cu DHT11 si DS18B20 pe ecran TFT de 2.2" cu ILI9341 (2)
5.8.2014
   Am scos semnul "+" de la umiditate si am schimbat "bateria" cu o barcuta cu vele, care pluteste ce o apa, a carei nivel este proportional cu umiditatea...
dupa cum se vede si in filmuletul ministatie meteo cu DHT11 si DS18B20 pe ecran TFT de 2.2" cu ILI9341 (3)
   Sketch-ul folosit la versiunea 4.1.2 este:
/*
original sketch by niq_ro from http://nicuflorica.blogspot.com using ucglib library
version for 2.2" TFT with ILI9341  - 2014.07.29, Craiova - Romania
use Universal uC Color Graphics Library from https://code.google.com/p/ucglib/
*/
#include <SPI.h>
#include "Ucglib.h"
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 6 , /*cs=*/ 5, /*reset=*/ 4); // at Uno
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 26 , /*cs=*/ 24, /*reset=*/ 22); // at Mega
/*
Mega | Uno | TFT - ILI9341
----------------------
D22  | D4  | RESET
D24  | D5  | CS
D26  | D6  | D/C
 ?   | ?   | LED (via 220 ohms resistor at 5V)
D51  | D11 | MOSI
D50  | D12 | MISO
D52  | D13 | SCK
-----------------------------
with CD4050 adapter or 10k resistor, power supply and logical levels is 3.3V
schematic: http://nicuflorica.blogspot.ro/2014/07/afisaj-grafic-color-qvga-de-22-cu.html
*/

#include <OneWire.h>
OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)  
int ics =0; //count number of sensor

#include "DHT.h"
#define DHTPIN A0     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);

float t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;
float t13, t23;
int h11, h12;

void setup(void) {
delay(1000);
dht.begin();
ucg.begin(UCG_FONT_MODE_TRANSPARENT);
ucg.clearScreen();
ucg.setFont(ucg_font_ncenR14r);
ucg.setColor(255, 0, 255);
ucg.setColor(1, 255, 0,0);

  ucg.setRotate90();
  ucg.setColor(255, 255, 255); // culoare alba
  ucg.drawFrame(0,0,320,240); //   
  ucg.setFont(ucg_font_courB24); // 20 pixel height
  ucg.setColor(255, 0, 0); // culoare rosie
  ucg.setPrintPos(60,30);
  ucg.print("Ministatie");
  ucg.setColor(0, 255, 0); // culoare verde
  ucg.setColor(0, 255, 0);
  ucg.setColor(0, 0, 255); // culoare albastru
  ucg.setPrintPos(20, 60);
  ucg.print("meteo cu DHT11");
  ucg.setPrintPos(60, 90);
  ucg.setColor(0, 255, 0); // culoare verde
  ucg.print("si DS18B20");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 0); // culoare galbena
  ucg.setPrintPos(25,120);
  ucg.print("ecran grafic 2,2'' (5,6cm)");
  ucg.setFont(ucg_font_courB24); // 20 pixel height 
  ucg.setColor(0, 255, 255); // culoare bleo
  ucg.setPrintPos(10,150);
  ucg.print("QVGA cu ILI9341");
  ucg.setColor(255, 0, 255); // culoare mov
  ucg.setPrintPos(20,180);
  ucg.print("versiune 4.1.2");
  ucg.setFont(ucg_font_fur17r); // 17 pixel height
  ucg.setColor(255, 255, 255); // culoare alb
  ucg.setPrintPos(60,210);
  ucg.print("realizat de niq_ro");

delay(5000);
ucg.clearScreen();
t13=40.0;
h12=40.0;
}

void loop(void) {
 // DHT11 part
 int h11 = dht.readHumidity();
  
 //DS18B20 part 
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius;
if ( !ds.search(addr)) {
    ds.reset_search();
    ics=0;
    return;
  }
ics++; 

ds.reset();
ds.select(addr);
ds.write(0x44, 1);        // start conversion, with parasite power on at the end
delay(1000);     // maybe 750ms is enough, maybe not
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
  data[i] = ds.read();
  }
  // Convert the data to actual temperature
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
t12 = (float)raw / 16.0;

int t15 = t12;
float t16 = 10*t15;
t16 = t16/10;

t16 = t12;
if (t16 != t13) 
{
temperaturi(t16, t13, 20, 0); // temperature, old temperature, x,y
termometre(t16, 20);
}

if (h11 != h12) 
{
 umiditate(h11, h12, 115, 90); // humidity, old humidity x, y
 barca (h11, h12);
}

//}
delay (2000); 
t13=t16;
h12=h11;
} // final de program, se revine de la inceput

void temperaturi(float t3, float t4, int ics, int igrec)
{
int t5 = t3;
int t6 = t4;
ucg.setFont(ucg_font_courB24);    
if (t3*t4 < 0)
{ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
 ucg.drawHLine(ics+7, qy + igrec , 105);
}
}
int t51 = t5/10;
int t61 = t6/10;
ucg.setColor(0, 0, 0); 
if (t51 != t61)
{
for (int qy = 39 ; qy < 60; qy++) 
{
ucg.drawHLine(ics+28, qy + igrec , 21);
}
}
t5 = t3 - t51*10;
t6 = t4 - t61*10;
if (t5 != t6)
{
for (int qy = 39 ; qy < 60; qy++) 
{
ucg.drawHLine(ics+49, qy + igrec , 21);
}
} 
for (int qy = 39 ; qy < 60; qy++) 
{
 ucg.drawHLine(ics+91, qy + igrec , 21);
}
if (igrec <30) ucg.setColor(255, 255, 0);  
else ucg.setColor(0, 0, 255);  
ucg.setPrintPos(10 + ics, 30 + igrec);
//ucg.print("t  :"); 
ucg.print("temperatura:"); 
ucg.setPrintPos(10 + ics, 60 + igrec);
if (t3 > 10.0) ucg.print("+");
else
 if (t3>0.0) ucg.print(" +");
else
 if (t3<0.0)
{
 t3=-t3;
 if (t3 > 10.0) ucg.print("-");
else
 if (t3 > 0.0) ucg.print(" -");
}  
if (t3==0.0) ucg.print("  ");
ucg.print(t3,1); 
ucg.print(" C"); 
ucg.setFont(ucg_font_fur17r); 
ucg.setPrintPos(30 + ics, 35 + igrec);
//if (igrec == 0) ucg.print("int"); 
//else ucg.print("ext"); 
ucg.setPrintPos(115 + ics, 50 + igrec);
ucg.print("o"); 

ucg.setPrintPos(75 + ics, 60 + igrec);
ucg.print(",");


}

void termometre (float t, int ics1)
{
ucg.setColor(255, 255, 255);  
ucg.drawFrame(ics1-4,10,9,200); 
ucg.drawCircle(ics1,220,10,UCG_DRAW_ALL);  
for (int a = 0; a < 10; a++)
{
ucg.drawLine(ics1-5,20+20*a,ics1-7,20+20*a);
ucg.drawLine(ics1+5,20+20*a,ics1+7,20+20*a);
}
ucg.drawLine(ics1-10,140,ics1+10,140);  
ucg.setFont(ucg_font_courB24);    
ucg.setPrintPos(13 + ics1, 149);
ucg.print("0 C"); 
ucg.setFont(ucg_font_fur17r); 
ucg.setPrintPos(37 + ics1, 135);
ucg.print("o"); 
int lin = 140 - 2*t;
ucg.setColor(0, 0, 0);  // black 
ucg.drawBox(ics1-2,21, 5, lin+5);
if (ics1 <30) ucg.setColor(255, 0, 0);  
else ucg.setColor(0, 0, 255);  
ucg.drawDisc(ics1,220,8,UCG_DRAW_ALL);  
ucg.drawBox(ics1-2,lin, 5, 210-lin);
}

void umiditate(int h3, int h4, int zet, int igrec1)
{
  ucg.setFont(ucg_font_courB24); // 20 pixel height   

// sterg semnul ??
int h51 = h3/10;
int h61 = h4/10;

ucg.setColor(0, 0, 0); 

// sterg zeci daca e cazul
if (h51 != h61)
{
//ucg.setColor(255, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
//  ucg.drawHLine(zet+28, qy + igrec1 , 21);
  ucg.drawHLine(zet+40, qy + igrec1, 42);
}
}
  int h5 = h3 - h51*10;
  int h6 = h4 - h61*10;

// sterg unitati daca e cazul
//if ((t5 != t6) || (t5-t6>0.2))
if (h5 != h6)
{
//ucg.setColor(0, 255, 0); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(zet+79, qy + igrec1 , 21);
}
} 

 ucg.setColor(0, 255, 255);  
 ucg.setPrintPos(zet, 30 + igrec1);
 ucg.print("umiditate:"); 


//ucg.setFont(ucg_font_fub42n); // 20 pixel height   
ucg.setPrintPos(40 + zet, 60 + igrec1);
//if (h3 > 10) ucg.print("+");
if (h3 > 10) ucg.print(" ");
else
{
//ucg.setColor(255, 255, 255); 
ucg.setColor(0, 0, 0); 
for (int qy = 39 ; qy < 60; qy++) 
{
  ucg.drawHLine(zet+40, qy + igrec1 , 42);
}
if (igrec1 <30) ucg.setColor(255, 255, 0);  
else ucg.setColor(0, 255, 255); 
ucg.setPrintPos(61 + zet, 60 + igrec1);
//ucg.print("+");
ucg.print(" ");
}
 ucg.print(h3); 
 ucg.print("%"); 
}


void barca (int h, int h2) // new humidity, old humidity.,
{
 
int xx = 280; 
int yy = 230;
//sterg barca
//ucg.setColor(100,100,100);  
ucg.setColor(0,0,0);  
ucg.drawBox(xx-25, yy-20-h2, 50, 30);


//sterg apa
//ucg.setColor(125, 125, 125);  
ucg.setColor(0, 0, 0);  
ucg.drawBox(xx-35, yy+10-h2, 70, h2-h);

//desenez apa
ucg.setColor(0, 255, 255);  
ucg.drawBox(xx-35, yy+10-h, 70, h);

//desenz barcuta;
//desenez carena
ucg.setColor(255, 255, 0);  
ucg.drawBox(xx-20, yy-h, 40, 10);
ucg.drawTriangle(xx-25, yy-h, xx-20, yy-h, xx-20, yy+10-h);
ucg.drawTriangle(xx+25, yy-h, xx+20, yy-h, xx+20, yy+10-h);
//desenez catarg
ucg.drawBox(xx-1, yy-20-h, 2, 20);
//desenez velele
ucg.setColor(0, 0, 255); // vela albastra  
ucg.drawTriangle(xx+2, yy-20-h, xx+2, yy-h, xx+20, yy-h);
ucg.setColor(255, 0, 0); // vela rosie  
ucg.drawTriangle(xx-2, yy-15-h, xx-2, yy-h, xx-20, yy-h);
}


6.8.2014
   Am facut un alt filmulet, cu lumina ambianta mai multa, pentru a se mai defocaliza camera, numit ministatie meteo cu DHT11 si DS18B20 pe ecran TFT de 2.2" cu ILI9341 (4)