If I need to send data from a PC via RS485 and recognize it in the serial monitor of a UNO with an attached IO Expansion Shield For Arduino V5 SKU DFR0088 what might the data format needed to be. I need a simple way to send temperatures say 95-120 to a UNO and have its sketch recognize these values. Eventually, the UNO will monitor a mixing valve's output temp and adjust it via a stepper to keep the output in the range of the temperature being requested. Modbus may be difficult to implement using my PC XOJO software. Currently, if I send a string value from XOJO such as 9 it shows up in the serial monitor as 99, or sending 95 will show up as 99 and 101.
Interesting problem. There are many protocols available, what is the protocol you are using (data format)? What software do you have for the Arduino or do you need to write it? Look at the instructions to see how to post your code. Also post a Schematic, not a frizzy picture of how you have it wired. Links to the hardware items showing technical information always helps as many items although different have the same name.
As a test to see if I had established a connection the data from XOJO was just being sent out as a simple string. XOJO format:
Try
ArduinoSerial.connectArduinoSerial.write SendATextField.Text +Chr(13)+ Chr(10)
Catch error As IOException
MessageBox("The serial connection could not be opened.")
End Try
Not being familiar with RS485 coms I'm wondering if the data needs to be converted to binary and sent a bit at a time. Then converted back to strings.
RS485 doesn't care if you send your data "in binary" or ASCII. RS485 is the physical layer of communication. It will receive the data you send.
After going through your other two RS485 threads: Your shield is not good for learning RS485 communication as it connects to HW Serial (Serial0). So you can't use debug messages in parallel.
Therefore I recommend that you leave away the shield.
Connect your RS485 board with dupont wires to the Uno.
Use the RS485 board together with SoftSerial.
Use Hardware Serial for debug messages to serial monitor.
Start with a simple pass through programm where you just print the received data on the RS485 port to Serial.
If I follow your suggestion, I will need to separate the boards and connect RX output 0 on the shield to some other pin that will be used to creating a software serial port. Any particular pin for this port? I will need to do some research to figure out how to set up a soft serial port. I take it the serial monitor is tied to a hard-wired serial port, so you need to have the RS485 coms be on the soft serial port. Is this correct?
Hello cliffcoulter
If do you have an Arduino Mega available you can brew a smart Protocol Analyzer for yourself. A small sketch to change the baudrate can help at the first step.
Have a nice day and enjoy coding in C++.
with SoftSerial you can use free pins.
avoid 0 and 1 - because it is used for HW Serial.
avoid 13 ... it could interfere with the built in LED.
Most examples just start with pins 2 and 3
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
and don't forget to keep the baudrate low for Softserial.
I felt you were giving me just what I needed to move forward and excited about giving it a go today. After separating the shield and bringing PWR and GND from the UNO over to the shield I have not been able to get the shield to respond. Not even a reset on the shield which would normally blink it's reset light. Some requirement for the shield is missing and the info I find about the shield is sketchy at best to me. If it is obvious to you what might be missing that would be great but if not do you have another suggestion for a replacement RS485 shield that would work better for my application?
No, it doesn't, so I ordered a few. While I'm waiting, I removed the RX pin from the shield and will jumper it over to the softserial input port as you suggested. Hopefully a work around for today.
Should this basic Sketch be enough to test a software serial port? I don't even see the "Hello World" in the serial monitor.
> #include <SoftwareSerial.h>
>
> SoftwareSerial mySerial(2, 3); // RX, TX
>
> void setup()
> {
> // set the data rate for the SoftwareSerial port
> mySerial.begin(9600);
> mySerial.println("Hello, world?");
> }
>
> void loop() // run over and over
> {
> if (mySerial.available())
> mySerial.println(mySerial.read());
> }
I would add a delay, you could easily flood the serial system. Also what is it connected to. A schematic would help a lot.
Have you connected a TTL-USB converter to pin 2 and 3 to see what happens on Soft Serial?
because this makes not so much sense:
mySerial.println(mySerial.read());
you print to pin 3 what you have received at pin 2.
a simple pass through sketch to mirrow traffic from SoftSerial to Serial could look like following.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop()
{
if (mySerial.available())
Serial.println(mySerial.read());
}
This program could print Hello World? to SoftSerial but keep in mind, that in RS485 you have to enable DE/RE lines to send. So low level wise - this message will not be sent over RS485 without further code.
By serial monitor, do you mean the Arduino IDE? Your sketch prints to your software serial port, not the hardware serial port that the IDE is monitoring. You need to monitor the software serial port using a terminal program and a TTL-USB serial adapter as @noiasca has said.
I just wanted to thank you all for helping get me started on this project. After receiving RS485 coms module I was able to set up a software serial port and can now send commands from XOJO on my Mac. Part of that problem was resolved when I determined the data being sent was being received in decimal and not ASCII which was resolved by using "mySerial.readString()" instead of "mySerial.read()". I can now position a linear stepper motor with a TMC2208 driver and monitor temperatures with a LM35. Eventually this will control water temperatures with a remote mixing valve for a hydronic heating system. And you're right, Arduino IDE. Thanks again for your patients.
