Project 9: Output Devices

This week was all about output devices. I made a OLED display to read out ADXL 343 accelerometer data.

...

Let's Start with the Group Project

The group project was to probe input devices for digital and analog signals.

...

Making the Breakout Board

I wanted to get a SSD1306 128x32 OLED Screen to read out my accelerometer data from last week. I started by playing around with the OLED Screen.

I ensured that I had the Adafruit_SSD1306 library and Adafruit_GFX library downloaded in the Arduino IDE.

I wired the SDA, SCL, ground, and power to my ESP 32c3 and ran the example sketch from the SSD1306 library corresponding to my screen (128x32). The video below shows all of the icons flashing in succession. I then used a bread board to see if I could get readings from a accelerometer (MPU6050) breakout board to the OLED screen. I connected the ground, power, SDA, and SCL of both to the ESP32c3.

...
I wrote the following script.

                                            #include 
                                                #include 
                                                #include 
                                                #include 
                                                #include 
                                                
                                                Adafruit_MPU6050 mpu;
                                                Adafruit_SSD1306 display(128, 32, &Wire);
                                                
                                                void setup(void) {
                                                  Serial.begin(115200);
                                                  while (!Serial) delay(10);
                                                
                                                  // Initialize MPU6050
                                                  if (!mpu.begin()) {
                                                    Serial.println("Failed to find MPU6050 chip");
                                                    while (1) delay(10);
                                                  }
                                                
                                                  // Initialize OLED display
                                                  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
                                                    Serial.println(F("SSD1306 allocation failed"));
                                                    while (1);
                                                  }
                                                  display.display();
                                                  delay(2000);  // Pause for 2 seconds
                                                
                                                  // Set up MPU6050 settings
                                                  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
                                                  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
                                                  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
                                                }
                                                
                                                void loop() {
                                                  sensors_event_t a, g, temp;
                                                  mpu.getEvent(&a, &g, &temp);
                                                
                                                  // Clear the display
                                                  display.clearDisplay();
                                                
                                                  // Display acceleration values
                                                  display.setTextSize(1);
                                                  display.setTextColor(SSD1306_WHITE);
                                                  display.setCursor(0, 0);
                                                  display.print("Accel X: "); display.print(a.acceleration.x); display.println(" m/s^2");
                                                  display.print("Accel Y: "); display.print(a.acceleration.y); display.println(" m/s^2");
                                                  display.print("Accel Z: "); display.print(a.acceleration.z); display.println(" m/s^2");
                                                
                                                  // Display rotation values
                                                  display.print("Gyro X: "); display.print(g.gyro.x); display.println(" rad/s");
                                                  display.print("Gyro Y: "); display.print(g.gyro.y); display.println(" rad/s");
                                                  display.print("Gyro Z: "); display.print(g.gyro.z); display.println(" rad/s");
                                                
                                                  // Display temperature
                                                  display.print("Temp: "); display.print(temp.temperature); display.println(" C");
                                                
                                                  // Update the display with the new data
                                                  display.display();
                                                
                                                  // Delay before next reading
                                                  delay(500);
                                                }
                                                
                                


It worked great. Check out the video below.

Now it was time to design my PCB. I used essentially the same design as last week's, but added some connectors for the OLED.
...


I milled out my design and soldered components. The 4 pin connector at the bottom gave my some trouble- the traces and pads started losing their adhesion and peeling up. I had to do a bit of board surgery.
...
...


I next ran the I2C scanner from last week. This should've indicated two separate I2C connections, which I had validated with the working breadboard setup above. Unfortunately, no I2C components were found.

I removed the OLED screen and had the same result-no connected I2C devices.

I resoldered the ADXL343 with a bit more solder paste and tried again. I added all the components and tried again. Still no I2C device.

I removed the OLED to see if my accelerometer was working. The scanner found the ADXL343. The problem had to be isolated to my OLED screen.
...
...


I then removed the OLED screen from the PCB and tried to use my board like a breakout board for the accelerometer. I used a breadboard to resolve traces that I no longer had.
...


I ran the I2C scanner and it was able to find both devices. This was exciting. I wrote a script to read out the sensortest example data to the OLED screen.

                                            #include 
                                                #include 
                                                #include 
                                                #include 
                                                #include 
                                                
                                                #define ADXL343_SCK 13
                                                #define ADXL343_MISO 12
                                                #define ADXL343_MOSI 11
                                                #define ADXL343_CS 10
                                                
                                                // Create an instance of the ADXL343 sensor
                                                Adafruit_ADXL343 accel = Adafruit_ADXL343(12345);
                                                
                                                // Define the OLED display (128x32)
                                                Adafruit_SSD1306 display(128, 32, &Wire, -1);
                                                
                                                void setup(void)
                                                {
                                                  Serial.begin(115200);
                                                  while (!Serial);
                                                  
                                                  // Initialize the OLED
                                                  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
                                                    Serial.println("SSD1306 allocation failed");
                                                    while (1);
                                                  }
                                                  display.clearDisplay();
                                                  
                                                  Serial.println("Accelerometer Test");
                                                  
                                                  // Initialize the sensor
                                                  if(!accel.begin()) {
                                                    Serial.println("Ooops, no ADXL343 detected ... Check your wiring!");
                                                    while(1);
                                                  }
                                                  
                                                  // Set the range for the accelerometer
                                                  accel.setRange(ADXL343_RANGE_16_G);
                                                  
                                                  // Display initial information on the OLED
                                                  display.setTextSize(1);      
                                                  display.setTextColor(SSD1306_WHITE);  
                                                  display.setCursor(0, 0);     
                                                  display.print("ADXL343 Sensor Initialized");
                                                  display.display();
                                                  delay(2000);
                                                  
                                                  display.clearDisplay();
                                                }
                                                
                                                void loop(void)
                                                {
                                                  // Get a new sensor event
                                                  sensors_event_t event;
                                                  accel.getEvent(&event);
                                                  
                                                  // Clear previous display data
                                                  display.clearDisplay();
                                                  
                                                  // Display the results on the OLED screen
                                                  display.setCursor(0, 0);
                                                  display.print("X: "); 
                                                  display.print(event.acceleration.x);
                                                  display.print(" m/s^2");
                                                  
                                                  display.setCursor(0, 10);
                                                  display.print("Y: "); 
                                                  display.print(event.acceleration.y);
                                                  display.print(" m/s^2");
                                                
                                                  display.setCursor(0, 20);
                                                  display.print("Z: "); 
                                                  display.print(event.acceleration.z);
                                                  display.print(" m/s^2");
                                                
                                                  display.display();
                                                  
                                                  delay(500);
                                                }
                                                
                                                
                                                
                                
This worked! I think it is because I had my traces from my OLED screen in the PCB routed to the pullup resistors from the ADXL 343, which may have interfered with things. Instead, I needed to route those traces directly to the Xiao.
...


I redid my traces in KiCAD accordingly.
...


Then I re-milled my board. And soldered on the components.
...


First, I tried the I2C scanner. I had an issue with the OLED. The scanner only found the accelerometer, not the OLED. With Leo's help and some multimeter use, we found that I had miswired SDA and SCL. It was time for some surgery.
...


I cut then crossed the SDA and SCL lines with additional wires.
...


I tried the scanner and now, it was recognizing both I2C devices.
...


Finally, I ran my script and was able to read out my accelerometer data to the OLED.
...


Heres's all my files for this week Week 9 Files