Skip to content

Instantly share code, notes, and snippets.

@yoneken
Created October 3, 2013 15:57
Show Gist options
  • Save yoneken/6812201 to your computer and use it in GitHub Desktop.
Save yoneken/6812201 to your computer and use it in GitHub Desktop.
ADC test for BeagleBone Black.
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[]){
FILE *Handle = NULL;
char *Slots = "/sys/devices/bone_capemgr.9/slots";
char *AIn1 = "/sys/devices/ocp.2/helper.14/AIN1";
char buf[10] = {0};
struct timespec start, end;
int i;
if((Handle = fopen(Slots, "rb+")) == NULL){
printf("Unable to register adc.\n");
return 1;
}
fwrite("cape-bone-iio", sizeof(char), 13, Handle);
fclose(Handle);
if((Handle = fopen(AIn1, "rb")) == NULL){
printf("Unable to open AIN1.\n");
return 1;
}
clock_gettime(CLOCK_MONOTONIC ,&start);
fread(buf, sizeof(char), 10, Handle);
clock_gettime(CLOCK_MONOTONIC ,&end);
fclose(Handle);
printf("Get value from AIN1 : %s\n", buf);
printf("Time elapsed %d [ns]\n", end.tv_nsec - start.tv_nsec);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment