Go Down

Topic: printing a double variable (Read 44541 times) previous topic - next topic

mikalhart

It's worth mentioning that native float/double printing is planned for the forthcoming release of the Arduino software (0013).  So don't invest too much effort on getting it to work just yet. :)

Mikal

nathanas

I have written the code below...I'm working on a project for my university.
Please use an one wire sensor and the lcd shield to see what is wrong.....
I have to make a project for a project for my university and i have to finish it until Monday!!
Please help me get pass this problem...I am trying to find out wqhats happening for 5 days with no luck...
All i can tell is that the byte array cannot be displaied on the screen.Maybe because it contains 2 digits....
please help..
the code is pasted below!


Code: [Select]

#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");
}

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);


//********THE PROBLEM IS BELOW!!!!
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);
}




// Format a number to 2 decimal places
void formatNum( int num ) {
// First part before decimalpoint
itoa( num / 100, numStr, 10 );
int pos = strlen( numStr );
numStr[pos++] = '.';
int decimal = num % 100;
if( decimal > 9 ) {
itoa( decimal, &numStr[pos], 10 );
} else {
numStr[pos++] = '0';
itoa( decimal, &numStr[pos], 10 );
}
}

The only help I want is to help me print the dhtll_dat[0] & dhtll_dat[2] values to my lcd. In the serial monitor it prints "Current humdity = 58.0%  temperature = 29.0C "
I want these values printed to my nokia lcd...Please help!!!
THE PROBLEM is at the end of the code...I have comments so you find it fast...
Please reply....

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy