Dear experts,
I have bought an anemometer from China with RS485/MODBUS interface (named 3001-FS). I would like to connct it with my Arduino MEGA.
I have bought additional components to connct it:
- A step-up converter to operate the device at 24V from my 5V power source (and I have confirmed it is working fine and supplying 24V)
- A RS485<->TTL232 converter (type R411A01), which seems to have an autp TX read toggle. I have connected the device at A+/B- and the Arduino at RX/TX at Serial1 (and of course, also 5V and ground)
The device comes with a manual (attached), which provides the parameters of the MODBUS (which gives me a lot of trouble as I am not familiar with MODBUS at all.
I have used the simplemodbusmaster library with the following code:
#include <SimpleModbusMaster.h>
#define baud 9600 // SENSOR SPEC
#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 9 // INDUSTRUINO RS485
// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 1 // SENSOR SPEC
enum
{
PACKET1, // only need 1 type of operation: read wind sensor
TOTAL_NO_OF_PACKETS // leave this last entry
};
// 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()
{
modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 0, 1, 0);
// Initialize the Modbus Finite State Machine
// default SERIAL_8N2 -- wind sensor brochure mentions n,8,1 = 8N1??
modbus_configure(&Serial1, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
// Serial1 = INDUSTRUINO RS485
Serial.begin(9600);
}
void loop()
{
modbus_update(); // send 1 simple Master request to Slave, as defined above
float wind_speed = regs[0] / 10.0;
Serial.print("wind speed (m/s): ");
Serial.println(wind_speed);
delay(3000);
}
I have found a website with a similar device and used that code (Modbus RTU on Industruino IND.I/O | Industruino).
Can somebody please help me to debug this and provide ideas what I can try to get it to work?
Thanks,
MRoggi
test-compressed.pdf (557 KB)