Reading Analog Inputs directly using pigpio



  • 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



  • 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



  • 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



  • 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

    #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;
    }
    
    


  • 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.



  • 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



  • 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