Hello!
I am currently working on a project to print a .txt file to an Arduino using the Serial COM port. In windows I configured a Generic/Text printer which prints ASCII values to a specific COM port.
When I try to print the .txt file, it sends ASCII values (decimal) to the Serial port and the Arduino reads it without a problem.
Now I would like to convert the decimal ASCII values to strings or characters so I can output a text on my OLED screen.
My code looks like this:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET LED_BUILTIN // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 20 // Number of snowflakes in the animation example
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000
};
int incoming;
void setup() {
Serial.begin(9600);
// by default, we'll generate the high voltage from the 5v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
// Show image buffer on the display hardware.
display.display();
//delay(2000);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 0);
display.clearDisplay();
display.println("READY");
// invert the display
display.invertDisplay(true);
//delay(1000);
display.invertDisplay(false);
//delay(1000);
display.display();
//delay(2000);
display.clearDisplay();
}
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
incoming = Serial.read();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 0);
display.clearDisplay();
display.print("I received: ");
display.println(mysrr);
display.display();
}
delay (500);
}
The output of this code on my OLED screen is:
"I recieved: 10" and the decimal number changes to other decimal numbers every 0,5 second until the .txt is done printing characters.
My question:
Can someone help me to write an ASCII decimal to text converter so I can print "Test" through the Serial port and have my OLED say "Test" in stead of decimal numbers?
Thanks in advance!