this is a hint that the OLED-object can't work with variable-type "String" directly.
But there is a variant to transform variable-type String into a so called c_str-ring.
try
String myTestStr = "ABC";
Serial.println(myTestStr);
Oled.println(myTestStr.c_str() );
The variable type String is not well suited for RAM-limited microcontrollers.
There are some traps with Strings. Globally defined Strings eat up all memory over time and then the program will crash.
The alternatives are arrays of char (c-strings) or a library called SafeString wich you can install with the library-manager in the Arduino-IDE
Here is a demo-code how SafeStrings can be used
This demo-code has two debug-macros. Which reduce the the code you have to write to print to the serial monitor.
If you have questions about anything just ask
#define dbg(myFixedText, variableName) \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope
#define dbgi(myFixedText, variableName,timeInterval) \
do { \
static unsigned long intervalStartTime; \
if ( millis() - intervalStartTime >= timeInterval ){ \
intervalStartTime = millis(); \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName); \
} \
} while (false);
// usage: dbgi("2:my fixed text",myVar,myInterval);
// myVar can be any variable or expression that is defined in scope
// myInterval is the time-interval which must pass by before the next
// print is executed
#include <SafeString.h>
createSafeString(myDemo_SS, 32);
createSafeString(mySecondDemo_SS, 32);
unsigned long myCounter;
// if program starts printout the source-code filename etc. to the serial monitor
void PrintFileNameDateTime() {
Serial.println( F("Code running comes from file ") );
Serial.println(__FILE__);
Serial.print( F(" compiled ") );
Serial.print(__DATE__);
Serial.print( F(" ") );
Serial.println(__TIME__);
}
//useful function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &periodStartTime, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - periodStartTime >= TimePeriod )
{
periodStartTime = currentMillis; // set new expireTime
return true; // more time than TimePeriod) has elapsed since last time if-condition was true
}
else return false; // not expired
}
unsigned long MyTestTimer = 0; // variables MUST be of type unsigned long
const byte OnBoard_LED = 13; // Arduino-Uno Onboard-LED is IO-pin 13
// make onboard-LED blink to show: "program is running"
void BlinkHeartBeatLED(int IO_Pin, int BlinkPeriod) {
static unsigned long MyBlinkTimer;
pinMode(IO_Pin, OUTPUT);
if ( TimePeriodIsOver(MyBlinkTimer,BlinkPeriod) ) {
digitalWrite(IO_Pin,!digitalRead(IO_Pin) );
}
}
void setup() {
Serial.begin(115200);
Serial.println( F("Setup-Start") );
PrintFileNameDateTime();
myCounter = 0;
myDemo_SS = "Hello world!";
}
void loop() {
BlinkHeartBeatLED(OnBoard_LED,500);
myCounter++;
// loop is running very fast counting up very fast
// but only once every 1234 milliseconds print
if ( TimePeriodIsOver(MyTestTimer,1234) ) {
mySecondDemo_SS = myDemo_SS; // assigning a SafeString to another SafeString
mySecondDemo_SS += " "; // append a SPACE
mySecondDemo_SS += myCounter; // append integer-number
Serial.println(mySecondDemo_SS);
}
}
best regards Stefan