RS485 with Uno communication

Hello, I'm doing a project that needs to connect a display named Samkoon EA-043A with Arduino UNO. I have tried to communicate these 2 devices using RS485 Modbus and tried a sample code. but I have received errors like this.

main

#include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
#include <ArduinoModbus.h>

const int ledPin = LED_BUILTIN;

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

  Serial.println("Modbus RTU Server LED");

  // start the Modbus RTU server, with (slave) id 1
  if (!ModbusRTUServer.begin(1, 9600)) {
    Serial.println("Failed to start Modbus RTU Server!");
    while (1);
  }

  // configure the LED
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  // configure a single coil at address 0x00
  ModbusRTUServer.configureCoils(X01, 1);
}

void loop() {
  // poll for Modbus RTU requests
  ModbusRTUServer.poll();

  // read the current value of the coil
  int coilValue = ModbusRTUServer.coilRead(0x00);

  if (coilValue) {
    // coil value set, turn LED on
    digitalWrite(ledPin, HIGH);
    Serial.println("done");
  } else {
    // coil value clear, turn LED off
    digitalWrite(ledPin, LOW);
  }
}

error

Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"





















C:\Users\User\AppData\Local\Temp\arduino_modified_sketch_354942\ModbusRTUServerLED.ino: In function 'void setup()':

ModbusRTUServerLED:42:34: error: 'X01' was not declared in this scope

   ModbusRTUServer.configureCoils(X01, 1);

                                  ^~~

C:\Users\User\AppData\Local\Temp\arduino_modified_sketch_354942\ModbusRTUServerLED.ino:42:34: note: suggested alternative: 'B01'

   ModbusRTUServer.configureCoils(X01, 1);

                                  ^~~

                                  B01

exit status 1

'X01' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

the button created in the samkoon display with all the details is as followed.

should be "0x01", or just "1"
comment says address 0x00 ??

1 Like

don't mind about the comments, sir. the address In the SATOOL is X01. can I add 0x01 as the Arduino code.

Hi;

 ModbusRTUServer.configureCoils(X01, 1);

should be;

 ModbusRTUServer.configureCoils(0x01, 1);

zero, small x, zero, one

And then it compiles.

Tom... :smiley: :+1: :coffee: :australia:

2 Likes

What pins on the Arduino are you connecting the RS485 to ?

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