Hello i really need some help, i am trying to send some simple data from an Arduino acting as a master to some software acting as the slave. I am currently using Modbus poll to read the data that is being transmitted from the Arduino but i am having some errors.
I am using some example code found online which incorporates the ModbusMaster.h library in order to send data to a holding register. I want to send a binary 1 to the register from the Arduino in order to use this as a trigger in my software.
I am confident that my hardware is configured in the right way as i am seeing expected results when pressing the push button (writes to LCD correctly & Modbuspoll receives some kind of data). I have digital inputs connected to the DE & RE Pins on the Rs 485 and the Arduino RX & TX connected to DI & RO. I then have the A+ and B- connected to the respective terminals on the Rs485 IC to the SH-U10 USB converter.
My problem feels like it is within the software side of the project, when i compile my code which isn't much different from the example code i found online, i am receiving an error;
warning: large integer implicitly truncated to unsigned type [-Woverflow]
node.writeSingleRegister(0x40001, 1);
But the code still compiles and let's me upload to Arduino device.
I open modbus poll to see if the data has been transmitted correctly i get an error when i push the button, the LCD prints S1: High but modbus poll shows
"insufficient bytes received"
The Arduino IDE serial monitor also show's 3-4 square boxes and a weird character, not the information expected to be transmitted. I am quite frankly not sure what is going wrong here as the code is identical to the example and people have been able to get that working fine, it just seems like my byte data being trasmitted isn't correct. Any help would be gratefully appreciated and Thankyou in advance!
The hardware i'm using;
Arduino Uno
5V TTL to Rs485 Module
SH-U10 USB to RS485 Converter
Push Button
LCD
The code i'm using:
#include <ModbusMaster.h>
#include <LiquidCrystal.h>
#define MAX485_DE 9
#define MAX485_RE_NEG 3
ModbusMaster node;
LiquidCrystal lcd(8, 2, 4, 5, 6, 7);
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
const int button1 = 10;
const int button2 = 11;
const int button3 = 12;
const int button4 = 13;
void setup() {
lcd.begin(14, 2);
pinMode(button3, INPUT);
pinMode(MAX485_RE_NEG, OUTPUT); //declaring pinmode output for max485
pinMode(MAX485_DE, OUTPUT); //declaring pinmode output for max485
lcd.print("Welcome!");
delay(1000);
lcd.clear();
lcd.print("Project Simulation");
delay(1000);
digitalWrite(MAX485_RE_NEG, 0); //initialise
digitalWrite(MAX485_DE, 0); //initialise
Serial.begin(9600);
node.begin(1, Serial); //Slave ID as 1
node.preTransmission(preTransmission); //Callback for configuring RS-485 Transreceiver correctly
node.postTransmission(postTransmission);
}
void loop() {
int a = digitalRead(button3);
if (a == 1)
{
node.writeSingleRegister(0x40001, 1);
lcd.setCursor(0, 1);
lcd.print("S1: HIGH");
}
}