For this week, I decided to do the OLED lab for the I2C lab and the Playing WAV file for the SPI lab.
OLED Screen Display using I2C
Firstly, I put together the circuit wiring with the OLED and the potentiometer. To get the OLED to work, I had to import the Adafruit OLED model library and the GFX library, and then initialize the screen.
Next, I imported a font library and changed the text size using the display.setFont() function in Arduino code. On the picture to the left, you can see that the text for “sensor” is a lot bigger than it was before.
I also tried out Richard Moore’s QR code library by downloading it in the QR code manager. I used the code provided from the lab page to use the string I sent into Serial to generate a QR code, and it created a lovely QR graphic to display on the OLED.
This is what I sent through the Serial Monitor. When I scanned the QR code, it sent me to “hi this is my message” on my browser.
Lab: Playing .WAV Files from an Arduino using I2S and SPI
For the sound lab, I checked out a micro SD Card reader, audio breakout board and an I2S amplifier from the shop. I borrowed a microSD from a friend and loaded my favorite doja cat song onto it as a .wav file. Then, I plugged my hardware onto the breadboard using the following connections:
SD Card Reader
Vcc – voltage in. Connects to microcontroller voltage out
CS – Chip select. Connects to microcontroller CS (pin D10 on the Nano/Uno)
DI – SPI data in. Connects to microcontroller SDO (pin D11 on the Nano/Uno)
SCK – SPI clock.. Connects to microcontroller SCLK (pin D13 on the Nano/Uno)
DO – SPI data out. Connects to microcontroller SDI (pin D12 on the Nano/Uno)
CD – card detect. Not connected in this example
GND – ground. Connects to microcontroller ground
Amplifier
BCLK connects to A3 of the Nano 33 IoT board
LRC connects to A2 of the Nano 33 IoT board
DIN connects to D4 (SDA Pin) of the Nano 33 IoT board
Vin connects to 3.3V
GND connects to ground
+ connects to the left and right sides of a 3.5mm audio jack
– connects to the center pin of a 3.5mm audio jack
Next, I loaded in the code provided from the lab into the microcontroller. When running it, I couldn’t figure out why the SD card wasn’t initializing at first. Then, I realized I forgot to connect the SD card to power and ground.
The picture on the left is the correct wiring! The audio jack plug is the black attachment at the bottom of the breadboard. I tried plugging in my earbuds and couldn’t hear anything… The Serial monitor said the SD card and .wav file were valid and the file was playing, but no sound was coming out, and I couldn’t figure out why. Doja cat and I weren’t meant to be today.