AndyNC
Posts: 46
Joined: Thu Aug 30, 2012 7:04 am

ADS1115 changing gain etc using WiringPi

Sun Jan 13, 2019 7:06 pm

Hi All,

I've just added a ADSD1115 to i2c bus and have it displaying ADC values on a 4x20 LCD display.
I may need to change the gain and sample rate.
I've looked through the wiring PI source but can't find any functions for manipulating the config register/s.
Are there any functions I've missed or do I have to create my own using I2C calls to the device directly.

Many thanks

Andy

danjperron
Posts: 3391
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: ADS1115 changing gain etc using WiringPi

Sun Jan 13, 2019 9:10 pm

It is a trick! The gain is changed by using digitalWrite with the base pin number you define for the ads1115 setup.
Pin number+1 will be the frame rate.

Code: Select all

#include <stdio.h>
#include <wiringPi.h>
#include <ads1115.h>


#define	AD_BASE 120


int main (void)
{

  char * Vref[]={"6.144","4.096","2.048","1.024","0.512","0.256"};

  int i;
  int g;
  int value;

  wiringPiSetup () ;
  ads1115Setup(AD_BASE,0x48);

  for(g=0;g<6;g++)
  {
    digitalWrite(AD_BASE,g);
    printf("\nGain with Vref=%sV\n",Vref[g]);
    printf("------------\n");
    for (i=0;i<4;i++)
     printf("Ch%d:%d\n",i,analogRead(AD_BASE+i));
  }
  return 0 ;
}

Code: Select all

[email protected]:~ $ ./ad

Gain with Vref=6.144V
------------
Ch0:2721
Ch1:5488
Ch2:8253
Ch3:11006

Gain with Vref=4.096V
------------
Ch0:4082
Ch1:8232
Ch2:12379
Ch3:16509

Gain with Vref=2.048V
------------
Ch0:8163
Ch1:16464
Ch2:24758
Ch3:32767

Gain with Vref=1.024V
------------
Ch0:16327
Ch1:32767
Ch2:32767
Ch3:32767

Gain with Vref=0.512V
------------
Ch0:32655
Ch1:32767
Ch2:32767
Ch3:32767

Gain with Vref=0.256V
------------
Ch0:32767
Ch1:32767
Ch2:32767
Ch3:32767

AndyNC
Posts: 46
Joined: Thu Aug 30, 2012 7:04 am

Re: ADS1115 changing gain etc using WiringPi

Sun Jan 13, 2019 9:53 pm

Thank you danjperron,

I have this working now with variable gain. Can't verify it precisely because the analogue pins are floating at the moment but the display seems to correspond to increasing sensitivity.

You say that the conversion rate will be Pin number+1 but what of the other parameters such as the input multiplexer?
Is there a table some where in the wiringPi documentation that tell me this?

I couldn't work anything out from the wiringPi source code.

Again thanks

Andy

Edit: Just found the myDigitalWrite function which explains it. I may need to extend or override it to change the multiplexer and other settings.
But on further examination it seem limited to node-> data0 and data1. I may have to write to the registers using I2C functions or write it all myself. I have done this on Pics and MSP430s but I was looking for and easy option.

danjperron
Posts: 3391
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: ADS1115 changing gain etc using WiringPi

Sun Jan 13, 2019 10:23 pm

You say that the conversion rate will be Pin number+1 but what of the other parameters such as the input multiplexer?
The multiplexer is done with the analogRead!

ex: analogRead(AD_BASE + chan)

where chan is

Code: Select all

 switch (chan)
  {
    case 0: config |= CONFIG_MUX_SINGLE_0 ; break ;
    case 1: config |= CONFIG_MUX_SINGLE_1 ; break ;
    case 2: config |= CONFIG_MUX_SINGLE_2 ; break ;
    case 3: config |= CONFIG_MUX_SINGLE_3 ; break ;

    case 4: config |= CONFIG_MUX_DIFF_0_1 ; break ;
    case 5: config |= CONFIG_MUX_DIFF_2_3 ; break ;
    case 6: config |= CONFIG_MUX_DIFF_0_3 ; break ;
    case 7: config |= CONFIG_MUX_DIFF_1_3 ; break ;
  }

No need to modify the code! Everythings is there!

Be aware that Gain and frame rate are global by the chip itself.
Last edited by danjperron on Sun Jan 13, 2019 10:35 pm, edited 1 time in total.

AndyNC
Posts: 46
Joined: Thu Aug 30, 2012 7:04 am

Re: ADS1115 changing gain etc using WiringPi

Sun Jan 13, 2019 10:31 pm

Thank you again,
No need for me to do anything except use it as supplied.
I did not notice the extra 4 channel options.

Andy

Return to “C/C++”