-
Notifications
You must be signed in to change notification settings - Fork 1
/
adsTest.cpp
39 lines (33 loc) · 830 Bytes
/
adsTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bcm2835.h>
#include <unistd.h>
#include <time.h>
#include "ADS8689_BCM2835.h"
int main()
{
ADS8689 adc;
struct timespec delay;
delay.tv_sec = 0;
delay.tv_nsec = 10000;
if (!bcm2835_init())
{
printf("bcm2835_init failed. Are you running as root??\n");
return 1;
}
//change tp bcm2835_aux_spi_begin() if using SPI1
if (!bcm2835_spi_begin())
{
printf("bcm2835_spi_begin failed. Are you running as root??\n");
return 1;
}
//using SPI0 and CS0, comment arguments for SPI1 and CS2
if(!adc.begin(SPI_0, BCM2835_SPI_CS0))
return 1;
while(1)
{
//read adc
int val = adc.readADC();
printf("val = %d ", val);
printf("Voltage = %f\n", (((float)(val)) * 4.096f)/(65535));
nanosleep(&delay, NULL); //must wait at least 10000 ns before next read
}
}