Arduino micro I2C issues


Ok my Arduino micro is giving me a trying time, and I hope someone can assist.

I have the ADS1115 module hooked up to the I2C port (2&3) and using Nick Gammons I2C_scanner works fine. I get an address returned via USB serial 0x48 i think it was.

When I try to move on to another example, the Adafruit ADS1X15 single ended for example, i get nada, nothing, zero out of the serial port (usb - COM12).

I change no wiring between code changes. (+5, GND, SDA, SCL all left alone)

What am I doing wrong with this beast?


Maybe one of the modules doesn't have pull-ups.
What if you connect both at the same time?

Only one module. Do you mean pull-ups on the i2c lines?

Of course I2C pull-ups.

What happens if you connect both modules at the same time?

Both modules meaning what? I only have 1x ADS1115 and one Arduino Micro.

Ah! Code example, not module example.


I don't have that code.

No worries ex-AWOL, tried pullups, no difference.

Post your code.
Where in code did you change the I2C address?

Did you change these lines

//Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
Adafruit_ADS1015 ads;     /* Use this for the 12-bit version */

Do you get the Hello! message?

Yes, commented out ADS1015 and uncommented ADS1115.

I do not get the hello message even.

Nowhere to change the I2C address that I can see.

#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
//Adafruit_ADS1015 ads;     /* Use this for the 12-bit version */

void setup() 
  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
  // The ADC input range (or gain) can be changed via the following
  // functions, but be careful never to exceed VDD +0.3V max, or to
  // exceed the upper and lower limits if you adjust the input range!
  // Setting these values incorrectly may destroy your ADC!
  //                                                                ADS1015  ADS1115
  //                                                                -------  -------
   ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV (default)
  // ads.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV
  // ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 1mV      0.0625mV
  // ads.setGain(GAIN_FOUR);       // 4x gain   +/- 1.024V  1 bit = 0.5mV    0.03125mV
  // ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.25mV   0.015625mV
  // ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV

void loop() 
  int16_t adc0, adc1, adc2, adc3;
  float volts0, volts1, volts2, volts3;

  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);

  volts0 = ads.computeVolts(adc0);
  volts1 = ads.computeVolts(adc1);
  volts2 = ads.computeVolts(adc2);
  volts3 = ads.computeVolts(adc3);

  Serial.print("AIN0: "); Serial.print(adc0); Serial.print("  "); Serial.print(volts0); Serial.println("V");
  Serial.print("AIN1: "); Serial.print(adc1); Serial.print("  "); Serial.print(volts1); Serial.println("V");
  Serial.print("AIN2: "); Serial.print(adc2); Serial.print("  "); Serial.print(volts2); Serial.println("V");
  Serial.print("AIN3: "); Serial.print(adc3); Serial.print("  "); Serial.print(volts3); Serial.println("V");


Figured it out guys, have to add the I2C address to the following line


Who knew the program would not execute in order i.e. serial prints before ads.begin...


If you look at void setup, serial prints happen before ads.begin, however ads.begin needs to have the correct address for the AD module, then the serial prints work.
I thought things happened line-by-line in the arduino universe...

No, you've misread the situation.
The prints simply cause characters to be written to a buffer, to be printed at a later time.
The mechanism that prints them is dependent upon interrupts, which if disabled will prevent prints.
If whatever is causing your I2C to fail is also preventing interrupts then you won't see your prints.
A delay after the prints, or a flush should show how this works.

If you look at your setup()
In sequence.
You set the baud at 9600
Print text line of "Hello!"
Print a second text line
Print another text line with a bunch of numbers as text.

Then sent out a setting that goes nowhere that you figured it out.. set the I2C address .

The I2C address that you expected the gain setting to go.

Move the address settings to above the gain.

A simple suggestion.
Instead of hello print your file name.

I shall indeed give your suggestion a try. Thanks.

Ahh ok, so using the ads.begin statement without an address was causing the program to pause at that point?

No, I think the suggestion is that setting the gain before the "begin" was the problem, assuming that gain setting requires communication with a device, and isn't simply an internal driver operation.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.