Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read BeagleBone Analog Input (C++)
Forum Updated to NodeBB v4.3 + New Features

Read BeagleBone Analog Input (C++)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cherault
    wrote on last edited by
    #1

    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;
    myFile.open(PATH, ios::in);
    myFile << CAPE << endl;
    myFile.close();
    }

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

    int main()
    {
    autoConfig();

        int ain0;
        while(1)
        {
                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.

    Regards,

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cherault
        wrote on last edited by
        #3

        Hi SGait,

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

        Regards,

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved