displaying temperature on seven segment 4-digit display

I need help with displaying all four digits of the temperature reading, as I have only managed to get the first two digits of the temperature reading to display on the 4-digit screen.(which means the display only shows whole numbers and no decimals). the temperature reading is as shown in attachment(note only four and four digits are one temperature scan). all I`ve tried has either ended up with the display showing “0” or just a “_”, but not any numbers related to the reading

Note I do not claim that anything in this script is mine, as I have copied from different sources and sticthes this together

this is my script:

#include <OneWire.h>
#include <DallasTemperature.h>
#include “TM1637.h”

//{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//0~9,A,b,C,d,E,F

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define CLK 7//Pins for TM1637
#define DIO 8

TM1637 tm1637(CLK,DIO);

void setup(){

tm1637.init();
tm1637.set(BRIGHT_TYPICAL);
//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
sensors.begin();
Serial.begin(9600);

delay(1500);//Delay to let system boot

}//end “setup()”

void loop(){

//Start of Program

sensors.requestTemperatures();
sensors.getTempCByIndex(0);
Serial.print(sensors.getTempCByIndex(0));

int temp = sensors.getTempCByIndex(0);

int digitoneT = temp / 10;
int digittwoT = temp % 10;
int digittreeT = temp / 10;
int digitfourT = temp % 10;

tm1637.display(0,digitoneT);
tm1637.display(1,digittwoT);
//tm1637.display(2,digittreeT);
//tm1637.display(3,digitfourT);

//tm1637.display(2,12); // put a C at the end

delay (3000);

//Wait 3 seconds before accessing sensor again.

//Fastest should be once every two seconds.
delay(3000);

}// end loop()

Skjermbilde.PNG

That display is hard to read, with on spaces or linefeeds.

Try changing
Serial.print(sensors.getTempCByIndex(0));
to
Serial.println(sensors.getTempCByIndex(0));

now show us the output that way. How does it look to you?

foggha:
I need help with displaying all four digits of the temperature reading, as I have only managed to get the first two digits of the temperature reading to display on the 4-digit screen.(which means the display only shows whole numbers and no decimals). the temperature reading is as shown in attachment(note only four and four digits are one temperature scan). all I`ve tried has either ended up with the display showing “0” or just a “_”, but not any numbers related to the reading

Note I do not claim that anything in this script is mine, as I have copied from different sources and sticthes this together

you were throwing away the decimal value when you read the sensor into an int

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

   int x = temp *100; // get rid of decimal point,  x is now temp in 1/100 degrees
 
  for(uint8_t i = 0; i<4;i++){
    int digit =  x%10; // strip off lowest digit
    tm1637.display(3-i,digit);
    x=x/10;
    }


}// end loop()

Chuck.

thank you so much, problem solved. println() also made things on the serial easier to read

Tried this code with aDS18B20 probe, and throw it in the freezer, as it passed zero deg it show 04C, any hints on how to fix this so it show decimals that match the northern hemosphere? :slight_smile:
if the numbers were 1 decimal further to the right there would also be room for the - in front of the numbers.