//#include <Wire.h>
#include <TinyDebug.h>
// void setup() {
// Debug.begin();
// //Wire.begin(I2C_ADDRESS); /* join i2c bus with address 8 */
// //Wire.onRequest(requestEvent); /* register request event */
// pinMode(1, OUTPUT);
// pinMode (THERMISTORPIN, INPUT); // thermistor ON ATtiny85 PIN4!
// }
// function that executes whenever data is requested from master
void requestEvent() {
//Wire.write("24.33;"); /*send string on request */
// send the current data as 16bits representing milliamps, first 2 bytes for sensor
//unsigned short mAmps = presteinhart;
//byte bytes[2] = { (byte)((mAmps >> 8) & 0xff), (byte)(mAmps & 0xff) };
//Wire.write(bytes, 2);
char buffer[5];
//dtostrf(Tc, 4, 2, buffer);
//Wire.write(buffer);
}
#define I2C_ADDRESS 0x08
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void setup(void) {
Debug.begin();
}
void loop(void) {
float temp_ntc_0 = cacl_temp(analogRead(A3));
float temp_ntc_1 = cacl_temp(analogRead(A2));
float temp_ntc_2 = cacl_temp(analogRead(A0));
Debug.println("");
Debug.print("temp_ntc_0=");
Debug.println(temp_ntc_0);
Debug.print("temp_ntc_1=");
Debug.println(temp_ntc_1);
Debug.print("temp_ntc_2=");
Debug.println(temp_ntc_2);
char buffer[20]; // 18
char temp[10];
memset(buffer, 0, sizeof(buffer));
dtostrf(temp_ntc_0, 5, 2, temp);
strcat(buffer, temp);
strcat(buffer, ";");
dtostrf(temp_ntc_1, 5, 2, temp);
strcat(buffer, temp);
strcat(buffer, ";");
dtostrf(temp_ntc_2, 5, 2, temp);
strcat(buffer, temp);
strcat(buffer, ";");
Debug.println(buffer);
char hexBuffer[3 * sizeof(buffer)]; // Allocate enough space for 2 hexadecimal characters per byte and a null terminator
for (int i = 0; i < sizeof(buffer) - 1; i++) { // Subtract 1 to avoid printing the null terminator
sprintf(hexBuffer + 3 * i, "%02X ", buffer[i]); // Format each byte as a 2-digit hexadecimal value with leading zeros
}
hexBuffer[3 * (sizeof(buffer) - 1)] = '\0'; // Add null terminator at the end of the hexBuffer
Debug.println(hexBuffer);
delay(1000);
}
float cacl_temp(int analogValue) {
return 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
}