Need Help with Reading Modbus Output using Simple Modbus Master

Hi guys,

I'm currently working on a project involving reading data from a Schneider Acti 9 Power Meter and sending the data through Arduino to the internet. I'm having a problem with reading data from the power meter to the Arduino. The main library I'm using is the Simple Modbus Master library. The code I have right now is as the following. The output of this code, for some reason, is 769.


#include <SimpleModbusMaster.h>
#include <SoftwareSerial.h>

//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate
#define retry_count 10

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2

#define LED 13
#define RX 8
#define TX 7

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 1

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
PACKET1,
//PACKET2,
TOTAL_NO_OF_PACKETS // leave this last entry
};

SoftwareSerial Modbus(RX,TX);

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
// Initialize each packet
modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 1845, 2, 0);
//modbus_construct(&packets[PACKET2], 1, PRESET_MULTIPLE_REGISTERS, 1, 1, 0);

// Initialize the Modbus Finite State Machine
modbus_configure(&Serial, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);

pinMode(LED, OUTPUT);
}

void loop()
{
modbus_update();
long temp = (long)regs[0]<<16|regs[1]; //?
Serial.println(readRegs[0]); //?
}


I'm still very new to Modbus. I've haven't fully understood it. Please help :confused:

The main library I'm using is the Simple Modbus Master library.

Post a link to it, there are several different version of libraries with that name on the Internet.

I'm currently working on a project involving reading data from a Schneider Acti 9 Power Meter and sending the data through Arduino to the internet.

This is your second thread about the connection to that device and you still failed to provide a link to it's manual!

modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 1845, 2, 0);

It's a bad idea to request two registers if you provide only space for one of them.

The output of this code, for some reason, is 769.

It outputs the content of register 1845. The register seems to contain 769. Why are your surprised?

Here's the link to the library I'm using.
I'm using the SimpleModbusMasterV2rev2 files.

I just found the manual for the device. I attached it to this reply.

pylon:

modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 1845, 2, 0);

It's a bad idea to request two registers if you provide only space for one of them.

I don't really understand this part. How do I add more space so that I can read more than 1 register in each packet?

pylon:
It outputs the content of register 1845. The register seems to contain 769. Why are your surprised?

The problem is that I already tried to change the register address to different registers, but the output is always the same: 769.

Acti 9 iEM3000_A9MEM3155.pdf (121 KB)

I don't really understand this part. How do I add more space so that I can read more than 1 register in each packet?

Like that:

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 2

I just found the manual for the device. I attached it to this reply.

That's not a manual, that's a fact sheet. The manual would declare which register holds what value. Where did you get the register number 1845 from?

pylon:
Like that:

// The total amount of available memory on the master to store data

#define TOTAL_NO_OF_REGISTERS 2

Oh, I see.

pylon:
That's not a manual, that's a fact sheet. The manual would declare which register holds what value. Where did you get the register number 1845 from?

Ohh, thanks for pointing that out. Here's the Modbus register manual. Here's the rest of the manual.

The Google Photos link doesn't work for me. If it's an image file, please post it directly to the forum as external links tend to get unpopulated quite soon.

This should work. . Just in case it doesn't, I've also attached it

According to that sheet register 1845 holds the year. This isn't a value that I would expect to change that much. If you never adjusted the value a year 2001 seems to make sense to me. So again: why are you surprised to read that value?

If you used other registers, which one did you try?

Actually, I've already changed the year to match this year, 2019. That's why I'm surprised to read that the value is 769. Also, I've tried reading other registers, specifically register 3000 and still it gave the value 769.

Update:
I've tried to change the number of registers, reading the same register, 1845, but instead of the usual 769, the serial monitor displays 0.

I've tried to change the number of registers, reading the same register, 1845, but instead of the usual 769, the serial monitor displays 0.

I get the impression that your hardware wiring is not correct. Post a complete wiring diagram!

This is my configuration. I connect the power line and load of the power meter according to the configuration in the manual. The RS485 communication port in the power meter is then connected to the MAX485 chip. The serial output of the MAX485 chip I connect to the Arduino according to this format:

RO -> RX
DO -> TX
DE -> pin 3
RE -> pin 2

I completely overlooked that:

void loop()
{
 modbus_update();
 long temp = (long)regs[0]<<16|regs[1]; //?
 Serial.println(readRegs[0]);  //?
}

You must not use the Serial interface for debugging output while it's used for the Modbus connection! Everything you print will be sent to the Modbus and there the bytes make no sense.

DO -> TX

I doubt the pin is called DO.

DE -> pin 3
RE -> pin 2

Both (DE and RE) are expected to be connected to pin 2 (at least that's in your code).

What is that setup expected to do in the end? Is the UNO used to control anything or just as a forwarder of data from or to the PC?