zhiyo
Posts: 1
Joined: Fri Dec 29, 2017 2:52 pm

Learning adc read&Setup with Ads1115

Fri Dec 29, 2017 4:51 pm

I'm learnning how to read data from ads1115 with WiringPi.

And i found an example code from viewtopic.php?t=36250&p=305270

Code: Select all

#include <ads1115.h>
#define MY_BASE 2222 //pinBase
...
  ads1115Setup (MY_BASE, 0x48) ;
  int ch0 = analogRead (MY_BASE + 0) ;
  int ch3 = analogRead (MY_BASE + 3) ;
// and so on
This code works fine with single channel , but if i want to read 2-channels ,the ouput values are always the same.

I'm not sure if i'm doing it right .
----------------------------------------------------------------------------------------------------------------------------------------
There are few questions i want to figure out :

Even thougth gordan has explained in viewtopic.php?t=189280 a mcp12s17 case
-> The pinBase is the new pin number of the first pin of the device - any number >= 64 that you like.

1.How should I define the pinBase properly for ads1115?
Does it mean I can set pinBase to any number >=64 in ads1115 too?


2. how do i set analogRead to single-end or diffirential mode ?

Please help me find out if i missed something.

aminka
Posts: 17
Joined: Tue Jun 30, 2020 6:34 pm

Re: Learning adc read&Setup with Ads1115

Mon Jul 06, 2020 7:07 pm

zhiyo wrote:
Fri Dec 29, 2017 4:51 pm
I'm learnning how to read data from ads1115 with WiringPi.

And i found an example code from viewtopic.php?t=36250&p=305270

Code: Select all

#include <ads1115.h>
#define MY_BASE 2222 //pinBase
...
  ads1115Setup (MY_BASE, 0x48) ;
  int ch0 = analogRead (MY_BASE + 0) ;
  int ch3 = analogRead (MY_BASE + 3) ;
// and so on
This code works fine with single channel , but if i want to read 2-channels ,the ouput values are always the same.

I'm not sure if i'm doing it right .
----------------------------------------------------------------------------------------------------------------------------------------
if you get the answer tell me please.

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

Re: Learning adc read&Setup with Ads1115

Mon Jul 06, 2020 10:52 pm

WiringPi start to be obsolete because of abuse that Gordon got about is nice work. Some people are nasty!

The current source code is not available anymore but you could find some source code from wiringpi unofficial branch

Then to answer your question you need to look at the code in file ads1115.c

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 ;
  }
Channel 0,1,2,3 are the individual and 4,5,6,7 are the differential.

Return to “Beginners”