Arduino Forum

Using Arduino => Programming Questions => Topic started by: danielb on Jan 21, 2013, 02:01 pm

Title: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 21, 2013, 02:01 pm
Hi everybody
I'm Daniele from Italy and I'm happy to be here.

I'm tryng to dispaly a temperature by this display ( i've read everything )
but I've got a big problem

I see on dispaly      e127 °C
and if i unplug +5 volts to ds18b20 it become 0 27 °C

this is the code that I wrote

Serial.println(temperature,DEC);
      char buffer[4];
      itoa(temperature,buffer,10);
      ht1632_putchar(0 , 0, buffer[0]);
      ht1632_putchar(6 , 0, buffer[1]);
      ht1632_putchar(12 , 0, buffer[2]);
      ht1632_putchar(18 , 0, buffer[3]);
      ht1632_puttinychar(26 , 0, 'o');
      ht1632_putchar(33 , 0, 'C');
      delay(150);

any idea ???

thank you so much

Daniele
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: PaulS on Jan 21, 2013, 02:22 pm
Quote
and if i unplug +5 volts to ds18b20 it become 0 27 °C

Why does that surprise you? If the sensor isn't powered, it can't function. If it can't function, you really can't expect to read a temperature from it, can you?

Of course, it's hard to tell much from your snippet of code.
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 21, 2013, 03:04 pm
thank you so much !

of course that if the sensor isn't powered it doesn't works !

i try it to be sure that the input pin was correct and the buffer was filled by data !

I shoult post full code ?
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 21, 2013, 03:10 pm
this is the full code

I use pin 13 of atmel ( input 7 of arduino )

Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 21, 2013, 05:17 pm
I think there needs to be a call to "sensors.requestTemperatures()" and "sensors.getTemp..." in there.  Did you look at the sample code for DallasTemperature?
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 21, 2013, 05:50 pm
thanks for your answer

"sensors.requestTemperatures()"  ( i forgot to write it on here but is present on sketch )

what and where else exatly ?

char temperature = 0 ;

sensors.requestTemperatures();

Serial.println(temperature,DEC);

      char buffer[4];
      itoa(temperature,buffer,10);
      ht1632_putchar(0 , 0, buffer[0]);
      ht1632_putchar(6 , 0, buffer[1]);
      ht1632_putchar(12 , 0, buffer[2]);
      ht1632_putchar(18 , 0, buffer[3]);
      ht1632_puttinychar(26 , 0, 'o');
      ht1632_putchar(33 , 0, 'C');
      delay(150);


thanks
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 21, 2013, 05:51 pm
sorry for multiple post

like this ??

char temperature = 0 ;
sensors.requestTemperatures();

temperature = (sensors.getTempCByIndex(0));


Serial.println(temperature,DEC);
      char buffer[4];
      itoa(temperature,buffer,10);
      ht1632_putchar(0 , 0, buffer[0]);
      ht1632_putchar(6 , 0, buffer[1]);
      ht1632_putchar(12 , 0, buffer[2]);
      ht1632_putchar(18 , 0, buffer[3]);
      ht1632_puttinychar(26 , 0, 'o');
      ht1632_putchar(33 , 0, 'C');
      delay(150);
 
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 21, 2013, 06:00 pm
That does look much closer to being right.

getTempCByIndex() does not return a char though, it returns float. 
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 21, 2013, 06:41 pm
ahhhh so  what i should change ??

float temperature = 0 ??


thanks in advance
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 21, 2013, 06:54 pm
Actually no, sorry, you were better off with the char, you just won't be getting fractional degrees.
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 21, 2013, 07:04 pm
I don't understand.
I' can't convert ?

What's the problem with decimal ?

ie I can't show on this dispaly 22,5 °C ?
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 21, 2013, 07:08 pm
I think at this point you should just try it and see.
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 21, 2013, 07:21 pm
  float temperature=0 ;
sensors.requestTemperatures();

temperature = (sensors.getTempCByIndex(0));


Serial.println(temperature,DEC);
      char buffer[4];
      itoa(temperature,buffer,10);
      ht1632_putchar(0 , 0, buffer[0]);
      ht1632_putchar(6 , 0, buffer[1]);
      ht1632_putchar(12 , 0, buffer[2]);
      ht1632_putchar(18 , 0, buffer[3]);
      ht1632_puttinychar(26 , 0, 'o');
      ht1632_putchar(33 , 0, 'C');
      delay(150);


do not works... e127 °C show
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 22, 2013, 02:31 am
Which part do you suppose is not working-- the part that reads the temperature from the sensor, or the part that displays the temperature on the LCD screen?
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 22, 2013, 09:18 am
I think that inside buffer there is nothing becouse it write 127. The ds 18b20 works perfectly becouse with lcd skecht show the correct temperature
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: UKHeliBob on Jan 22, 2013, 09:54 am
Some questions :

What do you get on the screen if you just output buffer[0] ?

Does the same problem occur if you output the temperature to somewhere else on the screen ?

What happens if you output  the temperature twice ?  Output it once then output it again without clearing the screen ?

What does your code do to the screen immediately before showing the temperature ?

What happens if you print some text before the temperature ?

What happens if you put a specific value in the buffer without reading the temperature then output it ?
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 22, 2013, 12:13 pm
this is with the code posted

( fot.jpg)

i tryed to give a value and it put on display it and it show the value
( exaple 22.50 )

sensors.requestTemperatures();

float TempC = 22.50 ;//sensors.getTempCByIndex(0);

Serial.println(TempC,DEC);
      char buffer[4];
      itoa(TempC,buffer,10);
      ht1632_putchar(0 , 8, buffer[0]);
      ht1632_putchar(6 , 8, buffer[1]);
      ht1632_putchar(12 , 8, buffer[2]);
      ht1632_putchar(18 , 8, buffer[3]);
      ht1632_putchar(24 , 8, buffer[3]);
      ht1632_puttinychar(32 , 8, 'o');
      ht1632_putchar(39 , 8, 'C');
      delay(150); 

this is the result ( foto22.jpg )


thanks in advance
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 22, 2013, 02:21 pm
if i write float TempC =  2250;
show 22500 °C

in serial monitor
show the temperature in this way :  19.4375000000

I think the problem is the decimal

I must divide 19 from 43 without the dot ( or comma )

put 19 into a buffer and the 43 into another buffer

then show it

Right ???

thanks
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 22, 2013, 02:48 pm

if i write float TempC =  2250;
show 22500 °C

in serial monitor
show the temperature in this way :  19.4375000000


That's strange, I would expect to see: 2250 , wouldn't you?

Quote

I think the problem is the decimal
I must divide 19 from 43 without the dot ( or comma )
put 19 into a buffer and the 43 into another buffer
then show it
Right ???
thanks


Pretty much.  You will need to adjust your buffer size to 5 and/or adjust your placement on the screen if you want to be able to show "19.43", since that is five characters and your existing code uses four.  Or, you could show it as "19.4" and leave it where it is on the screen.

John
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 22, 2013, 04:19 pm
yes of course
but i can resolve 22500 problem display but not my BIG problem

If I write

float TempC = sensors.getTempCByIndex(0);

I should see something !!! not e127 that is the error when someting goes wrong !!

I need help for this

resolve 22550 end not 22 50 will be able to resolve !!
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 24, 2013, 12:06 pm
hi guys
don't rell me how but now it WORKS !!!

this is the correct code


sensors.requestTemperatures();

int temp = sensors.getTempCByIndex(0);

Serial.println(temp,DEC);
      char buffer[4];
      itoa(temp,buffer,10);
      ht1632_putchar(6 , 8, buffer[0]);
      ht1632_putchar(12 , 8, buffer[1]);
//     ht1632_putchar(12 , 8, buffer[2]);
//     ht1632_putchar(18 , 8, buffer[3]);
      ht1632_puttinychar(19 , 8, 'o');
      ht1632_putchar(24 , 8, 'C');
      delay(150); 


only one question ( easy i think )

now it show the temperature in this format XX °C

and if I would like to show decimal ?

ie   XX,X °C ?

how I should change it ?

Many thanks

Daniel
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: PaulS on Jan 24, 2013, 12:11 pm
Quote
how I should change it ?

Based on snippets? Who knows? Post ALL of your code. Right now, we can only guess what sensors is.

Code: [Select]
int temp = sensors.getTempCByIndex(0);
Does that method return an int? Or a float?
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 24, 2013, 12:55 pm
Pauls Thank you for your answer
the kind of sensor il write on the topic and on the top post... SENSOR IS DALLAS DS18B20

the entire code was just posted so I repost

Thank you so much

Daniele
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: PaulS on Jan 24, 2013, 01:02 pm
Code: [Select]
  // returns temperature in degrees C
  float getTempC(uint8_t*);

  // returns temperature in degrees F
  float getTempF(uint8_t*);

  // Get temperature for device index (slow)
  float getTempCByIndex(uint8_t);
 
  // Get temperature for device index (slow)
  float getTempFByIndex(uint8_t);

So, yes all the methods to get the temperature return a float, not an int.

Your buffer will need to be larger, and you'll need to use ftoa(), instead of itoa(). After that, you'll need to put more characters to the display.
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 24, 2013, 01:09 pm
thanks
so what i change ?

int temp = sensors.getTempCByIndex(0);

to

float temp = sensors.getTempCByIndex(0);  ???

then ?
( I think I must change sometingh here but how ? )

char buffer[4];
      itoa(temp,buffer,10);


Many thanks

Daniel
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: PaulS on Jan 24, 2013, 01:45 pm
Quote
( I think I must change sometingh here but how ? )

Quote
Your buffer will need to be larger, and you'll need to use ftoa(), instead of itoa(). After that, you'll need to put more characters to the display.
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 24, 2013, 01:57 pm
if i change

itoa(temp,buffer,10);

to

ftoa(temp,buffer,10);

I receive this error

lcd24x16_base___temperatura.cpp: In function 'void loop()':
lcd24x16_base___temperatura:112: error: 'ftoa' was not declared in this scope

where is the problem ?
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: PaulS on Jan 24, 2013, 02:51 pm
Try dtostrf().
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 24, 2013, 04:48 pm
lcd24x16_base___temperatura.cpp: In function 'void loop()':
lcd24x16_base___temperatura:112: error: invalid conversion from 'char*' to 'signed char'
c:/users/daniele/desktop/varie2/arduino-0023/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:581: error: too few arguments to function 'char* dtostrf(double, signed char, unsigned char, char*)'
lcd24x16_base___temperatura:112: error: at this point in file
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: PeterH on Jan 24, 2013, 05:16 pm

error: too few arguments to function 'char* dtostrf(double, signed char, unsigned char, char*)'


You aren't passing the correct number and type of arguments to dtostrf(). The documentation tells you what it expects. Only you know what you're actually providing, since we can't see your code, but it's obviously not correct. Change your code so it passes the arguments that the function expects.
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 24, 2013, 05:48 pm
I understand the kind of error but I don't know what I should write.



sensors.requestTemperatures();

float temp = sensors.getTempCByIndex(0);

Serial.println(temp,DEC);
      char buffer[8];
      dtostrf(temp,buffer,10);                                    <====== Float temp inside to buffer in decimal type but how change it ?
      ht1632_putchar(6 , 8, buffer[0]);
      ht1632_putchar(12 , 8, buffer[1]);
//     ht1632_putchar(12 , 8, buffer[2]);
//     ht1632_putchar(18 , 8, buffer[3]);
      ht1632_puttinychar(19 , 8, 'o');
      ht1632_putchar(24 , 8, 'C');
      delay(150); 


temp is the variable where the sensor give the reading of temperature
buffer is where temp goes

how convert by dtostrf float temp to buffer  ?


the error is

dtostrf(double, signed char, unsigned char, char*)

what is double ?
what is signed char ?
what is unsigned char ?
what is char* ?

many thanks

Daniel
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 24, 2013, 06:19 pm
http://lmgtfy.com/?q=dtostrf&l=1

This has information about what the parameters need to be.  If you have trouble interpreting it, post back with what you tried and why  :)

Cheers,
John
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: PaulS on Jan 24, 2013, 06:19 pm
Quote
what is double ?

The value to be converted.

Quote
what is signed char ?

The width of the string to be produced. Why an signed char? Beats me.

Quote
what is unsigned char ?

The precision - the number of places after the decimal point. Why an unsigned char? Beats me.

Quote
what is char* ?

The buffer where the string is to be created.

Code: [Select]
float someTemp = 14.5;
char buffer[10];
dtostrf(someTemp, 8, 3, buffer);
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 24, 2013, 06:43 pm
many thanks for you help

here what I write


sensors.requestTemperatures();
//int temp = sensors.getTempCByIndex(0);
float temp = sensors.getTempCByIndex(0);

Serial.println(temp,DEC);
      char buffer[10];
   //     itoa(temp,buffer,10);
      dtostrf(temp, 8, 3, buffer);
      ht1632_putchar(6 , 8, buffer[0]);
      ht1632_putchar(12 , 8, buffer[1]);
      ht1632_putchar(18 , 8, buffer[2]);
      ht1632_putchar(24 , 8, buffer[3]);
      ht1632_puttinychar(32 , 8, 'o');
      ht1632_putchar(35 , 8, 'C');
      delay(150); 

in this way change only where the temp is writed on display

ie 22 degree is written in decimal position  _ _ , 22 °C

but without comma

where is the error ? I feel to be near to solution

Many thanks
Daniel
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 24, 2013, 07:18 pm
I think you would do better to consider the code that Paul provided as an example and an opportunity to think about how it applies to your situation rather than something to just paste into your code and report back that it doesn't work.

You should ask yourself questions like
How wide do I want the number to be?  e.g. "22.51345" would be 8 wide
What precision do I want it to have ?   e.g. "-23.434"  would be a precision of 3.
and
Is my buffer[] big enough to hold it?
Do I have room to put it on the LCD buffer[0], buffer[1], buffer[2],... buffer[width-1]

Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: danielb on Jan 24, 2013, 07:34 pm
jhon thank you so much now with your details I've understand the meaning of it

I've changed the code here

float temp = sensors.getTempCByIndex(0);

Serial.println(temp,DEC);
      char buffer[10];
   //     itoa(temp,buffer,10);
      dtostrf(temp, 5, 2, buffer);
      ht1632_putchar(6 , 8, buffer[0]);
      ht1632_putchar(12 , 8, buffer[1]);
      ht1632_putchar(18 , 8, buffer[2]);
      ht1632_putchar(24 , 8, buffer[3]);
      ht1632_puttinychar(32 , 8, 'o');
      ht1632_putchar(37 , 8, 'C');
      delay(150); 

now works perfectly

many thanks
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: johncc on Jan 24, 2013, 07:40 pm
Great!!  Then we'll leave it at that for now  ;)
Title: Re: Arduino Uno ds18b20 and sure 2416 dor matrix display
Post by: PaulS on Jan 24, 2013, 11:24 pm
You are asking for 5 characters in the output, with two  digits after the decimal point, so something like 23.45. Then, you are showing 4 characters on the LCD (23.4). Why?