Perfect! That fixed it. Thanks so much.dastels wrote: ↑Wed Nov 23, 2022 6:12 pm Yes. Your syntax is incorrect.
Maybe:DaveCode: Select all
//digitalWrite(12, rel_hum >= 80); if (rel_hum >=80) { digitalWrite(12, HIGH); Serial.println("Vent: ON"); } else if (rel_hum <=60) { digitalWrite(12, LOW); Serial.println("Vent: OFF"); }
Sensor + Relay + RTC + Display - Arduino Code
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
Well now I have the tft wired into the board again. Can you suggest any shortcuts for getting the serial monitor data to the display?
I've installed libraries and tried to paste the "graphicstest" example into my existing sketch just to see if I can get them to run together, but I'm just getting error messages.
I've installed libraries and tried to paste the "graphicstest" example into my existing sketch just to see if I can get them to run together, but I'm just getting error messages.
- Franklin97355
- Posts: 23916
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Sensor + Relay + RTC + Display - Arduino Code
The error messages would help. Do you want just serial character data or graphics too?
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
I only want serial data to display. Just haven't found any real clear explanations or examples yet.Franklin97355 wrote: ↑Sat Nov 26, 2022 12:38 pm The error messages would help. Do you want just serial character data or graphics too?
I'll share error messages when I start working on the actual problem.
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
Well I have this update with initialization for the tft. Any hints for getting serial data to the display? I've tried to apply a few examples, but just getting stuck every time so far....
Could something like this be in the ballpark?
I tried this in the loop, but it didn't anything for the display.
Code: Select all
#include <RTClib.h>
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
RTC_DS1307 rtc;
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
pinMode(12, OUTPUT);
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
tft.init(135, 240); // Init ST7789 240x135
}
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
}
}
void loop() {
float temp = htu.readTemperature();
float rel_hum = htu.readHumidity();
Serial.print("Temp: "); Serial.print(temp); Serial.print(" C");
Serial.print("\t");
Serial.print("RH: "); Serial.print(rel_hum); Serial.println(" \%");
delay(4000);
if (rel_hum >=80) {
digitalWrite(12, HIGH);
Serial.println("Vent: ON");
} else if (rel_hum <=60) {
digitalWrite(12, LOW);
Serial.println("Vent: OFF");
}
{
DateTime now = rtc.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print("\t");
delay(3000);
}
}
Could something like this be in the ballpark?
Code: Select all
if (Serial.available())
tft.print((char)Serial.read());
- dastels
- Posts: 15699
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Sensor + Relay + RTC + Display - Arduino Code
Often a you need to do a println at the end to flush the line out. Not sure if that's the case here but it's worth a try.
Dave
Dave
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
Well I've looked around the tft example some more and pared down the rest as much as possible, with text ("TEST") displaying how I want it. I added this in setup...
...with this at the end...
That example also has this short text that prints to the serial just once while "TEST" displays on the screen ...
I've tried a few different things and can't even get this to the tft. Any other hints? IS this any closer...
Code: Select all
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(30, 30);
tft.fillScreen(ST77XX_BLACK);
drawtext("TEST", ST77XX_WHITE);
delay(100);
tft.invertDisplay(true);
delay(1000);
Code: Select all
void drawtext(char *text, uint16_t color) {
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
Code: Select all
Serial.print(F("Hello! ST77xx TFT Test"));
Code: Select all
if (Serial.available()) {
tft.write(Serial.println());
}
- dastels
- Posts: 15699
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Sensor + Relay + RTC + Display - Arduino Code
Code: Select all
if (Serial.available()) {
tft.write(Serial.println());
}
Code: Select all
tft.writeln();
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
Do you mean that by itself somewhere, or like this?...
Code: Select all
if (Serial.available()) {
tft.writeln();
}
- dastels
- Posts: 15699
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Sensor + Relay + RTC + Display - Arduino Code
Let's back up a step. What are you trying to do with the display. The code you've been sharing seems to be trying to put on the tft what you type into the Serial console/monitor. Reading through the conversation I think you want the tft to echo what gets output to Serial. Is that right?
Dave
Dave
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
Yes, that is correct. The sketch is doing everything else I need and I just want serial to display on the tft, clearing between each line of data. Here's what I have so far. Apologies I know it's messy....dastels wrote: ↑Thu Dec 01, 2022 9:52 am Let's back up a step. What are you trying to do with the display. The code you've been sharing seems to be trying to put on the tft what you type into the Serial console/monitor. Reading through the conversation I think you want the tft to echo what gets output to Serial. Is that right?
Dave
Code: Select all
#include <RTClib.h>
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
RTC_DS1307 rtc;
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
pinMode(12, OUTPUT);
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
tft.init(135, 240);
tft.setRotation(3);
tft.setTextSize(2);
tft.setCursor(30, 30);
tft.fillScreen(ST77XX_BLACK);
tft.fillScreen(ST77XX_BLACK);
//drawtext("TEST", ST77XX_WHITE);
delay(1000);
}
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
}
}
void loop()
{
float temp = htu.readTemperature();
float rel_hum = htu.readHumidity();
Serial.print("Temp: "); Serial.print(temp); Serial.print(" C");
Serial.print("\t");
Serial.print("RH: "); Serial.print(rel_hum); Serial.println(" \%");
delay(4000);
if (rel_hum >=80) {
digitalWrite(12, HIGH);
Serial.println("Vent: ON");
} else if (rel_hum <=60) {
digitalWrite(12, LOW);
Serial.println("Vent: OFF");
}
{
DateTime now = rtc.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print("\t");
delay(3000);
}
}
void drawtext(char *text, uint16_t color) {
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
I don't understand exactly what the third void function accomplishes and I'm sure it's part of my problem. I just left it in there because it was the only way I could get anything to the tft....
Code: Select all
void drawtext(char *text, uint16_t color) {
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
- dastels
- Posts: 15699
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Sensor + Relay + RTC + Display - Arduino Code
You probably want to close the block after
rather than after
BTW, Arduino has formatter to clean up your code.
Have a look at some of the examples for the tft. There will be some that output text that should give you need. Usually on a display like this, you set the cursor position, then output the text rather than having it scroll.
Reading through the GFX guide will be a help as well: https://learn.adafruit.com/adafruit-gfx ... cs-library
Dave
Code: Select all
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
Code: Select all
delay(1000);
Have a look at some of the examples for the tft. There will be some that output text that should give you need. Usually on a display like this, you set the cursor position, then output the text rather than having it scroll.
Reading through the GFX guide will be a help as well: https://learn.adafruit.com/adafruit-gfx ... cs-library
Dave
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
Actually the serial write breaks when I move that line down...I'll experiment with it some more.dastels wrote: ↑Thu Dec 01, 2022 11:47 pm You probably want to close the block afterrather than afterCode: Select all
if (!htu.begin()) { Serial.println("Couldn't find sensor!"); while (1);
BTW, Arduino has formatter to clean up your code.Code: Select all
delay(1000);
Have a look at some of the examples for the tft. There will be some that output text that should give you need. Usually on a display like this, you set the cursor position, then output the text rather than having it scroll.
Reading through the GFX guide will be a help as well:DaveCode: Select all
https://learn.adafruit.com/adafruit-gfx-graphics-library
I think I have a handle on the gfx library as far as getting text to display right.
Yep I've been through most of the tft examples and have not yet seen something like this wither serial data displaying on the tft. Anywhere else to look for examples?
- dastels
- Posts: 15699
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Sensor + Relay + RTC + Display - Arduino Code
You won't display serial data on the display, you'll put data on the display as well (or instead of) printing it to serial.
Dave
Dave
- hydrophyte
- Posts: 67
- Joined: Tue Mar 23, 2021 12:52 am
Re: Sensor + Relay + RTC + Display - Arduino Code
Well I guess I had wondered about that. I had this idea in mind because I saw a couple projects that seemed to have taken approach for some reason.
How about, as a new starting point, setting up the tft graphics in setup...
Code: Select all
tft.setRotation(3);
tft.setTextSize(2);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(30, 30);
delay(1000);
Code: Select all
float temp = htu.readTemperature();
float rel_hum = htu.readHumidity();
tft.print("Temp: "); tft.print(temp); tft.println(" C");
tft.print("\t");
tft.print("RH: "); tft.print(rel_hum); tft.println(" \%");
Code: Select all
DateTime now = rtc.now();
tft.print(now.hour(), DEC);
tft.print(':');
tft.print(now.minute(), DEC);
tft.print(':');
tft.print(now.second(), DEC);
tft.print("\t");
Please be positive and constructive with your questions and comments.