Να ρωτήσω και γω κάτι για arduino?
Πρόσφατα τον έπιασα στα χέρια μου και πήρα και την nokia 3310 LCD Shield από nuelectronics.com καθώς και τα αισθητήρια θερμοκρασίας.
http://www.nuelectronics.com/estore/...products_id=12
http://www.nuelectronics.com/estore/...products_id=28
Θέλω πέρα από το serial monitor να μπορώ να εμφανίσω τις τιμές και στην οθόνη LCD, αλλά επειδή είναι σε byte values (2 digits), δεν μπορώ...
Ξέρω μόνο να τυπώνω string...
Κάποιος να μου πει τι κώδικα να χρησιμοποιήσω για να το κάνω...Χρησιμοποιώ την "nokia_3310_lcd.h" library.
[bold]Ή απλώς πως να μετατρέψω τo byte σε sting![/bold] Διότι string μπορώ να εμφανίσω στην οθόνη...
Ο κώδικας τρέχει κανονικά και το παρακάτω σημείο είναι αυτό που θέλω να εμφανίσω και στην οθόνη πέρα από τον serial monitor, στο οποίο οι τιμές εμφανίζονται κανονικά.
"Current humdity = 57.0% temperature = 29.0C"
-----------
Serial.print("Current humdity = ");
Serial.print(dht11_dat[0], DEC);
Serial.print(".");
Serial.print(dht11_dat[1], DEC);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(dht11_dat[2], DEC);
Serial.print(".");
Serial.print(dht11_dat[3], DEC);
Serial.println("C ");
---------------------------
Και ολόκληρος ο κώδικας:
-----------
#include "nokia_3310_lcd.h"
char numStr[8];
#define DHT11_PIN 0 // ADC0
Nokia_3310_lcd lcd=Nokia_3310_lcd();
byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++){
while(!(PINC & _BV(DHT11_PIN))); // wait for 50us
delayMicroseconds(30);
if(PINC & _BV(DHT11_PIN))
result |=(1<<(7-i));
while((PINC & _BV(DHT11_PIN))); // wait '1' finish
}
return result;
}
void setup()
{
lcd.LCD_3310_init();
lcd.LCD_3310_clear();
lcd.LCD_3310_write_string( 0, 1, "Nokia 3310 LCD", MENU_NORMAL);
lcd.LCD_3310_write_string( 0, 3, "NaThAN", MENU_NORMAL);
lcd.LCD_3310_write_string( 13, 4, "Electronics!", MENU_NORMAL);
delay(1000);
lcd.LCD_3310_clear();
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
Serial.begin(19200);
Serial.println("Ready");
}
void loop()
{
byte dht11_dat[5];
byte dht11_in;
byte i;
// start condition
// 1. pull-down i/o pin from 18ms
PORTC &= ~_BV(DHT11_PIN);
delay(18);
PORTC |= _BV(DHT11_PIN);
delayMicroseconds(40);
DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds(40);
dht11_in = PINC & _BV(DHT11_PIN);
if(dht11_in){
Serial.println("dht11 start condition 1 not met");
return;
}
delayMicroseconds(80);
dht11_in = PINC & _BV(DHT11_PIN);
if(!dht11_in){
Serial.println("dht11 start condition 2 not met");
return;
}
delayMicroseconds(80);
// now ready for data reception
for (i=0; i<5; i++)
dht11_dat[i] = read_dht11_dat();
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
// check check_sum
if(dht11_dat[4]!= dht11_check_sum)
{
Serial.println("DHT11 checksum error");
}
char n=i;
Serial.print("Current humdity = ");
Serial.print(dht11_dat[0], DEC);
Serial.print(".");
Serial.print(dht11_dat[1], DEC);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(dht11_dat[2], DEC);
Serial.print(".");
Serial.print(dht11_dat[3], DEC);
Serial.println("C ");
lcd.LCD_3310_write_string( 0, 0, "Humidity Sensor...", MENU_NORMAL);
lcd.LCD_3310_write_string( 0, 3, "temp = ", MENU_NORMAL);
lcd.LCD_3310_write_byte( dht11_dat[2],DEC); //Here is the problem....
// How can i make the byte array printed on the lcd screen?? PLEASE HELP!!!!
delay(2000);
}
-------------------------------
Please κάποιος να με βοηθήσει... Οποιοσδήποτε που έχει περάσει τιμές από αισθητήρια σε οθόνη πρέπει να έχει αντιμετωπίσει το ίδιο πρόβλημα...
