Metro mini v2 and multiple stemma/I2C

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
idarlund
 
Posts: 46
Joined: Fri Sep 16, 2022 4:57 pm

Metro mini v2 and multiple stemma/I2C

Post by idarlund »

Hi,

I've connected a Metro Mini v2 (https://www.adafruit.com/product/5597) with a FeatherWing OLED (https://learn.adafruit.com/adafruit-128 ... g/overview) over STEMMA QT (I2C). When also connecting an Adafruit Mini GPS PA1010D Module (https://learn.adafruit.com/adafruit-min ... e/overview) over the same I2C it seems I'm only able to connect to one of the I2C devices and not both at the same time, despite they having different addresses.

Here's my connection:
PXL_20220929_140131661.jpg
PXL_20220929_140131661.jpg (110.32 KiB) Viewed 157 times
Here's my code (when uncommenting "Adafruit_GPS GPS(&Wire);" and "GPS.begin(0x10);" the connection to the I2C is no longer working):

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_GPS.h>

// Connect to the OLED on the hardware I2C port
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);

// Connect to the GPS on the hardware I2C port
// Adafruit_GPS GPS(&Wire);

#define BUTTON_UP  9
#define BUTTON_ENTER  8
#define BUTTON_DOWN  7
#define BUTTON_BACK  6


void setup() {
  // wait for hardware serial to appear
  while (!Serial);

  Serial.begin(115200);

  Serial.println("Connecting to OLED");
  display.begin(0x3C, true); // Address 0x3C default
  display.display(); // show splash-screen
  delay(2000);
  display.setRotation(3); // set correct rotation
  display.setTextSize(1); // set correct text size
  display.setTextColor(SH110X_WHITE); // set correct text color
  display.setCursor(0,0); // start at 0,0 coordinates
  display.clearDisplay(); // Remove splash-screen
  delay(1000);
  Serial.println("Connected to OLED");
  display.println("Connected to OLED");
  display.display();
  delay(1000);

  Serial.println("Connecting to GPS");
  display.println("Connecting to GPS");
  display.display();
//  GPS.begin(0x10);  // Address 0x10 default
  delay(1000); // wait for the GPS to power up - probably not necessary
  
  Serial.println("Completed");
  display.println("Completed");
  display.display();
  delay(1000);

  Serial.println("Setting up buttons");
  display.println("Setting up buttons");
  display.display();
  delay(1000);
  
  pinMode(BUTTON_UP, INPUT_PULLUP);
  pinMode(BUTTON_ENTER, INPUT_PULLUP);
  pinMode(BUTTON_DOWN, INPUT_PULLUP);
  pinMode(BUTTON_BACK, INPUT_PULLUP);

  Serial.println("Completed");
  display.println("Completed");
  display.display();
  delay(1000);

}

void loop() {
  
//  if (Serial.available()) {
//    char c = Serial.read();
//    GPS.write(c);
//  }
//  if (GPS.available()) {
//    char c = GPS.read();
//    Serial.write(c);
//  }
  
  if(!digitalRead(BUTTON_UP)) display.print("C");
  if(!digitalRead(BUTTON_ENTER)) display.print("B");
  if(!digitalRead(BUTTON_DOWN)) display.print("A");
  if(!digitalRead(BUTTON_BACK)) display.print("D");
  delay(10);
  yield();
  display.display();
}
What am I doing wrong?

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Metro mini v2 and multiple stemma/I2C

Post by dastels »

Does the GPS work on it's own, without the display?

Have you tried these two with a more capable MCU board? The ATmega328 only has 2K of RAM.
What are the RAM usage stats at the end of the build output?

Dave

User avatar
idarlund
 
Posts: 46
Joined: Fri Sep 16, 2022 4:57 pm

Re: Metro mini v2 and multiple stemma/I2C

Post by idarlund »

Thanks for your reply!

No, I have not tried other boards. I've got a 2560 and M0 feather. I could try those out.

Yes, the GPS works on it's own with the same cabeling.

With both:
Sketch uses 15152 bytes (52%) of program storage space. Maximum is 28672 bytes.
Global variables use 1378 bytes (67%) of dynamic memory, leaving 670 bytes for local variables. Maximum is 2048 bytes.
With only display:
Sketch uses 13584 bytes (47%) of program storage space. Maximum is 28672 bytes.
Global variables use 688 bytes (33%) of dynamic memory, leaving 1360 bytes for local variables. Maximum is 2048 bytes.
With only gps:
Sketch uses 7570 bytes (26%) of program storage space. Maximum is 28672 bytes.
Global variables use 1199 bytes (58%) of dynamic memory, leaving 849 bytes for local variables. Maximum is 2048 bytes.
For reference, here's the code with "only gps":

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_GPS.h>

// Set I2C bus to use: Wire, Wire1, etc.
// #define WIRE Wire


// Connect to the OLED on the hardware I2C port
// Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);

// Connect to the GPS on the hardware I2C port
Adafruit_GPS GPS(&Wire);

#define BUTTON_UP  9
#define BUTTON_ENTER  8
#define BUTTON_DOWN  7
#define BUTTON_BACK  6


void setup() {
  // wait for hardware serial to appear
  while (!Serial);

  // make this baud rate fast enough to we aren't waiting on it
  Serial.begin(115200);

  Serial.println("Connecting to OLED");
//  display.begin(0x3C, true); // Address 0x3C default
//  display.display(); // show splashscreen
  delay(2000);
//  display.setRotation(3); // set correct rotation
//  display.setTextSize(1); // set correct text size
//  display.setTextColor(SH110X_WHITE); // set correct text color
//  display.setCursor(0,0); // start at 0,0 coordinates
//  display.clearDisplay(); // Remove splashscreen
  delay(1000);
  Serial.println("Connected to OLED");
//  display.println("Connected to OLED");
//  display.display();
  delay(1000);

  Serial.println("Connecting to GPS");
//  display.println("Connecting to GPS");
//  display.display();
  GPS.begin(0x10);  // Address 0x10 default
  delay(1000); // wait for the GPS to power up - probably not necessary
  
  Serial.println("Completed");
//  display.println("Completed");
//  display.display();
  delay(1000);

  Serial.println("Setting up buttons");
//  display.println("Setting up buttons");
//  display.display();
  delay(1000);
  
  pinMode(BUTTON_UP, INPUT_PULLUP);
  pinMode(BUTTON_ENTER, INPUT_PULLUP);
  pinMode(BUTTON_DOWN, INPUT_PULLUP);
  pinMode(BUTTON_BACK, INPUT_PULLUP);

  Serial.println("Completed");
//  display.println("Completed");
//  display.display();
  delay(1000);

}

void loop() {
  
  if (Serial.available()) {
    char c = Serial.read();
    GPS.write(c);
  }
  if (GPS.available()) {
    char c = GPS.read();
    Serial.write(c);
  }
  
//  if(!digitalRead(BUTTON_UP)) display.print("C");
//  if(!digitalRead(BUTTON_ENTER)) display.print("B");
//  if(!digitalRead(BUTTON_DOWN)) display.print("A");
//  if(!digitalRead(BUTTON_BACK)) display.print("D");
  delay(10);
  yield();
//  display.display();
}

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Metro mini v2 and multiple stemma/I2C

Post by dastels »

My current thought is that the memory dynamically allocated required by them together is more than is available.

Working on either of your other boards will prove that.

Dave

User avatar
idarlund
 
Posts: 46
Joined: Fri Sep 16, 2022 4:57 pm

Re: Metro mini v2 and multiple stemma/I2C

Post by idarlund »

Thanks for your help so far! It might be too little RAM, but when testing it out on my M0 I can't get the display to work at all, even alone.. 😅 Connected it back to the Metro Mini just to check if I ruined my OLED, and it thankfully it still works.

Created a separate thread for this so it's easier to find solutions if anyone are googleing similar issues viewtopic.php?t=194814

User avatar
idarlund
 
Posts: 46
Joined: Fri Sep 16, 2022 4:57 pm

Re: Metro mini v2 and multiple stemma/I2C

Post by idarlund »

I have confirmed that the Metro mini v2 is not working with the OLED and the GPS at the same time. Most likely due to available RAM.

This thread can be closed with the solution to change to a board with more RAM :)

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”