Look at the picture
Now I have to separate the three values somehow to make it "fit" into the display. Thanks a lot and see you tomorrow!!!!!!!!!!!!!!!!
I am glad it worked but annoyed that I did not spot the real problem earlier but I was concentrating on the problem as presented rather than looking for the real reason.
You can blame it all on me - I spent to much time with people like MAX232 and obviously that spoiled me
What I want to do next is to separate the three values from each other - is there a possibility to assign each of them to a different variable? This would give me the possibility to locate them in different spots of the display! The whole thing would be more attractive and better readable!!
Thank you again Bob - you saved me!!!!!!!
Here´s the code as is so far
/
* Hardware: [NodeMCU, TFT 2.2" Display] - [ArduinoUno, Ethernetshield, Router]
Captures weatherdata from local WLAN (Arduino Webserver) and shows it on a TFT 2.2" Display
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define Serial Serial
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"
#include "SPI.h"
ESP8266WiFiMulti WiFiMulti;
//Pinout for Display
#define TFT_CS D0 // GPIO 16
#define TFT_RST 10 // D12 GPIO10
#define TFT_DC D1 // GPIO 5
#define TFT_MOSI D7 // GPIO 13
#define TFT_CLK D5 // GPIO 14
#define TFT_MISO D6 // GPIO 12
Adafruit_ILI9340 tft = Adafruit_ILI9340(TFT_CS, TFT_DC, TFT_RST);
#define ROTATION_NO 0
#define ROTATION_90 1
#define ROTATION_180 2
#define ROTATION_270 3
//**************************************
String weatherdata;
//**************************************
void setup() {
Serial.begin(115200);
// Serial.setDebugOutput(true);
Serial.println();
Serial.println();
Serial.println();
for (uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("DLINK", "C63SxIpdTT");
tft.begin();
tft.setRotation( ROTATION_270);
tft_printFrame();
tft_printCaption();
//tft_showData();
}
//Void setup()end
void tft_printCaption( )
{
tft.setTextColor(ILI9340_WHITE);
tft.setCursor( 10, 55);
tft.setTextSize(2);
tft.print("Bodentemperatur in ");
tft.setTextSize(1);
tft.print("O");
tft.setTextSize(3);
tft.print("C");
tft.setTextSize(2);
tft.setCursor( 50, 15);
tft.print(" HPascal");
tft.setTextSize(2);
tft.setCursor( 10, 210);
tft.print(" Prozent");
}
void tft_printFrame( )
{
tft.fillScreen(ILI9340_BLACK);
tft.drawRoundRect(1, 0, tft.width() - 1, 40, 10, ILI9340_BLUE);
tft.drawRoundRect(1, 50, tft.width() - 1, 135, 10, ILI9340_GREEN);
tft.drawRoundRect(0, 200, tft.width() - 1, 40, 10, ILI9340_RED);
}
void tft_showData()
{
tft.setTextSize(4);
tft.setTextColor(ILI9340_YELLOW, ILI9340_BLACK );
tft.setTextWrap(false);
tft.setCursor(20, 90);
tft.print(weatherdata);
Serial.print(weatherdata);
}
void tft_show_errormessage()
{
// if (httpCode == HTTP_CODE_OK) {}
tft.setCursor(20, 90);
tft.println(" ");
tft.print(" ");
tft.setTextSize(10);
tft.setTextColor(ILI9340_YELLOW, ILI9340_BLACK );
tft.setTextWrap(false);
tft.setCursor(20, 90);
tft.print("Error");
}
void loop( ) {
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
Serial.print("[HTTP] begin...\n");
// configure traged server and url
http.begin("http://192.168.1.17/?mode=text"); //HTTP to Plaintext
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
weatherdata = http.getString();// This variable contains airpressure, humidity and temperature
tft_showData();//That was a tough nut - cudos to UKHeliBob!!!!!!
}
}
else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
tft_show_errormessage();
}
http.end();
}else {tft_show_errormessage();}
}
I don't use the String library as it is regarded as the cause of memory fragmentation, particularly when Strings are copied/manipulated/split as you want to. However, judging by this
String() - Arduino Reference there are String functions that would allow you to split the String into component parts.
The general advice is not to use Strings but to use strings (zero terminated arrays of chars) which are much more memory friendly in the small memory environment of most Arduinos. I note, however, that you are using an 8266 which has more memory available and many examples that I have seen for it use Strings
Thanks - I´ll try that!!
Unfortunately I have another problem (suits me ) I need this webserver to send plain text and html. At the moment it sends only html. Maybe somebody has an idea how this could be done!! Thanks in advance!
greetings
#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
float temperature;
float humidity;
float pressure;
#define ALTITUDE 326.0
Adafruit_BME280 bme; // I2C
byte mac[] = { 0xDE, 0x13, 0x02, 0x58, 0xFF, 0x01 }; // MAC Adresse des Arduino Boards
byte ip[] = { 192, 168, 1, 15 }; // IP Adresse of Arduino Board
//byte gateway[] = { 192, 168, 1, 1 }; // Gateway (optional)
//byte subnet[] = { 255, 255, 255, 0 }; // Subnet Mask (optional)
EthernetServer server(80); // Port of server (Standard 80)
void setup() {
// initialize serial:
Serial.begin(115200);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("Server is at ");
Serial.println(Ethernet.localIP());
Serial.print("Reading sensor...");
Serial.println();
bool status;
// default settings
status = bme.begin(0x76); //The I2C address of the sensor I use is 0x76
if (!status) {
Serial.print("Error. Check");
Serial.print("connections");
while (1);
}
}
void loop() {
delay(2000);
getPressure();
getHumidity();
getTemperature();
//Printing Temperature
String temperatureString = String(temperature, 1);
Serial.print("T: ");
Serial.print(temperatureString);
//Serial.print((char)248);
Serial.print("C ");
Serial.print(" ");
//Printing Humidity
String humidityString = String(humidity, 0);
Serial.print("H: ");
Serial.print(humidityString);
Serial.print("%");
Serial.print(" ");
//Printing Pressure
Serial.print("P: ");
String pressureString = String(pressure, 0);
Serial.print(pressureString);
Serial.print(" hPa");
Serial.print(" ");
Serial.println();
}
float getTemperature()
{
temperature = bme.readTemperature();
}
float getHumidity()
{
humidity = bme.readHumidity();
}
float getPressure()
{
pressure = bme.readPressure();
pressure = bme.seaLevelForAltitude(ALTITUDE, pressure);
pressure = pressure / 100.0F;
//Webserver-Section
EthernetClient client = server.available();// check if client calls server
if (client) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 4"); // refresh the page automatically every 4 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<HEAD>");
client.println("<body>");
// for (int i=0; i <= 5; i++){client.println("
");} //align text vertically
client.println("<H1>");
client.println("<CENTER>");//align text horizontally
client.println(temperature, 1);
client.println("Grad Celsius");
client.println("
");
client.println(humidity, 0);
client.println("Prozent");
client.println("
");
client.println(pressure, 0);
client.println("Hectopascal");
//client.println("
");
client.println("</CENTER>");
client.println("</H1>");
client.println("</body>");
client.println("</html>");
delay(10); // wait to send data
client.stop();
} // stop connection with client
}
Maybe somebody has an idea how this could be done!!
Not me this time !