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;
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,
-
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