I have an analog sensor which reads values 0-5v, -75 degrees to 75 degrees. Now I have converted to +75 degrees and -75 degrees format depend on the voltage.
From 2.5v to 5v data is read properly (i.e 0-75 degree), but from 0-2.5v they are negative values -75 degree to 0. In the below image array holding register is reading 65493 and 65491 which are negative value. How do I make it readable format? Since my code is very big, only part of code is pasted.
#define ID 1
int Wind_Speed=30;
int Wind_Kmph=67;
signed int tracker_des_angle=-45;
signed int tracker_actual_pos=-43;
Modbus slave(ID, 0, 0);
boolean led;
int8_t state = 0;
unsigned long tempus;
// data array for modbus network sharing
uint16_t au16data[14];
void setup() {
// start communication
slave.begin( 9600 );
rtcSetup();
tempus = millis() + 100;
digitalWrite(13, HIGH );
}
void loop() {
// poll messages
// blink led pin on each valid message
state = slave.poll( au16data, 14);
if (state > 4) {
tempus = millis() + 50;
digitalWrite(13, HIGH);
}
if (millis() > tempus) digitalWrite(13, LOW );
calcTime();
convertUTCtoLocal();
au16data[0]=local_year;
au16data[1]=local_month;
au16data[2]=local_day;
au16data[3]=wkDay;
au16data[4]=local_h;
au16data[5]=local_m;
au16data[6]=local_s;
au16data[7]=Wind_Speed;
au16data[8]=Wind_Kmph;
au16data[9]=tracker_des_angle;
au16data[10]=tracker_actual_pos;
au16data[11] = slave.getInCnt();
au16data[12] = slave.getOutCnt();
au16data[13] = slave.getErrCnt();
}
