Dear all.
I have attached my code below . I have few question here.
http://arduino.cc/en/Reference/WordCast
question are:
- I have value latitude 13.08. Here 13 should put in lower byte of word and 08 into higher order of byte address. How to assign it
2)i have analog sensor which read analog voltage 0-5v . that being converted from +75 deg to -75 degree.
from 0-75 degree i can read value properly on QMODBUS, But 0 to -75 master varying with 65561 value.How to covert it to -ve value.
- IS it possible to assign our own slave address in below code
#define ID 1
Modbus slave(ID, 0, 0);
boolean led;
int8_t state = 0;
unsigned long tempus;
// data array for modbus network sharing
uint16_t au16data[9];
float 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(A0);
Yvoltage = Sensor_Value * ARDUINO_ANALOG_SCALING;
Ydegree=(30*Yvoltage)-75;
/* mySerial.println(Ydegree);
delay(1000);*/
au16data[0] = Ydegree;
// au16data[1]=latitude;
word(au16data[1],latitude);
//word(au16data[1]);
// diagnose communication
au16data[6] = slave.getInCnt();
au16data[7] = slave.getOutCnt();
au16data[8] = slave.getErrCnt();
}