Hello,
I’m somewhat new to the programming and libraries for Arduino Uno.
The setup I have is: Arduino Uno with a Velleman 2.8” touchscreen connected directly to the Arduino.
In addition I have an SHT85 sensor connected through the I2C lines, SCL and SDA because these lines are not used by the touch screen.
I have the sensor working if I read its data through the serial monitor.
I also have the touch screen working with presenting text on it.
Both are running in the same program.
However, if I execute the “sht.Read()” statement, the screen goes blank but I can still read the data from sensor on the serial monitor.
The question I have is, how can I make this work on the touch screen?
The program listing is below.
Thanks for any help,
Ron
#include <Wire.h>
#include "SHT85.h"
#define SHT85_ADDRESS 0x44
uint32_t start;
uint32_t stop;
SHT85 sht(SHT85_ADDRESS);
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft; // hard-wired for UNO shields anyway.
#include <TouchScreen.h>
const int XP=8,XM=A2,YP=A3,YM=9; // Touch screen I/O
const int TS_LEFT=918,TS_RT=107,TS_TOP=67,TS_BOT=902; // For landscape
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TSPoint tp;
#define MINPRESSURE 150
#define MAXPRESSURE 1000
#define SHT85_ADDRESS 0x44
#define BLACK 0x0000 ///< 0, 0, 0
#define NAVY 0x000F ///< 0, 0, 123
#define DARKGREEN 0x03E0 ///< 0, 125, 0
#define DARKCYAN 0x03EF ///< 0, 125, 123
#define MAROON 0x7800 ///< 123, 0, 0
#define PURPLE 0x780F ///< 123, 0, 123
#define OLIVE 0x7BE0 ///< 123, 125, 0
#define LIGHTGREY 0xC618 ///< 198, 195, 198
#define DARKGREY 0x7BEF ///< 123, 125, 123
#define BLUE 0x001F ///< 0, 0, 255
#define GREEN 0x07E0 ///< 0, 255, 0
#define CYAN 0x07FF ///< 0, 255, 255
#define RED 0xF800 ///< 255, 0, 0
#define MAGENTA 0xF81F ///< 255, 0, 255
#define YELLOW 0xFFE0 ///< 255, 255, 0
#define WHITE 0xFFFF ///< 255, 255, 255
#define ORANGE 0xFD20 ///< 255, 165, 0
#define GREENYELLOW 0xAFE5 ///< 173, 255, 41
uint8_t Orientation = 1; //Landscape
uint16_t ID;
uint8_t Screen = 0; // Home screen
int Xpos = 0; // X position of screen touch
int Ypos = 0; // Y position of screen touch
int B1x = 250, B1y = 60, B1w = 60, B1h = 45;
int B2x = 250, B2y = 135, B2w = 60, B2h = 45;
void setup()
{
// while(!Serial); // uncomment if needed
Serial.begin(9600);
Serial.println();
Wire.begin();
Wire.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);
Serial.println();
uint32_t ser;
bool b = sht.getSerialNumber(ser, true);
if (b)
{
Serial.print(ser, HEX);
Serial.println();
}
else
{
Serial.println("Error: could not get serial number.");
}
delay(1000);
tft.reset();
ID = tft.readID();
tft.begin(ID);
tft.setRotation(Orientation);
tft.fillScreen(BLACK);
Screen = 0;
tft.setCursor(20,75); tft.setTextColor(WHITE, BLACK); tft.setTextSize(2);
tft.print("TEMPERATURE (C):");
tft.setCursor(20,150); tft.setTextColor(WHITE, BLACK); tft.setTextSize(2);
tft.print("REL. HUMIDITY (%):");
tft.drawRect(B1x, B1y, B1w, B1h, YELLOW);
tft.drawRect(B2x, B2y, B2w, B2h, YELLOW);
delay(100);
}
void loop(){
sht.read();
tft.setCursor(250,75); tft.setTextColor(WHITE, BLACK); tft.setTextSize(2);
tft.print(sht.getTemperature(), 1);
Serial.print("\t");
Serial.print((stop - start) * 0.001);
Serial.print("\t");
Serial.print(sht.getTemperature(), 1);
Serial.print("\t");
Serial.println(sht.getHumidity(), 1);
delay(100);
}




