-1

I'm working on a Arduino Uno and a ADC ADS1115. Devices communicate by I2C where Arduino is the master.

I would like to use the ADC to the maximum of his possibility.

So i configure the ADC to set a pin when a conversion finish and use this pin as an external interrupt. But i can't read the data because I2C interrupt can't work in a external interrupt handler. I think to use a timer to have a fixed sampling rate too, but it's the same issue.

There is my code below, and if you have any idea of how i can doing my goal let's share it ;)

#include <QueueArray.h>
#include <ADS1115_Vibratec.h>

  Adafruit_ADS1115 ads;

  QueueArray <uint16_t> fifo;

  int i=0;

void setup() {

 Wire.begin();

 Serial.begin(115200);

 ads.Config( ADS1115_REG_CONFIG_OS_NOEFFECT,
          ADS1115_REG_CONFIG_MUX_DIFF_0_1,
          ADS1115_REG_CONFIG_PGA_6_144V,
          ADS1115_REG_CONFIG_MODE_CONTIN,
          ADS1115_REG_CONFIG_DR_860SPS,
          ADS1115_REG_CONFIG_CMODE_TRAD,
          ADS1115_REG_CONFIG_CPOL_ACTVLOW,
          ADS1115_REG_CONFIG_CLAT_NONLAT,
          ADS1115_REG_CONFIG_CQUE_1CONV);

 ads.Set_ConvReady_function();

 attachInterrupt(0,interrupt,RISING); //INT0 -> pin 2, fonction interrupt,    front montant


  }

  void loop() {

   while (!fifo.isEmpty ())
   {
      Serial.write(fifo.dequeue());
      Serial.println();

   }


  }
  void interrupt()
  {
    fifo.enqueue(ads.ReadConvert()); 
  }
1

You could set a 'volatile' flag in the interrupt routine. In the loop() you can check if the flag is set. That is how the i2dev uses the interrupt for the MPU-6050. See the MPU6050_DMP6.ino example.

First thing to do is set the I2C clock to 400 kHz. Keep the wires short and pullup resistors low.

Wire.begin();
Wire.setClock(400000L);   // 400 kHz I2C clock speed

You can let the MultiSpeed I2C Scanner run for a while to see if it is stable.

The ADS1115 has also I2C High-Speed Mode up to 3.4MHz. The Arduino can not do that. The Arduino has a fast SPI mode, but the ADS1115 has no SPI bus.

Using an interrupt adds extra overhead. A fixed software timer with millis might be just as fast.

Do you want the maximum of 860 Samples per second? The Arduino Uno or Mega or Leonardo are too slow for that. Do you want to continuously read data or just a burst and store it in ram ?

  • Thanks for your help. I would like to continuously read data. Are you sure that Arduino is too slow for 860 sps? – bouaaah Jul 19 '17 at 6:35
  • The Arduino Uno is too slow. It probably can not handle all that data with the normal Arduino functions. The Arduino Leonardo or Micro is a little better, because they can transmit data via the USB at higher rates. I think you need a Due or Zero or M0. Use the Arduino Uno to run tests and develop code, you will found out soon enough what datarate it can do. – Jot Jul 19 '17 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.