Has anyone written C code for the R-Pi to convert 16 bit serial numbers from the ADC into parallel numbers and save these to the Pi’S memory?
The ADC Pi is an Analogue to Digital converter for the Raspberry Pi
21/07/2018
Posted by:
WayneA
Wayne
21/07/2018
Posted by:
andrew
The usual way to store a series of numbers in C is using an array. You can find a good tutorial on arrays at Tutorialspoint
You can use our ADC Pi C library to read the values from the ADC Pi using the read_voltage() function.
The code example below creates an array with a size of 1000, reads the ADC 1000 times and then prints the recorded values back to the console.
#include
#include
#include
#include "ABE_ADCPi.h"
int main(int argc, char **argv){
setvbuf (stdout, NULL, _IONBF, 0); // needed to print to the command line
double values[1000];
// save the values from the ADC into the array
for (int i=0; i < 1000; i++){
values[i] = read_voltage(0x68,1, 16, 1, 1); // ADC on I2C address 0x68, channel = 1, 16 bit, pga = 1, conversion mode = continuous
usleep(200000); // sleep 0.2 seconds
}
// print them back to the console
for (int i=0; i < 1000; i++){
printf("Value %i: %G \n", i, values[i]);
}
return (0);
}
Save the code as "demo-adc-array.c" and you can compile it with the following command:
gcc ABE_ADCPi.c demo-adc-array.c -o demo-adc-array
The ADC Pi library files "ABE_ADCPi.h" and ABE_ADCPi.c" will need to be in the same folder as the demo-adc-array.c file.
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.