Hello, I've bought an energy meter (OB115-Mod) that supports RS485
I am trying to read it using an Arduino Nano;
This is the register map of the device
I'm following this example
which I intend to modify for my needs; I just want to read the voltage at the moment
#include <ModbusMaster.h>
/*!
We're using a MAX485-compatible RS485 Transceiver.
Rx/Tx is hooked up to the hardware serial port at 'Serial'.
The Data Enable and Receiver Enable pins are hooked up as follows:
*/
#define MAX485_DE 3
#define MAX485_RE_NEG 2
// instantiate ModbusMaster object
ModbusMaster node;
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
// Init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// Modbus communication runs at 9600 baud
Serial.begin(9600);
//Serial.begin(9600, SERIAL_8N1);
// Modbus slave ID 2
node.begin(2, Serial);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
bool state = true;
void loop()
{
uint8_t result;
uint16_t data[6];
// Toggle the coil at address 0x0002 (Manual Load Control)
// result = node.writeSingleCoil(0x0002, state);
// state = !state;
// Read 16 registers starting at 0x3100)
result = node.readInputRegisters(0x0002, 2);
// if (result == node.ku8MBSuccess)
// {
// Serial.print("Vbatt: ");
// Serial.println(node.getResponseBuffer(0x00)/100.0f);
// Serial.print("Vload: ");
// Serial.println(node.getResponseBuffer(0xC0)/100.0f);
// Serial.print("Pload: ");
// Serial.println((node.getResponseBuffer(0x0D) +
// node.getResponseBuffer(0x0E) << 16)/100.0f);
// }
Serial.println(result);
delay(1000);
}
I am getting what seems to be error 224 (I'm printing "result" into the serial monitor) preceeded by some strange characters (don't know if they're expected)
I've connected Arduino to TTL like this
RX0 to RO
TX1 to DI
D3 to DE
D2 to RE
+5V to VCC
GND to GND
And TTL to Meter
A to A
B to B
using a short twisted pair