Read BeagleBone Analog Input (C++)

  • Hi all,

    I made a short code to read in C++ the analog input of a BeagleBone Black (AIN0).
    Is Qt is able to show using "lcdnumber" the output values and if yes how ?

    This is the C++ code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <stdlib.h>

    #define CAPE "cape-bone-iio"
    #define PATH "/sys/devices/bone_capemgr.9/slots"
    #define AIN0 "/sys/devices/ocp.3/helper.15/AIN0"

    using namespace std;

    void autoConfig()
    ofstream myFile;, ios::in);
    myFile << CAPE << endl;

    string analogRead()
    ifstream myFile0(AIN0);
    string ligne0;
    while(getline(myFile0, ligne0))
    return ligne0;

    int main()

        int ain0;
                ain0 = atoi(analogRead().c_str());
                cout << ain0 << endl; //wanna plot this value on the lcdnumber of Qt
        return 0;


    Thanks for your help and support.


  • Lifetime Qt Champion


    I'd say QFile to read the device files, Qwt for the plotting part and you should be good to go for the GUI part.

    As for the data acquisition, depending on the speed you need you could simply use a QTimer to read the values and then update your plot with them.

    If you really need the infinite loops then you should use a QThread.

    Hope it helps

  • Hi SGait,

    Thanks for your reply.
    I will try QTimer to see how it works and give you a feedback.


Log in to reply