From 3facaaa2a92986ab572d8b6505cbe52db8e2fa53 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Sat, 10 Feb 2018 23:02:53 +0200 Subject: enable thermistor temperature reading. --- src/server/main.c | 18 +++++++++++------- src/tempmodule/main.ino | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/server/main.c b/src/server/main.c index 08e85b7..737d694 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -37,7 +37,7 @@ static int getpacket(char *data, size_t buffsize, int *sock, struct sockaddr_in static void draw_idle(void); static void draw_busy(const char * const data); static float digest_mpu_temp(const short int rawdata); -static float digest_thermistor_voltage(const short int rawdata); +static float digest_thermistor_temp(const short int rawdata); int main(void) { @@ -139,7 +139,7 @@ static void draw_idle(void) mvprintw(1, 0, "mpu temp: [waiting for ESP8266...]"); move(2, 0); clrtoeol(); - mvprintw(2, 0, "thermistor voltage: [waiting for ESP8266...]"); + mvprintw(2, 0, "thermistor temp: [waiting for ESP8266...]"); move(3, 0); clrtoeol(); mvprintw(3, 0, "press 'q' to exit"); @@ -152,13 +152,13 @@ static void draw_busy(const char * const data) short int mpu_data; short int thermistor_data; float mpu_temp; - float thermistor_voltage; + float thermistor_temp; memcpy(&sequence, data + 2, sizeof(sequence)); memcpy(&mpu_data, data + 6, sizeof(mpu_data)); memcpy(&thermistor_data, data + 8, sizeof(thermistor_data)); mpu_temp = digest_mpu_temp(mpu_data); - thermistor_voltage = digest_thermistor_voltage(thermistor_data); + thermistor_temp = digest_thermistor_temp(thermistor_data); move(0, 0); clrtoeol(); @@ -168,7 +168,7 @@ static void draw_busy(const char * const data) mvprintw(1, 0, "mpu temp: %.3fC", mpu_temp); move(2, 0); clrtoeol(); - mvprintw(2, 0, "thermistor voltage: %.3fV", thermistor_voltage); + mvprintw(2, 0, "thermistor temp: %.1fC", thermistor_temp); move(3, 0); clrtoeol(); mvprintw(3, 0, "press 'q' to exit"); @@ -184,11 +184,15 @@ static float digest_mpu_temp(const short int rawdata) return ret; } -static float digest_thermistor_voltage(const short int rawdata) +/* + * raw data is in 0.1°K per 1. Subtract 2730 to get Celsius. + * Multiply by 0.1f (divide by 10) to get the correct scale. + */ +static float digest_thermistor_temp(const short int rawdata) { float ret; - ret = rawdata * 0.003222656f; + ret = (rawdata - 2730) * 0.1f; return ret; } diff --git a/src/tempmodule/main.ino b/src/tempmodule/main.ino index d0db8ea..dc90665 100644 --- a/src/tempmodule/main.ino +++ b/src/tempmodule/main.ino @@ -34,6 +34,7 @@ static const unsigned int iled = 2; static const unsigned int analog = A0; static const int port = 2191; static const int mpu_addr = 0x68; +static const int splitter_res = 4699; static char udppacketbuffer[32] = {0}; static char *udppacketcursor = NULL; IPAddress ip; @@ -96,6 +97,7 @@ void loop(void) } } data = analogRead(analog); + data = get_temperature(get_resistance(data, splitter_res)); udp_push(&data, sizeof(data)); if (!(udp_flush())) { -- cgit v1.2.3