9. Output Devices¶
For this week I worked on usesing an OLED screen with the board I prodced last week. For group I helped messure the power consumption.
Arduino Test¶
Knowing the OLED had I2C I wanted to test it using the Arduino Uno. I didn’t know where to start on coding the OLED so I asked ChatGPT for help. I asked ChatGPT to create a code that just said my name and asked it what pins I needed. Heres the code it gave me:
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10,20);
display.println("Jed Smith");
display.display();
}
void loop() {
// Nothing to do here
}
ChatGPT also told me the pins I needed. The OLED display uses GND, VCC, SCL, and SDA. SCL = Serial Clock Pin. And SDA = Serial Data Pin.
Using the Arduino Uno pinouts you can see here:
I wired the my Arduino Uno to the OLED Display. I then ran the code in the Arduino IDE and it worked first time and this is what that looked like:
Xiao OLED¶
After I got the OLED working on the Arduino Uno I then went to get it working on the Seeed Xiao Rp2040. Using these Pinouts for the Xiao:
And the board I milled for electronics production. I uploaded the code to the Xiao through the Arduino IDE and it worked first try:
I then wanted to try to understand the code a little more so I started changing small aspectd of the code to try and see what would change.
Moving the text around¶
I learned the line display.setCursor(10,20);
is where on the OLED the text was positioned. I changed the line of code to display.setCursor(5,30);
and it moved to this:
Changing what the text says¶
I think its pretty obvious but the line display.println("Jed Smith");
is the text thats displayed on the OLED.
Changing text size¶
Again this one is pretty obvious, line display.setTextSize(2);
, I changed the number to 5 and this is what that looked like:
Changing Color¶
The line to do this is display.setTextColor(SSD1206_WHITE);
, I tried changing the color and I got an error message that said “ ‘SSD1306_GREEN` was not declared in this scope. But after asking chatgpt it said that most likely meant the library wasnt installed properly, I then re-installed the library and nothing changed so I don’t know how I would change the color.
What I Learned¶
This week I learned how to use an OLED display and how to manipulate the OLED code to change what the display looks like. This was helpful because I will use an OLED in my final project.