Trying to read a text field from my Thingspeak channel (text) and display it using arduino giga display shield.
Matlab Visualization Code (works properly)
My first 3 lines of information display properly on my giga display shield.
The 4th line which is supposed to be a timestamp stored in my field as text (ex:
Displays as -1, not the text timestamp I am looking for. Any help is appreciated.
% Read the last entry and its timestamp
[data, timestamps] = thingSpeakRead(x, ‘NumPoints’, 1);
% Add a timezone offset of 5 hours
localTime = timestamps – hours(5);
% Display the local timestamp as text
text(0.5, 0.5, datestr(localTime), ‘FontSize’, 20, ‘HorizontalAlignment’, ‘center’);
axis off;
Note – sensitive info replaced with X
Arduino code
#include <WiFi.h> //library for connecting to WiFi
#include <ThingSpeak.h> //library for reading data from ThingSpeak
#include "Arduino_GigaDisplay_GFX.h" //library for using the GigaDisplay shield
//define WiFi credentials
const char* ssid = "x";
const char* password = "x";
WiFiClient client;
String textData = "";
//define ThingSpeak channel IDs and read APIs
unsigned long lakeChannelID = x;
const char* lakeReadAPI = "x";
//define GigaDisplay object
GigaDisplay_GFX display;
#define BLACK 0x0000
#define WHITE 0xFFFF
#define NEW 0xFF6B35
void setup() {
//initialize serial communication for debugging
Serial.begin(9600);
//connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi…");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
ThingSpeak.begin(client); // Initialize ThingSpeak
display.begin();
}
void loop() {
float homeTemp = ThingSpeak.readFloatField(lakeChannelID, 8, lakeReadAPI);
float lakeTemp1 = ThingSpeak.readFloatField(lakeChannelID, 1, lakeReadAPI);
float lakeTemp2 = ThingSpeak.readFloatField(lakeChannelID, 2, lakeReadAPI);
float lakeTemp3 = ThingSpeak.readFloatField(lakeChannelID, 3, lakeReadAPI);
float lakeTemp4 = ThingSpeak.readFloatField(lakeChannelID, 4, lakeReadAPI);
float lakeTemp5 = ThingSpeak.readFloatField(lakeChannelID, 5, lakeReadAPI);
float lakeTemp6 = ThingSpeak.readFloatField(lakeChannelID, 6, lakeReadAPI);
String textData = ThingSpeak.readStringField(lakeChannelID,7, lakeReadAPI);
float lakeTempOutAvg = (lakeTemp1 + lakeTemp2 + lakeTemp3)/3;
float lakeTempUnderAvg = (lakeTemp4 + lakeTemp5 + lakeTemp6)/3;
long statuscode = ThingSpeak.getLastReadStatus();
if (statuscode == 200)
{
//print temperature data to serial monitor for debugging
Serial.print("Home Outside Temp: ");
Serial.println(homeTemp);
Serial.print("Lake Outside Temp: ");
Serial.println(lakeTemp1);
Serial.print("Lake Outside Average: ");
Serial.println(lakeTempOutAvg);
Serial.print("Lake Under Average: ");
Serial.println(lakeTempUnderAvg);
Serial.print("Last Read: ");
Serial.println(textData);
//clear display and set cursor to top left corner
display.setRotation(1); // -90 degrees rotation
display.fillScreen(BLACK);
display.setTextColor(NEW);
display.setTextSize( 5);
display.setCursor(50, 10); // Adjusted for rotated display
display.print("Home Outdoors");
display.setCursor(200, 60); // Adjusted for rotated display
display.print(homeTemp, 1);
display.print(" F");
display.setCursor(50, 120); // Adjusted for rotated display
display.print("Lake Outdoors");
display.setCursor(200, 170); // Adjusted for rotated display
display.print(lakeTempOutAvg, 1);
display.print(" F");
display.setCursor(50, 230); // Adjusted for rotated display
display.print("Lake Under House");
display.setCursor(200, 280); // Adjusted for rotated display
display.print(lakeTempUnderAvg, 1);
display.print(" F");
display.setCursor(50, 340); // Adjusted for rotated display
display.print("Data Last Reported");
display.setCursor(200, 390); // Adjusted for rotated display
display.print(textData);
//wait for 10 seconds before updating again
delay(10000);
}
}
//Code sourced from ThingSpeak and GigaDisplay libraries.Matlab Visualization Code (works properly)
My first 3 lines of information display properly on my giga display shield.
The 4th line which is supposed to be a timestamp stored in my field as text (ex:
Displays as -1, not the text timestamp I am looking for. Any help is appreciated.
% Read the last entry and its timestamp
[data, timestamps] = thingSpeakRead(x, ‘NumPoints’, 1);
% Add a timezone offset of 5 hours
localTime = timestamps – hours(5);
% Display the local timestamp as text
text(0.5, 0.5, datestr(localTime), ‘FontSize’, 20, ‘HorizontalAlignment’, ‘center’);
axis off;
Note – sensitive info replaced with X
Arduino code
#include <WiFi.h> //library for connecting to WiFi
#include <ThingSpeak.h> //library for reading data from ThingSpeak
#include "Arduino_GigaDisplay_GFX.h" //library for using the GigaDisplay shield
//define WiFi credentials
const char* ssid = "x";
const char* password = "x";
WiFiClient client;
String textData = "";
//define ThingSpeak channel IDs and read APIs
unsigned long lakeChannelID = x;
const char* lakeReadAPI = "x";
//define GigaDisplay object
GigaDisplay_GFX display;
#define BLACK 0x0000
#define WHITE 0xFFFF
#define NEW 0xFF6B35
void setup() {
//initialize serial communication for debugging
Serial.begin(9600);
//connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi…");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
ThingSpeak.begin(client); // Initialize ThingSpeak
display.begin();
}
void loop() {
float homeTemp = ThingSpeak.readFloatField(lakeChannelID, 8, lakeReadAPI);
float lakeTemp1 = ThingSpeak.readFloatField(lakeChannelID, 1, lakeReadAPI);
float lakeTemp2 = ThingSpeak.readFloatField(lakeChannelID, 2, lakeReadAPI);
float lakeTemp3 = ThingSpeak.readFloatField(lakeChannelID, 3, lakeReadAPI);
float lakeTemp4 = ThingSpeak.readFloatField(lakeChannelID, 4, lakeReadAPI);
float lakeTemp5 = ThingSpeak.readFloatField(lakeChannelID, 5, lakeReadAPI);
float lakeTemp6 = ThingSpeak.readFloatField(lakeChannelID, 6, lakeReadAPI);
String textData = ThingSpeak.readStringField(lakeChannelID,7, lakeReadAPI);
float lakeTempOutAvg = (lakeTemp1 + lakeTemp2 + lakeTemp3)/3;
float lakeTempUnderAvg = (lakeTemp4 + lakeTemp5 + lakeTemp6)/3;
long statuscode = ThingSpeak.getLastReadStatus();
if (statuscode == 200)
{
//print temperature data to serial monitor for debugging
Serial.print("Home Outside Temp: ");
Serial.println(homeTemp);
Serial.print("Lake Outside Temp: ");
Serial.println(lakeTemp1);
Serial.print("Lake Outside Average: ");
Serial.println(lakeTempOutAvg);
Serial.print("Lake Under Average: ");
Serial.println(lakeTempUnderAvg);
Serial.print("Last Read: ");
Serial.println(textData);
//clear display and set cursor to top left corner
display.setRotation(1); // -90 degrees rotation
display.fillScreen(BLACK);
display.setTextColor(NEW);
display.setTextSize( 5);
display.setCursor(50, 10); // Adjusted for rotated display
display.print("Home Outdoors");
display.setCursor(200, 60); // Adjusted for rotated display
display.print(homeTemp, 1);
display.print(" F");
display.setCursor(50, 120); // Adjusted for rotated display
display.print("Lake Outdoors");
display.setCursor(200, 170); // Adjusted for rotated display
display.print(lakeTempOutAvg, 1);
display.print(" F");
display.setCursor(50, 230); // Adjusted for rotated display
display.print("Lake Under House");
display.setCursor(200, 280); // Adjusted for rotated display
display.print(lakeTempUnderAvg, 1);
display.print(" F");
display.setCursor(50, 340); // Adjusted for rotated display
display.print("Data Last Reported");
display.setCursor(200, 390); // Adjusted for rotated display
display.print(textData);
//wait for 10 seconds before updating again
delay(10000);
}
}
//Code sourced from ThingSpeak and GigaDisplay libraries. Matlab Visualization Code (works properly)
My first 3 lines of information display properly on my giga display shield.
The 4th line which is supposed to be a timestamp stored in my field as text (ex:
Displays as -1, not the text timestamp I am looking for. Any help is appreciated.
% Read the last entry and its timestamp
[data, timestamps] = thingSpeakRead(x, ‘NumPoints’, 1);
% Add a timezone offset of 5 hours
localTime = timestamps – hours(5);
% Display the local timestamp as text
text(0.5, 0.5, datestr(localTime), ‘FontSize’, 20, ‘HorizontalAlignment’, ‘center’);
axis off;
Note – sensitive info replaced with X
Arduino code
#include <WiFi.h> //library for connecting to WiFi
#include <ThingSpeak.h> //library for reading data from ThingSpeak
#include "Arduino_GigaDisplay_GFX.h" //library for using the GigaDisplay shield
//define WiFi credentials
const char* ssid = "x";
const char* password = "x";
WiFiClient client;
String textData = "";
//define ThingSpeak channel IDs and read APIs
unsigned long lakeChannelID = x;
const char* lakeReadAPI = "x";
//define GigaDisplay object
GigaDisplay_GFX display;
#define BLACK 0x0000
#define WHITE 0xFFFF
#define NEW 0xFF6B35
void setup() {
//initialize serial communication for debugging
Serial.begin(9600);
//connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi…");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
ThingSpeak.begin(client); // Initialize ThingSpeak
display.begin();
}
void loop() {
float homeTemp = ThingSpeak.readFloatField(lakeChannelID, 8, lakeReadAPI);
float lakeTemp1 = ThingSpeak.readFloatField(lakeChannelID, 1, lakeReadAPI);
float lakeTemp2 = ThingSpeak.readFloatField(lakeChannelID, 2, lakeReadAPI);
float lakeTemp3 = ThingSpeak.readFloatField(lakeChannelID, 3, lakeReadAPI);
float lakeTemp4 = ThingSpeak.readFloatField(lakeChannelID, 4, lakeReadAPI);
float lakeTemp5 = ThingSpeak.readFloatField(lakeChannelID, 5, lakeReadAPI);
float lakeTemp6 = ThingSpeak.readFloatField(lakeChannelID, 6, lakeReadAPI);
String textData = ThingSpeak.readStringField(lakeChannelID,7, lakeReadAPI);
float lakeTempOutAvg = (lakeTemp1 + lakeTemp2 + lakeTemp3)/3;
float lakeTempUnderAvg = (lakeTemp4 + lakeTemp5 + lakeTemp6)/3;
long statuscode = ThingSpeak.getLastReadStatus();
if (statuscode == 200)
{
//print temperature data to serial monitor for debugging
Serial.print("Home Outside Temp: ");
Serial.println(homeTemp);
Serial.print("Lake Outside Temp: ");
Serial.println(lakeTemp1);
Serial.print("Lake Outside Average: ");
Serial.println(lakeTempOutAvg);
Serial.print("Lake Under Average: ");
Serial.println(lakeTempUnderAvg);
Serial.print("Last Read: ");
Serial.println(textData);
//clear display and set cursor to top left corner
display.setRotation(1); // -90 degrees rotation
display.fillScreen(BLACK);
display.setTextColor(NEW);
display.setTextSize( 5);
display.setCursor(50, 10); // Adjusted for rotated display
display.print("Home Outdoors");
display.setCursor(200, 60); // Adjusted for rotated display
display.print(homeTemp, 1);
display.print(" F");
display.setCursor(50, 120); // Adjusted for rotated display
display.print("Lake Outdoors");
display.setCursor(200, 170); // Adjusted for rotated display
display.print(lakeTempOutAvg, 1);
display.print(" F");
display.setCursor(50, 230); // Adjusted for rotated display
display.print("Lake Under House");
display.setCursor(200, 280); // Adjusted for rotated display
display.print(lakeTempUnderAvg, 1);
display.print(" F");
display.setCursor(50, 340); // Adjusted for rotated display
display.print("Data Last Reported");
display.setCursor(200, 390); // Adjusted for rotated display
display.print(textData);
//wait for 10 seconds before updating again
delay(10000);
}
}
//Code sourced from ThingSpeak and GigaDisplay libraries. thingspeak, arduino MATLAB Answers — New Questions









