Cubecell RS485 Modbus

Hi,
I am trying to read a rs485 sensor with heltec cubecell htcc-ab01, 5v StepUP and RS485 MAX module, but I can’t read the data correctly.
I am trying to use softSerial with GPIO1 and GPIO2 as Tx and Rx pin, but I can’t use write and readBytes with softSerial.
Because I need to interrogate the sensor, with a specific request, to get the data.

Here the code:

#include “softSerial.h”

#define RX GPIO2 //Serial Receive pin
#define TX GPIO1 //Serial Transmit pin
#define RTS_pin GPIO3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
softSerial RS485Serial(RX, TX);
void setup() {

pinMode(RTS_pin, OUTPUT);

// Start the built-in serial port, for Serial Monitor
Serial.begin(115200);
Serial.println(“sensor data”);

// Start the Modbus serial Port, for anemometer
RS485Serial.begin(4800);
pinMode(RTS_pin, OUTPUT);
pinMode(Vext, OUTPUT);
delay(1000);
}

void loop() {

Serial.println(“data*****”);

digitalWrite(RTS_pin, RS485Transmit);
digitalWrite(Vext, LOW); // init Transmit
delay(1000);
byte data_request[] = {0x01, 0x03, 0x00, 0x1E, 0x00, 0x01, 0xE4, 0x0C}; // inquiry frame

RS485Serial.write(data_request, sizeof(data_request));
RS485Serial.flush();

digitalWrite(RTS_pin, RS485Receive); // Init Receive
byte data_buf[8];
RS485Serial.readBytes(data_buf, 8);

Serial.print("data: “);
for( byte i=0; i<7; i++ ) {
Serial.print(data_buf[i], HEX);
Serial.print(” “);
}
Serial.print(” ==> ");
Serial.print(data_buf[4]);
Serial.println();
delay(100);

Serial.println(“data end*****”);

}

Can you help me to make the rigth request to the sensor?
Thank you for your help.

hi,

Could you compare this:
%E5%9B%BE%E7%89%87
%E5%9B%BE%E7%89%87

Tank you @jasonXu, I corrected softSerial variable as

softSerial RS485Serial(GPIO1 /TX pin/, GPIO2 /RX pin/);

but the problem still remain, because I can’t use “write” method and i can’t find other way to send byte array to inquiry the rs485 sensor and read the sensor response.

I am trying to do the same.
In my case the slave device is not configurable to 8N1 for serial communication, only 8E1 is available. the cubecell cant handle 8E1 for now.

as far i know, 8N1 is not the common way for modbus

I thought that CubeCell AB01 only has a hardware serial port, not softSerial, but I am not quite sure. Unfortunately it is hard to find in the documentation.
Regards Achim

hi,

we have some software example.

Hi @jasonXu
After updating the modbus (over RS485) slave device, i am also able to choose the standard serial settings (8N1).

unfortunately it is also not working with the cubecell.
i am using the ModbusMaster library by doc walker.

I have tested my sketch by using the Arduino Mega2560 and it worked fine with it. The same sketch with the cubecell did not work (i tried using serial and serial1 of the cubecell AB-02).

I tried two different transceivers:

  1. CubeCell AB-02 -> MAX13487 -> modbus slave device
  2. CubeCell AB-02 -> MAX485 -> modbus slave device

I always getting an timeout error.

It seems like the serial communication to the transceiver is not working correctly.
Has anyone a clue, what i could try next?

1 Like

I purchased a logic analyzer and did some experiments and finally i got modbus working with the AB-02.

commenting out the line _serial->flush(); in doc walkers library did the trick.
for some reason flushing the transmitting buffer is not working with the cubecell. i dont know if i should put an small delay in the lib instead. Anyway, works also fine without delay (maybe depends on the length of the request).

@DSpada
sorry for misusing your thread. Maybe you could use the HardwareSerial instead.

edit: in my case an pullup (4.7k) on RxD and TxD is needed.

3 Likes

Hi!
Was this problem solved for HTCC-AB01?
Isn’t possible to send and received modbus using this module?
If not, what module would you recommed?
thanks!

Hello,
I’m currently testing RS485 Soil moisture sensor with an adapter RS485 - TTL with the HTCC-AB01. I really need to make this work (already tested with an Arduino NANO). Does someone can help with an example on how to work with software serial and RS485 on the Cubecell AB01?

1 Like

Hello,

I’m trying to connect my new sensor that goes with RS485 protocol. Im trying with AB01 and AB02 but i can’t make it work. Do i need to use the MAX485 modbus adapter? Did anybody know how to do it? Any example code? giveme any clue please.

Thank you!

Yes you actually need a MAX485 adapter. You can follow the example on top of this topic, I have used with some RS485 sensors.