I'm trying to get my Arduino w/ an I/O expansion shield to communicate with a WattNode electrical meter via modbus. I'm able to send a packet and the WattNode appears to be accepting it as the light flashes green (this is what the manual says it should do when communications are correct). However, I am not really sure how to read the response. I have tried doing Serial.read() but this just results in a -1.
Any help would be great. And if I need to provide more info, just let me know.
Thanks!
James
int EN = 2;
int incomingByte = 0; // for incoming serial data
void setup() {
pinMode(EN, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(EN,HIGH);
Serial.write((byte)0x01);
Serial.write((byte)0x03);
Serial.write((byte)0x04);
Serial.write((byte)0xC5);
Serial.write((byte)0x00);
Serial.write((byte)0x01);
Serial.write((byte)0x95);
Serial.write((byte)0x07);
digitalWrite(EN,LOW);
incomingByte = Serial.read();
Serial.println(incomingByte, DEC);
delay(1000);
}
Oops, I changed it. With it setup like that, I now get a blinking yellow like from the WattNode. The manual says that "If the WattNode meter sees packets on the bus addressed to other devices, it will light the LED yellow for 200 milliseconds or longer if the packet duration is longer than 200 milliseconds." This doesn't make sense since I didn't change the address.
So I did a bit more reading, and tried a few more things to read the response from the WattNode, but not luck. I'm checking with Serial.available(), but still am not seeing anything.
int EN = 2;
int incomingByte = 0; // for incoming serial data
void setup() {
pinMode(EN, OUTPUT);
Serial.begin(9600);
digitalWrite(EN,HIGH);
}
void loop() {
for (int i=0; i<5; i++) {
digitalWrite(EN,HIGH);
Serial.write((byte)0x01);
Serial.write((byte)0x03);
Serial.write((byte)0x05);
Serial.write((byte)0x14);
Serial.write((byte)0x00);
Serial.write((byte)0x16);
Serial.write((byte)0x84);
Serial.write((byte)0xCC);
delay(100);
digitalWrite(EN,LOW);
}
delay(2000);
digitalWrite(EN,LOW);
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
digitalWrite(EN,HIGH);
delay(1000);
}
I think you need to connect your device to two other pins, and use NewSoftSerial (0023 or earlier) or SoftwareSerial (1.0+) to talk to it, and use Serial to talk to the PC/Serial Monitor.
Hmm, I feel like I'm still missing some important link here. I was under the impression that using the I/O expansion shield for talking to the WattNode was what I needed. So far it seems to be taking my communications, but I'm not able to read its response.