Arduino Uno ds18b20 and sure 2416 dor matrix display

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 !!

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

how I should change it ?

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

int temp = sensors.getTempCByIndex(0);

Does that method return an int? Or a float?

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

dallas 18B20.txt (15 KB)

  // 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.

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

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

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.

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 ?

Try dtostrf().

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

danielb:
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.

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

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

Cheers,
John

what is double ?

The value to be converted.

what is signed char ?

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

what is unsigned char ?

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

what is char* ?

The buffer where the string is to be created.

float someTemp = 14.5;
char buffer[10];
dtostrf(someTemp, 8, 3, buffer);

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

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]

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

Great!! Then we'll leave it at that for now :wink:

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?