Hi,
I have been unable to print the DS18b20 temerature sensor to the ST7735 TFT screen from Adafruit. 128 x 160. Everything prints fine to the serial monitor.
I had expected that the following section calling up the temperature in Celsius would be able to print? Any help will be appreciated.
{
sensors.requestTemperatures(); // Send the command to get temperatures.
myTemp0 = (sensors.getTempCByIndex(0));
myTemp1 = (sensors.getTempCByIndex(1));
{
The following is as far as I have been able to get.
#include <SPI.h>
#include <TFT.h>
// Libraries for DS1820 and Onewire
#include <OneWire.h>
#include <DallasTemperature.h>
//You can use any (4 or) 5 pins
//#define sclk 4
//#define mosi 5
#define cs 6 // pin definition for the Uno
#define dc 7 // pin definition for the Uno
#define rst 8 // pin definition for the Uno
// you can also connect this to the Arduino reset
float myTemp0;
float myHighTemp0;
float myLowTemp0 = 50;
float myTemp1;
float myHighTemp1;
float myLowTemp1 = 50;
OneWire oneWire(2); // Setup onewire instance to communicate with devices.
DallasTemperature sensors(&oneWire);
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
void setup()
{
// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 255);
// write the static text to the screen
// set the font color to white
TFTscreen.stroke(0,0,0);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen
TFTscreen.text("Temperatures :\n ",10,0);
// set the font color to white
TFTscreen.stroke(50,50,50);
// set the font size
TFTscreen.setTextSize(1);
// write the text to the top left corner of the screen
TFTscreen.text("Fridge Temperature :\n ",10,20);
// write the text to the top left corner of the screen
TFTscreen.text("Pot One Temperature :\n ",10,30);
// ste the font size very large for the loop
TFTscreen.setTextSize(1);
sensors.begin();
Serial.begin(9600);
}
void loop()
{
readtemp(); // Read the temperature.
serialprint(); // Write the results to the serial monitor.
}
void readtemp() // call sensors.requestTemperatures() to issue
// a global temp request to all devices on the bus.
{
sensors.requestTemperatures(); // Send the command to get temperatures.
myTemp0 = (sensors.getTempCByIndex(0));
myTemp1 = (sensors.getTempCByIndex(1));
{
TFTscreen.stroke(255,255,255);
TFTscreen.setTextSize(1);
TFTScreen.print(myTemp0);
}
// Set High or Low Temp.
if (myTemp0 < myLowTemp0)
{
myLowTemp0 = myTemp0;
}
if (myTemp0 > myHighTemp0)
{
myHighTemp0 = myTemp0;
}
if (myTemp1 < myLowTemp1)
{
myLowTemp1 = myTemp1;
}
if (myTemp1 > myHighTemp1)
{
myHighTemp1 = myTemp1;
}
}
void serialprint()
{
Serial.print("Current Fridge Temp 0: ");
Serial.print(myTemp0);
Serial.print("C");
Serial.print(" Lowest Temp 0: ");
Serial.print(myLowTemp0);
Serial.print("C");
Serial.print(" Highest Temp 0: ");
Serial.print(myHighTemp0);
Serial.print("C");
Serial.print("\t\t");
Serial.print(" Current Pot Plant Temp 1: ");
Serial.print(myTemp1);
Serial.print("C");
Serial.print(" Lowest Temp 1: ");
Serial.print(myLowTemp1);
Serial.print("C");
Serial.print(" Highest Temp 1: ");
Serial.print(myHighTemp1);
Serial.println("C");
delay(2500);
}
Regards,
Wayne