i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by zep »

I'm trying to display ADS1015 A/D converter result on 128x32 OLED display. Both are Adafruit boards with default i2c addresses. I include header stuff from example sketch ssd1306_128x32_i2c example. I can print something on the display in setup() but the ADS1015 appears to be idle in loop(), no data returned, nothing to the display or serial monitor. I comment out all reference to the display and the ADS1015 runs just fine.
Should I expect no bus conflicts? Is there a fix?

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

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by dastels »

There doesn't seem to be an I2C address conflict between the two chips. Can you post your code?

Dave

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by zep »

Thank you. This demo sketch shows reading 256-element array sends readings to serial monitor OK but reading 512 elements causes hangup and reset. Something I'm doing or not doing with the 128x32 display is the cause. It appears the display is not releasing the bus at some point. Also maybe machine speed dependency effect.

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include <Adafruit_ADS1X15.h>
#include <Arduino.h>
Adafruit_ADS1015 ads;   

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

  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
  for(;;); // Don't proceed, loop forever
  }
  
  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(1000); 
  display.clearDisplay();
  display.display();
  
  display.setTextSize(1);    
  display.setTextColor(SSD1306_WHITE); 
 
  ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV (default)
  if (!ads.begin()) {
    Serial.println("Failed to initialize ADS.");
    while (1);
  }
}

void loop(void)
{ 
  int samples = 256; // runs OK with 256 samples but 512 samples causes reset and no data
  int ADarray[samples];
  int i;
   
  display.clearDisplay();
  display.display();
  display.setCursor(0, 5);    
  display.print("Filling array in loop");
  display.display();  
  delay(1000);
  
  //read array and send to serial monitor
  for (i = 0; i < samples; ++i){
    ADarray[i] = ads.readADC_Differential_0_1();
    Serial.print(i);Serial.print("  "); Serial.println(ADarray[i]);
  }
  Serial.println("  ");
  delay(1000);
}
Last edited by adafruit_support_bill on Tue Dec 28, 2021 8:50 am, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by adafruit_support_bill »

reading 256-element array sends readings to serial monitor OK but reading 512 elements causes hangup and reset.
Sounds like it could be a memory problem. What processor are you using?

https://learn.adafruit.com/memories-of- ... o-memories

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by zep »

Sysinfo attached. But I get all 512 readings if I remove references to the display.
Attachments
Sysinfo.JPG
Sysinfo.JPG (79.36 KiB) Viewed 257 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by adafruit_support_bill »

What kind of arduino processor are you using? OLED displays take a lot of memory for the frame buffer. If you are running on something like an UNO, you won't have much memory left over for your sample array.

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by zep »

I'm using a Nano. Maybe I can just live with it if display code change won't fix.

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

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by dastels »

Try allocating the array outside of loop(). There may be a limit on how much will fit on the stack. or it could just be an overall RAM limit. You only have 2K on a Nano. I believe ints on the '328 are 16-bit, so each one takes 2 bytes. An array of 256 will take 512 bytes, an array of 512 will take 1K. I expect the requires of GFX and the display system are not insignificant. So, yes, you're probably just running out of memory.

Dave

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by adafruit_support_bill »

The 128x32 display will take 512 bytes for the frame buffer. Plus a bit of overhead for other variables and stack in the library. Added to the 1K for your sample array and the memory requirements of the ADS1x15 library, that is more than 1.5K of dynamic memory used by your program.

The Arduino system itself needs a bit of dynamic memory as well. In my experience running Arduino code on those processors, it is best to leave at least 512 bytes for the system to do its thing.

https://learn.adafruit.com/memories-of- ... o-memories

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: i2c bus conflict, ADS1015 and 128x32 Monochrome OLED

Post by zep »

OK thanks guys for the help. At least that gives me some options.

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

Return to “Arduino Shields from Adafruit”