Raspberry Pico OLED Display Tutorial

See the Pico OLED build in Action!

Why Make This?
"Everyone dreams about it. One of the first gadgets we all dream of making is our own wristwatch...oh sorry...apparently, it's now a smartwatch...yeah. It's so smart it can form its own opinions, tuck you in and tell you your favorite bed time story, know intuitively when you are craving a martini with 2 rails of Spanish olives...
Wait...oh that's right, "smart" devices don't do any of that shit. Be careful! You wouldn't want to have to replace a cracked screen by accidentally bumping into the side of a toilet or falling off your bike in a Delaware street...
Who is going to remind you about your dentist appointment tomorrow at 10 am? Not your other device! Not Alexa, Not Siri, Not a piece of paper written by you and posted to the front door of your studio apartment!
FOCUS!
Hey, I understand. You just wanna make a little bing bing wahoo screen with colorful dancing lights so you can show your special someone.
You are so lucky to have me.
By the end of this tutorial you will understand how to hook the popular OLED display to your Pico and the code that runs it so you can know how to make changes; making you smarter than your friends.
It's time to BOSS UP!
CONCEPT
-
Turn ON Raspberry Pico
-
OLED displays some words or anime pics
-
Turn OFF Power: OLED Turns OFF

Electronic Components
There are 4 parts to this OLED Build:
-
The OLED Display
-
the Raspberry Pico
-
USB Cable
-
Dupont Wires
Software
-
Install Thonny: A lite and powerful code development IDE for Python that supports the PICO and micropython libraries are free to download!
The LDR Box Code for ATMEGA328P Chip
Study the //notes, Don't worry too much about the code.
Focus on how the Microchip does the job!
#include <avr/io.h> //Files we need to turn the pins on and off
#include <util/delay.h> //Files we need to make the chip wait some time
#include <avr/interrupt.h> //Files we need to make an interrupt trigger ( ISR )
#define noteDuration 8000 //How long we want the note to play for
//First We Set up the Rules for the Trigger
void interruptEnable(void) {
EIMSK |= (1 << INT0); //ISR enabled on INT0 pin which is PB0
EICRA |= (1 << ISC00); //triggers on any change in voltage
sei(); //enables global interrupts
}
/*Next we set up a Function to scan the amount of analog voltage coming in on our
pins connected to the analog to digital converter*/
uint16_t readADC(uint8_t channel) { /*ADC value will be a 10 bit number made of 2x 8 bit numbers from each ADC pin we can call "channel" */
ADMUX = (0xf0 & ADMUX) | channel; //Conversion process
ADCSRA |= (1 << ADSC); //Signal that it is busy doing conversion
loop_until_bit_is_clear(ADCSRA, ADSC); //Keep at it until the job is done and all clear is given
return(ADC); //give us that new digital value from that pin we scanned
}
/*The playNote function is confusing but you will better understand it if you play around with one value at a time*/
void playNote(uint16_t wavelength, uint16_t duration) { /*this is a function that will vibrate the
piezo speaker based on wavelength and duration*/
uint16_t elapsed; //to remember how much time has passed during each note
uint16_t i; //a counter
for (elapsed = 0; elapsed < duration; elapsed += wavelength) {
//This For Loop puts limits on the duration in order to create a wavelength
for (i = 0; i < wavelength; i++) { //This For loop with delay selects the pitch
_delay_us(1);
}
PORTB ^= (1 << PB1); //We alternate the pin on and off each loop to make it vibrate
}
}
uint8_t x; //Container for a value in our loop later
/*MAIN Staging Part of our code*/
int main(void) {
uint16_t adcValue0; //Like a container to hold our adcValue for later
interruptEnable(); //Tell the interrupt to get ready
DDRB |= (1 << PB1); //The speaker is connected to pin PB1 and it's negative leg to a capacitor which connects to the Ground of the chip
DDRC |= (1 << PC5); //Turns on the pin connected to one leg of the LDR sensor, it's other leg connects to the positive voltage of the chip
/*This is the loop of code the chip runs over and over and over*/
while(1) { //while the chip is running...
adcValue0 = readADC(5); /*set that adcValue container to hold the value that pops out from the
readADC function on ADC pin 5 (PC5) */
_delay_us(10); //wait 10 microseconds for it to complete
if (adcValue0 < 20) { //if the adc voltage value for the LDR is less than 20 then do...
//20 seems like a nice piercing pitch on our 8mhz chip (timing and speed changes sound)
for (x = 0; x < 50; x++) { //count up to 50 total but only add 1 each time through this loop
playNote(30, noteDuration); //using our playNote function for the wavelength and duration
PORTB ^= (1 << PB1); // Alternate the speaker pin on and off to make it vibrate during this process
}
}
else { //Otherwise...
PORTB &= ~(1 << PB1); //we keep the speak pin PB1 OFF and quiet
}
}
return (0); //This is just here, don't worry about it
}
Simple LDR Schematic

Terrible LDR Connection Sketch

UGLY LDR Soldered Concept
in 3d Printed Box

Yikes...I know. Concepts are always ugly.
You can make it prettier later with small improvements over time.
However you do it, stick to the schematic and you will be fine.
I flashed the program to my chip first.
If you want to see how to do all that you have to check out my Programming of this Atmega328P chip video that now has nearly 25,000 views!
Simple LDR Schematic
Now, let's take a look at the MUCH simpler Laser side!

Satisfying Laser Connection Sketch

UGLY Laser Soldered Concept
in 3d Printed Box
