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 frameRS485Serial.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.