-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtia-board.ino
79 lines (56 loc) · 1.67 KB
/
tia-board.ino
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <ADS1119.h>
#include <SPI.h>
#include <Arduino.h>
ADS1119 ads1 = ADS1119();
struct ADS1119Configuration configuration;
// Setup communication
int CS_pot_gain = 4;
int CS_pot_offset = 5;
//
int lightLevel = 0;
int lightMeasurements = 4;
int startGain = 190;
int levelOffset = 3;
void setup() {
Serial.begin(9600);
pinMode (CS_pot_gain, OUTPUT);
pinMode (CS_pot_offset, OUTPUT);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV16); //1MHz clock
digitalPotWrite(levelOffset, "offset");
digitalPotWrite(startGain, "gain");
delay(100);
configuration.mux = ADS1119MuxConfiguration::positiveAIN0negativeAIN1;
configuration.gain = ADS1119Configuration::Gain::one;
configuration.dataRate = ADS1119Configuration::DataRate::sps90;
configuration.conversionMode = ADS1119Configuration::ConversionMode::continuous;
configuration.voltageReference = ADS1119Configuration::VoltageReferenceSource::external;
configuration.externalReferenceVoltage = 5.0;
ads1.begin();
ads1.reset();
}
void loop() {
lightLevel = 0;
for(int i = 0; i<lightMeasurements; i++){
lightLevel = lightLevel + (1000*ads1.readVoltage(configuration));
}
lightLevel = lightLevel/lightMeasurements;
Serial.println(lightLevel);
delay(30);
}
int digitalPotWrite(int value, String mode)
{
if (mode == "gain"){
digitalWrite(CS_pot_gain, LOW);
SPI.transfer(B00010001);
SPI.transfer(value);
digitalWrite(CS_pot_gain , HIGH);
} else if (mode == "offset"){
digitalWrite(CS_pot_offset, LOW);
SPI.transfer(B00010001);
SPI.transfer(value);
digitalWrite(CS_pot_offset , HIGH);
}
}