I have an I2C OLED connected to my Arduino Uno and I have used it to display integers in past projects, but I would like to know how to place quotes around a variable (in this case Serial.read() ). My current solution displays strange characters around the text on the OLED, but if I use a constant non-changing variable the OLED doesn't spit out a garbage character. Here's my code:
#include <Arduino.h>;
#include <U8x8lib.h>;
int breakout = 0; // Set to 1 if you have broken out the OLED Module.
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
// U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the Display
String serialData;
void setup() {
Serial.begin(9600);
if(breakout = 1){
u8x8.setBusClock(100000); // Enabled when breakout is set to 1
}
u8x8.begin();
u8x8.setFlipMode(1);
}
void loop(void) {
u8x8.setFont(u8x8_font_amstrad_cpc_extended_f);
u8x8.setCursor(0, 0);
if(Serial.available() > 0){
serialData = Serial.readString();
String Data;
Data = "\"" + serialData + "\""; // CURRENT SOLUTION
u8x8.clear();
u8x8.setFont(u8x8_font_amstrad_cpc_extended_f);
u8x8.setCursor(0, 0);
u8x8.print(Data);
}
}
I am trying to figure out how to place quotes around the serial result, and currently it’s still broken, so I don’t completely consider this solved yet.
serialData has a line ending. You need to configure your serial monitor not to send a line ending or use Serial.readStringUntil() to read until the line ending. That is why the ending quote appears on the second line.
Did you fix this line as AWOL indicated in reply #4?