Trying to read a text field from my Thingspeak channel (text) and display it using arduino giga display shield.
Show older comments
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.
2 Comments
Christopher Stapels
on 10 Feb 2026 at 0:39
Edited: Christopher Stapels
on 10 Feb 2026 at 0:40
It would be easier on the API for you to use ThingSpeak.readMultipleFields(channelNumber, readAPIKey) to get multiple fields in one shot. See this example for code.
Then you arent sending a burst of seven seperate requests to the server in a few miliseconds.
By the fourth line, I think you mean
display.print("Data Last Reported");
display.setCursor(200, 390); // Adjusted for rotated display
display.print(textData);
which comes from this
String textData = ThingSpeak.readStringField(lakeChannelID,7, lakeReadAPI);
I suggest you use the created at timestamp, unless things get stored in your channel at a different time than when they were measured.
String createdAt = ThingSpeak.getCreatedAt(); // Created-at timestamp
Otherwise Im afraid field 7 doesnt have the data you think it does ( hence the -1) If you share your channelid (and its public), I could take a look a the data. and try to help. I understand if the channel is private that you might not want to share.
Arlian
on 10 Feb 2026 at 1:10
Answers (0)
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Prepare and Analyze Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!