Totalul afișărilor de pagină

test imagine

luni, 14 octombrie 2013

Termometru dublu cu LM335Z si un afisaj LCD cu 16 coloane si 2 randuri

   Fata de articolele precedente cand am folosit trasmiterea prin unde radio a valorilor citite de 2 senzori LM335 (vezi articolul Senzorul de temperatura LM335) si afisarea pe un afisaj LCD cu 16 coloane si 2 randuri conectat la un alt Arduino, acum o sa simplific problema, in sensul ca voi conecta senzorii direct la o placa Arduino, care va afisa valorile pe ecranul LCD1602.
   Schema de conectare a senzorilor si a afisajului este:
   Am facut niste teste, inclusiv un simbol grafic de casa:
si chiar o casa cu un cos de fum:
 
dupa cum se vede in filmuletul numit home vs outside temperature with LM335 and Arduino
   Prima varianta de sketch, in care am folosit si crearea unui simbol (de fapt 2 pentru casuta), dupa cum este prezentat la http://arduino.cc/en/Reference/LiquidCrystalCreateChar:

/*
original sketch by niq_ro (Nicu FLORICA) from http://nicuflorica.blogspot.com
version 1.1
program original scris de mine (niq_ro) versiounea 1.1
..............................................................*/

#include <LiquidCrystal.h>
// folosesc libraria pentru afisaje LCD simple
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// indic modul de legare, vezi mai jos:
/*                                    -------------------
                                      |  LCD  | Arduino |
                                      -------------------
 LCD RS pin to digital pin 7          |  RS   |   D7    |
 LCD Enable pin to digital pin 6      |  E    |   D6    |
 LCD D4 pin to digital pin 5          |  D4   |   D5    |
 LCD D5 pin to digital pin 4          |  D5   |   D4    |
 LCD D6 pin to digital pin 3          |  D6   |   D3    |
 LCD D7 pin to digital pin 2          |  D7   |   D2    |
 LCD R/W pin to ground                |  R/W  |   GND   |
                                      -------------------
*/
// http://arduino.cc/en/Reference/LiquidCrystalCreateChar
byte smiley[8] = {
  B00000,
  B10001,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
};

byte home12[8] = {
  B00001,
  B00110,
  B11000,
  B00111,
  B00100,
  B00100,
  B00111,
};

byte home22[8] = {
  B10000,
  B01100,
  B00011,
  B11100,
  B00100,
  B00100,
  B11100,
};



// variables 
// variabile 
int t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;

int temperaturePin1 = A0; // output from first LM335 is put at analog input no.0
int temperaturePin2 = A1; // output from second LM335 is put at analog input no.1
// cei 2 senzori de temperaturia LM335 sunt legati la pinii A0 si A1

// other  
int led = 13; //pin for LED


void setup() {
  lcd.createChar(0, smiley);
  lcd.createChar(1, home12);
  lcd.createChar(2, home22);
  lcd.begin(16, 2); // set up the LCD's number of columns and rows: 
 

pinMode(led, OUTPUT); 
 lcd.clear(); // clear the screen
 lcd.setCursor(0, 0); // put cursor at colon 2 and row 0 = left/up
 lcd.print("dual thermometer"); // print a text
 lcd.setCursor(0, 1); // put cursor at colon 0 and row 0 = left/down
 lcd.print("1.1 by niq_ro "); // print a text
 lcd.write(byte(0));
 delay (2000);
 lcd.clear(); // clear the screen
 

} // END void setup
  
void loop(){

  digitalWrite(led, HIGH);  

  // Read and store Sensor Data
t11=0;
t21=0;
//lcd.clear(); // clear the screen

for (int x=1; x <= 5; x++)
  {
// calculate the value  
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
 t10 = 100.0*(5.0*t1/1023-2.980)+25.0;
 t11 = t10 + t11;

t2 = analogRead(temperaturePin2); // read value from temperature from second sensor (LM335);
 t20 = 100.0*(5.0*t2/1023-2.980)+25.0;
 t21 = t20 + t21;

delay (500);
  }   

t12 = t11/5.0 -2.0 ; // average and corrected temperature  
t22 = t21/5.0 -1.0; // average and corrected temperature  

/*
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
t2 = analogRead(temperaturePin2); // read value from temperature from first sensor (LM335);
t10 = (100.0*(5.0*t1/1023.0-2.980)+25.0)-1.0; // 
t20 = (100.0*(5.0*t2/1023.0-2.980)+25.0);
*/
lcd.setCursor(14, 0);
lcd.write(byte(1));
lcd.write(byte(2));

    lcd.setCursor(3, 0);
    lcd.print("t1="); 
    if (t12<10) lcd.print(" "); 
    if (t12>0.0) lcd.print("+"); 
    lcd.print(t12,1);
    lcd.write(0b11011111);
    lcd.print("C");
    lcd.setCursor(3, 1);
    lcd.print("t2="); 
    if (t22<10) lcd.print(" "); 
    if (t22>0.0) lcd.print("+"); 
    lcd.print(t22,1);
    lcd.write(0b11011111);
    lcd.print("C");
    
digitalWrite(led, LOW); 
delay(1000);
}
   Pentru a crea casuta, mi-am desenat casuta:
si, dupa cum am scris si inainte, m-am folosit de un exemplu de la Arduino de pe site:
// http://arduino.cc/en/Reference/LiquidCrystalCreateChar
#include 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte smiley[8] = {
  B00000,
  B10001,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
};

void setup() {
  lcd.createChar(0, smiley);
  lcd.begin(16, 2);  
  lcd.write(byte(0));
}

void loop() {}
   La mine partea de definitie este:
// partea din stanga
byte home12[8] = {
  B00001,
  B00110,
  B11000,
  B00111,
  B00100,
  B00100,
  B00111,
};
// partea din dreapta
byte home22[8] = {
  B10000,
  B01100,
  B00011,
  B11100,
  B00100,
  B00100,
  B11100,
};
respectiv in partea de setari:
void setup() {
  lcd.createChar(1, home12);
  lcd.createChar(2, home22);

  Ulterior, am modificat "casa" si am schimbat modul de afisare:
- casuta cu animatie, din 2 caractere:
- casuta cu animatie, din 3 caractere:
 - simbolul de grad, mai rotiunjit decat cel original:

Sketch-ul devine:
/*
original sketch by niq_ro (Nicu FLORICA) from http://nicuflorica.blogspot.com
version 1.4
program original scris de mine (niq_ro) versiounea 1.4
..............................................................*/

#include <LiquidCrystal.h>
// folosesc libraria pentru afisaje LCD simple
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// indic modul de legare, vezi mai jos:
/*                                    -------------------
                                      |  LCD  | Arduino |
                                      -------------------
 LCD RS pin to digital pin 7          |  RS   |   D7    |
 LCD Enable pin to digital pin 6      |  E    |   D6    |
 LCD D4 pin to digital pin 5          |  D4   |   D5    |
 LCD D5 pin to digital pin 4          |  D5   |   D4    |
 LCD D6 pin to digital pin 3          |  D6   |   D3    |
 LCD D7 pin to digital pin 2          |  D7   |   D2    |
 LCD R/W pin to ground                |  R/W  |   GND   |
                                      -------------------
*/
// http://arduino.cc/en/Reference/LiquidCrystalCreateChar

byte home13[8] = {
  B00011,
  B00100,
  B01000,
  B11111,
  B01000,
  B01000,
  B01111,
};

byte home23[8] = {
  B00000,
  B10110,
  B01110,
  B11111,
  B00100,
  B00100,
  B11100,
};

byte home33[8] = {
  B00011,
  B10110,
  B01110,
  B11111,
  B00100,
  B00100,
  B11100,
};

byte home03[8] = {
  B11111,
  B00000,
  B00000,
  B11111,
  B00000,
  B00000,
  B11111,
};

byte grad[8] = {
  B00100,
  B01010,
  B00100,
  B00000,
  B00000,
  B00000,
  B00000,
};


// variables 
// variabile 
int t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;

int temperaturePin1 = A0; // output from first LM335 is put at analog input no.0
int temperaturePin2 = A1; // output from second LM335 is put at analog input no.1
// cei 2 senzori de temperaturia LM335 sunt legati la pinii A0 si A1

// other  
int led = 13; //pin for LED

void setup() {
  lcd.createChar(0, grad);
  lcd.createChar(1, home13);
  lcd.createChar(2, home23);
  lcd.createChar(3, home33);
  lcd.createChar(4, home03);
   
  lcd.begin(16, 2); // set up the LCD's number of columns and rows: 
 

pinMode(led, OUTPUT); 
 lcd.clear(); // clear the screen
 lcd.setCursor(0, 0); // put cursor at colon 2 and row 0 = left/up
 lcd.print("dual thermometer"); // print a text
 lcd.setCursor(1, 1); // put cursor at colon 0 and row 0 = left/down
 lcd.print("1.4 by niq_ro"); // print a text
 delay (2000);
 lcd.clear(); // clear the screen
 

} // END void setup
  
void loop(){

  digitalWrite(led, HIGH);  

  // Read and store Sensor Data
t11=0;
t21=0;
//lcd.clear(); // clear the screen

for (int x=1; x <= 5; x++)
  {
// calculate the value  
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
 t10 = 100.0*(5.0*t1/1023-2.980)+25.0;
 t11 = t10 + t11;

t2 = analogRead(temperaturePin2); // read value from temperature from second sensor (LM335);
 t20 = 100.0*(5.0*t2/1023-2.980)+25.0;
 t21 = t20 + t21;

delay (500);
  }   

t12 = t11/5.0 -2.0 ; // average and corrected temperature  
t22 = t21/5.0 -1.0; // average and corrected temperature  

/*
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
t2 = analogRead(temperaturePin2); // read value from temperature from first sensor (LM335);
t10 = (100.0*(5.0*t1/1023.0-2.980)+25.0)-1.0;
t20 = (100.0*(5.0*t2/1023.0-2.980)+25.0);
*/

    lcd.setCursor(2, 0);
    lcd.write(byte(1));
    lcd.write(byte(4));
    lcd.write(byte(3));
    lcd.print(":");
  //  lcd.print("t1="); 
    if (t12<10) lcd.print(" "); 
    if (t12>0.0) lcd.print("+"); 
    lcd.print(t12,1);
  //  lcd.write(0b11011111);
  lcd.write(byte(0));
    lcd.print("C");
  
  
    lcd.setCursor(2, 1);
    lcd.print("ext:");
  //  lcd.print("t2="); 
    if (t22<10) lcd.print(" "); 
    if (t22>0.0) lcd.print("+"); 
    lcd.print(t22,1);
   // lcd.write(0b11011111);
   lcd.write(byte(0));
    lcd.print("C");
    
digitalWrite(led, LOW); 
delay(500);
lcd.setCursor(4, 0);
lcd.write(byte(2));
}
   Am facut un filmulet, numit home vs outside temperature with LM335 and Arduino (II):
15.10.2013
   M-am gandit sa fac un simbol pentru exterior si am facut un copac din 2 bucati (5 coloane si 8 randuri, anterior faceam cu 7 randuri), apoi am micsorat casuta ca parea hala...
   Dupa ce am (re)vazut articolul LM335 + Arduino temperature sensor de la Legwinskij's Gadgets am refacut si eu simbolul de la grad:
   Ultima varianta este prezentata in filmuletul home vs outside temperature with LM335 and Arduino (III):

Niciun comentariu:

Trimiteți un comentariu