Originally Posted by
grumpy
What have you tried?
The focus of folks here is more on equipping you to solve problems, rather than just giving you solutions without any effort on your part. So you have to demonstrate some effort, rather than just demanding a solution.
You would also need to decide what should happen if the value does not have only two decimal places (such as 13.081). There is also a wrinkle in that a floating point variable cannot exactly represent all multiples of 0.01 (it only represents an approximation) and your solution would need to cope with that.
Code:
#define ID 1
#include<math.h>
Modbus slave(ID, 0, 0);
boolean led;
int8_t state = 0;
unsigned long tempus;
// data array for modbus network sharing
uint16_t au16data[9];
double latitude=13.08;
static int Sensor_Value;
float Yvoltage;
static float ARDUINO_ANALOG_SCALING = 0.00488758;
static float Ydegree;
void setup() {
// define i/o
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(6, LOW );
digitalWrite(7, LOW );
digitalWrite(8, LOW );
digitalWrite(9, LOW );
digitalWrite(13, HIGH );
// start communication
slave.begin( 9600 );
tempus = millis() + 100;
digitalWrite(13, HIGH );
}
void loop() {
// poll messages
// blink led pin on each valid message
state = slave.poll( au16data, 9 );
if (state > 4) {
tempus = millis() + 50;
digitalWrite(13, HIGH);
}
if (millis() > tempus) digitalWrite(13, LOW );
// read analog inputs
Sensor_Value=analogRead(A3);
Yvoltage = Sensor_Value * ARDUINO_ANALOG_SCALING;
Ydegree=(30*Yvoltage)-75;
/* mySerial.println(Ydegree);
delay(1000);*/
au16data[0] = Sensor_Value;
int lat_int=(int)latitude;
float lat_float=(latitude-lat_int)*1000;
//Serial.print((lat_float));
int value=(int)lat_int;
au16data[1]=lowByte(lat_int);
au16data[1]=highByte(value);
// Serial.println( au16data[1]);
au16data[6] = slave.getInCnt();
au16data[7] = slave.getOutCnt();
au16data[8] = slave.getErrCnt();
}
Here i am reading value 0 in floating point , WHich work fine over python