Hi.I would appreciate it if you could help me solve my problem.
I'm trying to receive mass flow data from a hydrogen coriolis.(mass flow address :30004 or 0x7534).Im currently using rs485 wth arduino.
This is the code ı'm using:
#include <ModbusMaster.h>
/*!
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 8
#define MAX485_RE_NEG 7
// initiating modbus prject
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);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// Modbus communication runs at 9600 baud
Serial.begin(9600);
// Modbus slave ID 1
node.begin(1, Serial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
bool state = true;
void loop()
{
uint8_t result;
uint16_t data[32];
result = node.writeSingleCoil(0x0002, state);
state = !state;
// Read 16 registers starting at 30000)
result = node.readHoldingRegisters(0x7530,16);
if (result == node.ku8MBSuccess)
{
Serial.print("mass flow: ");
Serial.println(node.getResponseBuffer(0x04)); //flow mass address 30004
Serial.print("temp: ");
Serial.println(node.getResponseBuffer(0x06)); //temperature address 30006
}
Serial.println("\n ------------ \n ");
delay(1000);
}
/*
RS485_HalfDuplex.pde - example using ModbusMaster library to communicate
with EPSolar LS2024B controller using a half-duplex RS485 transceiver.
This example is tested against an EPSolar LS2024B solar charge controller.
See here for protocol specs:
http://www.solar-elektro.cz/data/dokumenty/1733_modbus_protocol.pdf
Library:: ModbusMaster
Author:: Marius Kintel <marius at kintel dot net>
Copyright:: 2009-2016 Doc Walker
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
It seems that you have the RS485 pins on the device connected directly to the pins on the Arduino. If that is the case then it will not work because the two are not compatible
You need a voltage/polarity converter between the two
This is the error ı receive right now.
The odd thing is when ı directly connect device to pc through usb to rs485 converter ı can read data on modbus poll so ı'm assuming there's something wrong with the code.
I cannot tell from your 'photo, which is why a schematic would be more helpful, what exactly is the long board that is connected to the Uno ? What is connected to the two wires on the left of the 'photo ?
30004 is input register, not holding register. 4th register, so 0x03 in hex.
Also, like already mentioned here, you need to use softwareserial with Uno. And not hardwareserial pins.
You said that ı need a voltage/polarity converter but the device is connected to power directly withut arduino so its not poweredby arduino.Do ı still need the voltage converter?