Skip to content

Commit dca4016

Browse files
authored
Merge pull request #618 from kattni/ad8495-code
Adding AD8495 code.
2 parents 43c1671 + 67a78b0 commit dca4016

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#define TC_PIN A0 // set to ADC pin used
2+
#define AREF 3.3 // set to AREF, typically board voltage like 3.3 or 5.0
3+
#define ADC_RESOLUTION 10 // set to ADC bit resolution, 10 is default
4+
5+
float reading, voltage, temperature;
6+
7+
float get_voltage(int raw_adc) {
8+
return raw_adc * (AREF / (pow(2, ADC_RESOLUTION)-1));
9+
}
10+
11+
float get_temperature(float voltage) {
12+
return (voltage - 1.25) / 0.005;
13+
}
14+
15+
void setup() {
16+
Serial.begin(9600);
17+
}
18+
19+
void loop() {
20+
reading = analogRead(TC_PIN);
21+
voltage = get_voltage(reading);
22+
temperature = get_temperature(voltage);
23+
Serial.print("Temperature = ");
24+
Serial.print(temperature);
25+
Serial.println(" C");
26+
delay(500);
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import time
2+
import analogio
3+
import board
4+
5+
ad8495 = analogio.AnalogIn(board.A1)
6+
7+
8+
def get_voltage(pin):
9+
return (pin.value * 3.3) / 65536
10+
11+
12+
while True:
13+
temperature = (get_voltage(ad8495) - 1.25) / 0.005
14+
print(temperature)
15+
print(get_voltage(ad8495))
16+
time.sleep(0.5)

0 commit comments

Comments
 (0)