It's been alomst a week of beating my head on the monitor and I just can't figure out how to get data from a simple DS18B20 or DHT22 to display on the TFT within the loop in the program.
It's a ILI9341 controlled TFT 2.4" generic offshore display shield, UNO and darn simple code. I'm just trying to display temperature on the TFT from the Dallas sensor.
I know the Dallas is working as I can see the data update every second on the serial monitor, I can get the sensor data to display on the TFT in the void setup section, but with the identical code in the loop, it won't display. I actually can't get anything to display within the loop, not even static ("text"). I'm using the Adafruit GFX and Adafruit TFTLCD libraries...I will post my code if need be, but I think I am just missing something fundamental here. I'm a newbie, have successfully written code and made things work with other projects, it's just this TFT I can't get to work. Why will it display the data just fine outside the loop, but not inside? Is it the TFT library?
Let me know what you need from me, I have never wasted so much time on a such a simple problem.
Thanks all, I hope to move onto the next phase of this project before it becomes obsolete. >:(
Thank you. here is the code. It's a bit of a jumble mess as I have been trying numerous things to make it work. One thing I should mention is that in the Adafruit TFT library there are instructions about using a code line if a shield is being used. When I use that code it won't compile. It's to do with using a shield or using a breakout board. I can load all of the included examples "graphicstest" etc. in the library and they work, not sure if this is important just an FYI.
Appreciate your help.
Thank you
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // Data wire is plugged into pin 2 on the Arduino
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
// D0 connects to digital pin 8 (Notice these are
// D1 connects to digital pin 9 NOT in order!)
// D2 connects to digital pin 2
// D3 connects to digital pin 3
// D4 connects to digital pin 4
// D5 connects to digital pin 5
// D6 connects to digital pin 6
// D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
// Calibrates value
#define SENSIBILITY 300
#define MINPRESSURE 10
#define MAXPRESSURE 1000
//These are the pins for the shield!
#define YP A1
#define XM A2
#define YM 7
#define XP 6
// Calibrate values
#define TS_MINX 125
#define TS_MINY 85
#define TS_MAXX 965
#define TS_MAXY 905
TouchScreen ts = TouchScreen(XP, YP, XM, YM, SENSIBILITY);
float Temp1; // storage DS18B20 variables temperature sensors
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
Serial.println("DS18B20 Temperature Sensor");
// Start up the library
sensors.begin();
sensors.requestTemperatures();
Temp1 = sensors.getTempCByIndex(0);
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.drawRect(0, 0, 319, 240, YELLOW);
tft.setCursor(30, 20);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("DS18B20 Sensor Data");
tft.setCursor(75, 50);
tft.setTextColor(MAGENTA);
tft.setTextSize(2);
tft.print("Temp *C");
tft.setCursor(80, 70);
tft.setTextColor(MAGENTA);
tft.setTextSize(2);
tft.print(Temp1, 3);
}
void loop() {
// sensors.requestTemperatures();
// Temp1 = sensors.getTempCByIndex(0);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.setCursor(80, 100);
tft.print(Temp1, 2); tft.println(" Loop Data");
delay(1000);
Serial.print(Temp1, 2); Serial.println(" *C ");
}
I fiddled some more with it today and simplified things and I am now able to display items in the loop, yEAH!, however I can only display them once, if I deactivate the lines
then the temperature and words Loop Data will appear on the screen just fine, of course the data won't update. When I activate those 2 lines I can see the data updating on the serial monitor but that data doesn't appear on the screen anymore.
Glad I am making some progress.
Any help greatly appreciated.
Thank you
PS my updated code is in my previous post, rather than displaying it again here. thx
I think this has consumed enough of my time for now, I may just buy a pre-built controller. I am building a small beer brew setup, electric, and this is just the controller, and I have spent almost a week of after work time trying to get this one little thing to work, just the display, let alone all the rest of the code required. It might may be best to let others figure out the controller, and I will get back to fabricating pipes, plumbing etc.
Thanks for your help though, appreciated. I may come back to it this winter when there is nothing else to do, and just start the brewing manually for now.