Reading Analog Inputs directly using pigpio

saot
Posts: 3
Joined: Mon Jul 20, 2015 4:22 pm

Reading Analog Inputs directly using pigpio

Postby saot » Mon Jul 20, 2015 4:26 pm

What would be the process of reading from the Unipi analog inputs directly using the pigpio library?
I'm trying to write a C Program that can read these inputs and I'm not entirely sure how to get started
tomas_hora
Site Admin
Posts: 298
Joined: Wed Oct 29, 2014 9:56 am

Re: Reading Analog Inputs directly using pigpio

Postby tomas_hora » Tue Jul 21, 2015 7:30 am

Hi! The best would be to take a closer look at the implementation in Evok:
https://github.com/UniPiTechnology/evok ... ig.py#L206
https://github.com/UniPiTechnology/evok ... ig.py#L354

or at least how is the communication over the I2C bus handled and what messages needs to be send. Then just use the pigpios functions to access the I2C bus: http://abyz.co.uk/rpi/pigpio/cif.html#i2cOpen
saot
Posts: 3
Joined: Mon Jul 20, 2015 4:22 pm

Re: Reading Analog Inputs directly using pigpio

Postby saot » Tue Jul 21, 2015 6:20 pm

Thank you!

I've been looking through the implementation in Evok and was having a hard time understanding some of the process.
First off, how do I know which register to read from when I'm using the i2c read commands?

I tried the following code (without a register) and applied 5v to the Analog input and my output was 00000000

Code: Select all

#include <pigpio.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <bitset>

using namespace std;

int main()
{
  gpioInitialise();

  int handle = i2cOpen(1, 0x68, 0);
  cout << bitset<8>(i2cReadByte(handle)) << endl;
  cout << bitset<8>(i2cReadByte(handle)) << endl;
  cout << bitset<8>(i2cReadByte(handle)) << endl;
  cout << bitset<8>(i2cReadByte(handle)) << endl;

  i2cClose(handle);
  gpioTerminate();

  return 0;
}
tomas_hora
Site Admin
Posts: 298
Joined: Wed Oct 29, 2014 9:56 am

Re: Reading Analog Inputs directly using pigpio

Postby tomas_hora » Wed Jul 22, 2015 7:16 am

You will find out which register to read in the IC datasheet: http://ww1.microchip.com/downloads/en/D ... 22088b.pdf

Or there are many code examples that will give you idea on the internet.
saot
Posts: 3
Joined: Mon Jul 20, 2015 4:22 pm

Re: Reading Analog Inputs directly using pigpio

Postby saot » Wed Jul 22, 2015 3:54 pm

I've already looked through that Data Sheet and can find no mention of which register I should be reading from?
I've been trying to figure this out for a week now and no code sample online that I could find has helped me. Could you refer me to a sample that points me in the right direction?

Would the process be to simply read the bytes in, then convert them using the scheme described on page 16 of the data sheet? (Section 4.9.2)
Or am I missing a step?

Thanks for your help
tomas_hora
Site Admin
Posts: 298
Joined: Wed Oct 29, 2014 9:56 am

Re: Reading Analog Inputs directly using pigpio

Postby tomas_hora » Thu Jul 23, 2015 7:53 am

Maybe the easiest example is https://github.com/abelectronicsuk/adcp ... -inputs.py

or https://github.com/abelectronicsuk/adcpi

Basically yes, and then you need to convert it to the Voltage on the AI according to the voltage divider: V = raw_value * (correction / gain) where correction is cca 5.56

Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 1 guest