Hello guys, does anyone know a working library for the implementation of Arduino Uno and Schneider Power Meter or something similar in nature? Because I have used the SimpleModbus library and it does not give me results. When I loaded it up, the value is always 0. I am using the PM1200 and below is my code.
#include <SimpleModbusMaster.h>
//#include <SoftwareSerial.h>
#define TxEnablePin 2 // RS485 modbus direction control pin:
#define baud 9600 // modbus port speed:
#define timeout 1000 // modbus timeout in mSec:
#define polling 200 // modbus scan rate in mSec:
#define retry_count 20
#define TOTAL_NO_OF_REGISTERS 20// number of registers to poll for:
#define LED 13
enum
{
PACKET1,
TOTAL_NO_OF_PACKETS // leave this last entry
};
Packet packets[TOTAL_NO_OF_PACKETS]; // array of Packets to be configured
//packetPointer packet1 = &packets[PACKET1];
unsigned int regs[TOTAL_NO_OF_REGISTERS]; // master register array
long previousMillis = 0;
long interval = 1200;
unsigned long currentMillis;
//SoftwareSerial Serial1 (10, 11);
void setup() {
Serial.begin(9600);
modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 3926, 2, regs); //initialize packet 1
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
pinMode(LED,OUTPUT);
}
void loop() {
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
modbus_update();
float Power;
unsigned long temp = (unsigned long)regs[0] << 16 | regs[1];
Power = (float)&temp;
currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
Serial.print("Exception errors: ");
Serial.println(packets[PACKET1].exception_errors);
Serial.print("Failed requests: ");
Serial.println(packets[PACKET1].failed_requests);
Serial.print("Successful requests: ");
Serial.println(packets[PACKET1].successful_requests);
Serial.print("Low byte: ");
Serial.println(regs[0]);
Serial.print("High byte: ");
Serial.println(regs[1]);
Serial.print("Power ");
Serial.println(Power);
Serial.println("----------");
previousMillis = currentMillis;
}
}
Also, I am new to Modbus. I cannot fully understand it.
Please help.