1

I've been setting up a system using an Arduino Uno board that reads from both an Adafruit MPU6050 6-way gyroscope and accelerometer and an Adafruit NAU7802 connected to a load sensor. I have code for that working, but I would also like to connect an Adafruit FeatherWing OLED to display the results.

Since this is the first time I've used Arduino or any of these parts, I first wrote a sketch to output the readings from my sensors into the serial monitor and a separate sketch to experiment with the display. However, when I try to use the code from the display sketch with my sensor reading script, it completely breaks the working sensor script.

My void setup code for my sensors looks like:

#include <Adafruit_MPU6050.h>
#include <Adafruit_NAU7802.h>

Adafruit_MPU6050 mpu;
Adafruit_NAU7802 nau;

void setup() {
  Serial.begin(115200);

  Serial.println("\n\nstart test\n");
  delay(10);

  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    } else {
      Serial.println("MPU6050 Found!");
    }
  if (!nau.begin()) {
    Serial.println("Failed to find NAU7802");
    } else {
      Serial.println("NAU7802 Found!");
    }

I then tried to add a few lines to power up the display:

#include <Wire.h> //for I2C
#include <Adafruit_MPU6050.h> //for 6-way
#include <Adafruit_NAU7802.h> //for ADC
#include <Adafruit_GFX.h> //for display
#include <Adafruit_SH110X.h> //for display

Adafruit_MPU6050 mpu;
Adafruit_NAU7802 nau;
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);

void setup() {
  Serial.begin(115200);

  Serial.println("\n\nstart test\n");

  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    } else {
      Serial.println("MPU6050 Found!");
    }
  if (!nau.begin()) {
    Serial.println("Failed to find NAU7802");
    } else {
      Serial.println("NAU7802 Found!");
    }
  
  delay(200); //allows OLED to power up
  display.begin(0x3C, true); // Address 0x3C default
  display.display();
  delay(1000);

  display.clearDisplay();
  display.display();
  
}

Does not turn on the display, but instead causes all of the code in the setup before the display.begin() function is called to loop indefinitely (even though it's not even in the loop part of the sketch.)

I have no idea what is going on here, and any advice would be appreciated! Thank you!

EDIT: Thank you so much for all of the comments! I will try to answer the questions as best as I can here.

I was only powering the device through the USB port. Based on your suggestions, I tried the script again using 9V through the barrel jack to power the device, but it, unfortunately, didn't fix the issue.

I tried reversing the dimensions in the Adafruit_SH1107(64, 128, &Wire) function, but that also didn't change anything. Also, all of my libraries are up to date as far as I can tell.

Both the OLED and the sensors successfully run independently while both are attached to the circuit. So -- I can get the OLED to display something while the sensors are attached to the circuit, and I can get the sensors to read into the serial monitor while the display is attached to the circuit. The problem arises when I try to have all of the parts called in the same script.

Here's a picture of the circuit: picture of an arduino connected to multiple small sensors, all taped to a cardboard tray

Thank you all again for your help!

5
  • 1
    setup() loops when the arduino is repeatedly resetting ... maybe the arduino has inadequate power
    – jsotola
    Commented Jun 9, 2023 at 15:34
  • 1
    Please show us your circuit and explain how you are powering everything
    – chrisl
    Commented Jun 9, 2023 at 18:29
  • Not sure this is related. but according to the Adafruit_SH110x library, the api for create an instance is Adafruit_SH1107(WIDTH, HEIGHT, &Wire), you seems to had it revered with width = 64, and height = 128 in Adafruit_SH1107(64, 128, &Wire).
    – hcheung
    Commented Jun 10, 2023 at 5:57
  • If the OLED was working independently then resetting the Arduino due to incorrect initialization (dimensions) is unlikely. The same can be said for using an outdated version of the Adafruit GFX library. Never the less, the Adafruit SH1107 driver does come w/this warning: "This library depends on Adafruit_GFX being present on your system. Please make sure you have installed the latest version before using this library.". Please double check these settings/configurations and update your Question if necessary.
    – st2000
    Commented Jun 10, 2023 at 13:42
  • Also, can you please clarify that you can run the sensors while the OLED hardware is installed but the OLED software is not in the Sketch? All these devices (OLED, Accelerometer & Stress Sensor) exist on your I2C bus. And several have independent pull up resistors. In a good hardware design there should only be 1 set up pull up resistors at the far end of the I2C bus. Having multiple higher resistance pull up resistors will likely work but there is an upper limit.
    – st2000
    Commented Jun 10, 2023 at 13:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.