HI All,
I hope someone here can be of assistance.
I have complied a sketch to use a DS18B20 and a 4 digit 7 segment LCD display, everything seems to work OK except for the LCD display. I can get the 1st digit and the last digit to display but the the middle two digits do not display anything when I try to display the reading from the DS18B20. If there is an error getting the reading from the sensor I display EEEE, this works fine.
Here is my code:
/*
ds18b20 temperature sensor with 7 Segment LED display
*/
// Include Libraries
#include <LedControl.h> // For the 7 Segment LED display driven by MAX7219
#include <OneWire.h> // For the one wire functions
#include <DallasTemperature.h> // For the DS18B20
#define ONE_WIRE_BUS 3 // Data wire is plugged into pin 3 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass oneWire reference to Dallas Temperature.
DeviceAddress TempSens = {
0x28, 0x01, 0xC0, 0xB8, 0x00, 0x00, 0x00, 0x86 }; // Assign the address for the 1-Wire temp sensor.
LedControl lc=LedControl(12,11,10,0); // Pin 12 to Data In, 11 to Clk, 10 to LOAD
void setup(void)
{
Serial.begin(9600); // Start Serial Port
sensors.begin(); // Start up the Sensor library
sensors.setResolution(TempSens, 12); // Set DS18B20 Resolution
lc.shutdown(0,false); // Turn off power saving, enables display
lc.setIntensity(0,10); // Sets brightness (0~15 possible values)
lc.clearDisplay(0); // Clear screen
}
//Used for testing on a serial terminal
/*
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print("Error getting temperature");
}
else
{
Serial.print("C: ");
Serial.print(tempC,1);
Serial.print("0");
}
}
*/
void displayDigit(DeviceAddress deviceAddress)
{
float temp = sensors.getTempC(deviceAddress);
int MyTemp = temp*100;
if (temp == -127.00)
{
for (int a=0; a<4;a++)
{
lc.setDigit(0,a,14,false); // Displays EEEE on 7 Segment if temp is -127.00
delay (5000); // Wait 5 seconds
lc.clearDisplay(0); // Clear the display
}
}
else
{
lc.setDigit(0,0,(MyTemp%10000)/1000,false); // Print 10s
lc.setDigit(0,1,(MyTemp%1000)/100,true); // Print 1s with decimal point
lc.setDigit(0,2,(MyTemp%100)/10,false); // Print 10th digit
lc.setDigit(0,3,0,false); // Ignore 100th digit and print "0" instead
}
}
void loop(void)
{
sensors.requestTemperatures(); // Request temps from DS18B20
displayDigit(TempSens); // Display temp for DS18B20 called TempSens
// This section is for testing only, it will display the temp for DS18B20 called TempSens on Serial Terminal
/*
delay(1000);
sensors.requestTemperatures();
Serial.print("TempSens temperature is: ");
printTemperature(TempSens);
Serial.print("\n\r");
*/
}
I'm a noob when it comes to coding
Thank you