Using RS485 with an analog voltage sampler (R4AVA07)

Hi! I have a loadcell that i'm trying to collect analog data from to display on my serial monitor. I have a analog voltage sampler that I want to use to convert the voltage to digital data. I also have a RS485 connected to communicate with the voltage sampler. This setup seemed pretty straightforward to me, however, i haven't been able to get it to work. I am simply trying to read data from the rs485 on my arduino and print it on serial, but I don't see anything but -1 printed on my screen.

I haven't been able to find a lot of resources on this. Would anybody be able to help me out!

Thanks in advance!

Sure, please see How to get the best out of this forum and particularly "Hardware" and "Code Problems".

Some very good suggestions here

Also
have a look on ebay for a usb to rs485 for use while testing eg

You would likely get more help if you provided links to datasheets for the device(s) you are using.

I did a quick google search for R4AVA07. the first hit took me here.

If that device looks like the one you have, then it suggests that you need to talk to it using the modbus serial comms protocol.

The information in that link suggest 9600,8,N,1 as the default serial parameters.

The page in that link also gives several examples of the sequence of bytes (the raw modbus message). It uses the phrase send data or send frame.

If you are going to use Modbus, then you can either use predefined messages (a simple array of bytes) or one of the Modbus libraries.

When working with RS485, one of the cheap USB-RS485 adapters can be a really useful tool to have when debugging.

Have a search of the forum for "NPK sensor". It's a soil sensor that pops up here quite frequently with many people starting out with canned (array of bytes) messages.

Hello! I stumbled upon the same page after typing out my question. I tried using the raw Modbus messages in the link but couldn't get any success with that. I'll try looking into the libraries next.

#include <SoftwareSerial.h>

#define RX_PIN 2
#define TX_PIN 3

SoftwareSerial rs485(RX_PIN, TX_PIN);

void setup() {
  Serial.begin(9600);
  rs485.begin(9600);

}

void loop() {
  rs485.write("FF 03 00 0E 00 01 F0 17");
  delay(100);
  
  Serial.println(rs485.read());
  
}

Would appreciate it if you could take a look at my code. My communication line right now is only the R4AVA07 Modbus and the rs485 for the master Arduino.

Can you also elaborate on the default serial parameters? What do the 8, N, and the 1 describe?

Thanks!

A quick reply as i'm on a small screen at the moment.

8,N,1 refers to 8 data bits, no parity and 1 stop bit.

You need to control the tx/rx state of the MAX485 chip (on your RS485 interface module). The RS485 library may do that for you but you need to specify which i/o pins to use.

Modbus is binary data, so you will need to send an array of bytes, e.g.

  byte request [8] = {0xFF, 0x03, 0x00, 0x0E, 0x00, 0x01, 0xF0, 0x17};
  rs485.write(request, sizeof(request));

As has already been mentioned, you need to send an array of bytes rather than an ASCII string of characters.

I can't get back into that web page I found earlier - at least not past page 1. I've looked further (briefly) and I can't locate a user manual for your R4AVA07.

You need to request the user manual from the supplier as it will detail all the information you would need to be able to communicate with the board.

Although that sequence of bytes is a valid modbus message, the first byte is usually 01 (as it is the slave device address). If you do change any part of that message, then the CRC16 checksum in the last 2 bytes will be incorrect and you will need to recalculate it.

Note that the ArduinoRS485 library is mainly for use with the MKR series of boards.

You've not said which Arduino board you are using.

This is super helpful to know. Thank you! Now I'm able to receive data from the R4AVA07, but I'm struggling to interpret this information. I'm using an Arduino UNO. I'm supplying 3.3V across the ground and A1 pins of the R4AVA07. The data I'm seeing on serial is a pattern that repeats like (1, 3, 2, 1, 77, 121, 225). After repeating this several times, it turns into just 1s.

I don't understand why the pattern changes. I'm looping the command to receive voltage data which is (byte request [8] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};). Shouldn't I see the same pattern received? And do you guys know how I can change that data to ASCII again, like it's given in the manual, to convert it to the voltage reading?

I was able to access the full manual here

Update! I managed to interpret the reading and convert to voltage print out on the serial. Now i'm trying to figure out how to switch readings between the different analog pins on the R4AVA07. All I've done so far has been on the A1 pins, but for my project I will be using more than one pins. So I want to be able to alternate which one I'm getting a reading from.

Looking at the datasheet, I see I can switch by changing the register address in my command. But anything other than "0x00 0x00" won't return any data.

Here's my updated code:

#include <SoftwareSerial.h>

#define RX_PIN 2
#define TX_PIN 3
int hex[] = {256,1};

SoftwareSerial rs485(RX_PIN, TX_PIN);

void setup() {
  Serial.begin(9600);
  rs485.begin(9600);
}

void loop() {
  Serial.print(readVoltage());
  Serial.println("V");
  delay(100);
}

float readVoltage(){
  byte request [8] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
  rs485.write(request, sizeof(request));
  delay(1000);
  
  int adress = rs485.read();
  int function = rs485.read();
  int n = rs485.read();
  int i = 0;
  int data = 0;
  
  while (i<n){
    data = data + rs485.read()*hex[i] ;
    i=i+1;
  }
  
  int CRC16 = rs485.read() + rs485.read();
  
  float voltage = data/100.0; 
  return voltage;
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.