0% found this document useful (0 votes)
12 views1 page

UART TTL to RS485 Two-way Converter Module + Nodemcu - Projects Networking, Protocols, and Devices - Arduino Forum

The document discusses a forum thread about using a UART TTL to RS485 converter module with a NodeMCU for reading and writing data from a CNC machine. Users share code snippets and troubleshooting tips for setting up communication, including baud rate settings and the importance of knowing the communication protocol. The conversation highlights the need for specific commands to retrieve data from the CNC machine and the use of Modbus protocol for communication.

Uploaded by

a.k.y.5yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

UART TTL to RS485 Two-way Converter Module + Nodemcu - Projects Networking, Protocols, and Devices - Arduino Forum

The document discusses a forum thread about using a UART TTL to RS485 converter module with a NodeMCU for reading and writing data from a CNC machine. Users share code snippets and troubleshooting tips for setting up communication, including baud rate settings and the importance of knowing the communication protocol. The conversation highlights the need for specific commands to retrieve data from the CNC machine and the use of Modbus protocol for communication.

Uploaded by

a.k.y.5yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ARDUİNO.

CC PROFESSİONAL EDUCATİON STORE Ara GİRİŞ YAP

UART TTL to RS485 Two-way Converter Module + Nodemcu


Projects Networking, Protocols, and Devices

Konular Custom dashboards, smartphone remote control, data sharing between boards. Get them (for free)
using your forum account!
My Posts

Daha fazla
UART TTL to RS485 Two-way Converter Module +
KATEGORİLER Nodemcu
Projects Networking, Protocols, and Devices
Development Tools
Oca 2023
Projects sefaguntepe Oca 2023 post #1

O!cial Hardware 1 / 17
Hello, I want to read and write data from the CNC machine with the RS485 converter in
Oca 2023
Other Hardware the image. Can anyone share sample code?

Community

International

Deutsch

Español

Français

Italiano
Tüm kategoriler
Tem 2023

11.7 bin 1
görüntüleme bağlantı

horace Karma: 1000+ 2 Oca 2023 post #2

try a web search for arduino rs485 you will get plenty of links plus sample code
you may find information and sample code for a di"erent RS485 breakout module,
e.g.rs-485-arduino-quick-primer 346 , which had two extra pins RE and DE to enable the
transmitter and receiver - you can ignore these
a USB-RS485 dongle for a PC s useful for testing and debugging code
do you have information on the protocol used by the CNC machine?
what Arduino are you planning to use? recommend you use one with hardware serial
ports, e.g. Mega, ESP32, etc

sefaguntepe Oca 2023 post #3

I am currently getting data using the product in the image. However, I think I will get
better performance with the first product I sent. Can I use the same codes?

horace Karma: 1000+ Oca 2023 post #4

the board in the first image should be easier to use as you don't have the pins RE and DE
to enable the transmitter and receiver - I assume that the internal logic of the first board
sorts this out for you
just connect TXD and RXD to your host microctroller and you should be able to transmit
and receive RS485 data with a simple program
what arduino are you using?

sefaguntepe Oca 2023 post #5

I am using ESP8266 12-E


Lib: OTA+MQTT+WifiManager

horace Karma: 1000+ 1 Oca 2023 post #6

try this code

// ESP8266 SoftwareSerial
// https://circuits4you.com/2016/12/14/software-serial-esp8266/

#include <SoftwareSerial.h>

// pins Rx GPIO14 (D5) and Tx GPIO 12 (D6)


SoftwareSerial swSer(14, 12);

void setup() {
Serial.begin(115200); //Initialize hardware serial with baudrate of 115200
swSer.begin(115200); //Initialize software serial with baudrate of 115200
Serial.println("\nESP8266 Software serial test started");
}

void loop() {
while (swSer.available() > 0) { //wait for data at software serial
Serial.write(swSer.read()); //Send data recived from software serial to hardware serial
}
while (Serial.available() > 0) { //wait for data at hardware serial
swSer.write(Serial.read()); //send data recived from hardware serial to software seria
}
}

connect
ESP8266 Rx GPIO14 (D5) to RS485 TXD
ESP8266 Tx GPIO 12 (D6) to RS485 RXD

any idea what is the baudrate of the CDC machine? the above is 115200baud

you should be able to type on the serial monitor to send data over the RS485 link and
see the response

sefaguntepe Oca 2023 post #7

horace:

// pins Rx GPIO14 (D5) and Tx GPIO 12 (D6)


SoftwareSerial swSer(14, 12);

void setup() {
Serial.begin(115200); //Initialize hardware serial with baudrate of 115200
swSer.begin(115200); //Initialize software serial with baudrate of 115200
Serial.println("\nESP8266 Software serial test started");
}

void loop() {
while (swSer.available() > 0) { //wait for data at software serial
Serial.write(swSer.read()); //Send data recived from software serial to hardware serial
}
while (Serial.available() > 0) { //wait for data at hardware serial
swSer.write(Serial.read()); //send data recived from hardware serial to software ser
}
}

9600 - 8 - Even - 1

horace Karma: 1000+ Oca 2023 post #8

sefaguntepe:

9600 - 8 - Even - 1

set the Serial1 baudrate to 9600, e.g.

swSer.begin(9600, SERIAL_8E1); //Initialize software serial with baudrate of9600

sefaguntepe Oca 2023 post #9

Can I see all the data coming from the machine? In my previous work, I could only see
the parameters I set.

2 Yanıt

markd833 Karma: 700+ Oca 2023 post #10

You should be able to see any reply from your CNC machine.

You need to know the serial communication parameters such as baud rate in order to
successfully communicate with the CNC machine.

What communications protocol is used? You need to know this in order to interrogate
your CNC machine and understand the response you get from it.

Post a link to the user guide.

Also, is the image in post #5 your board? Are RXD2 & TXD2 available. If so, you could use
a hardware serial port.

1 Yanıt

horace Karma: 1000+ 1 Oca 2023 post #11

sefaguntepe:

Can I see all the data coming from the machine? In my previous work, I could only
see the parameters I set.

if you know the protocol you send a command and should be able to see the response

Edit: checking the ESP8266softwareserial documentation the baud rate setting should be

swSer.begin(9600, SWSERIAL_8E1); //Initialize software serial with baudrate of9600

sefaguntepe Oca 2023 post #12

markd833:

Also, is the image in post #5 your board? Are RXD2 & TXD2 available. If so, you could
use a hardware serial port.

yes my device

markd833 Karma: 700+ Oca 2023 post #13

The use of an RS485 interface may suggest a protocol such as Modbus. You need to
provide a link to the user guide or photos of the relevant pages from a paper manual if
that is the case.

sefaguntepe Oca 2023 post #14

These codes are for the converter in the second (4 pin) picture I took. I actually want to
convert this code to the converter (RX-TX) one in the first image I shot.
The code I used before:

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <ModbusRTU.h>
#include <SoftwareSerial.h>

char str0[6];

SoftwareSerial S(0, 4);


ModbusRTU mb;

bool cb(Modbus::ResultCode event, uint16_t transactionId, void* data) { // Callback to monitor


if (event != Modbus::EX_SUCCESS) {
Serial.print("Request result: 0x");
Serial.print(event, HEX);
}
return true;
}

void setup() {
Serial.begin(9600);
S.begin(9600, SWSERIAL_8E1);
mb.begin(&S, 16); // RE/DE connected to D0 of ESP8266
mb.master();
}
uint16_t val0[1];

void loop() {
if (!mb.slave()) {
mb.readHreg(2, 8501, val0, 1, cb); // Slave id is 1 and register address is 3926 and

markd833 Karma: 700+ Oca 2023 post #15

Assuming that the code works for the 4 pin RS485 board, then going from a board with
RE & DE signals to an auto switching board should not need any code modifications.

noiasca Oca 2023 post #16

sefaguntepe:

Can I see all the data coming from the machine? In my previous work, I could only
see the parameters I set.

I told you already in

Receiving all data with modbus using Arduino + RS485


Networking, Protocols, and Devices

Hello, I am getting data from CNC machines using MAX485 with Nodemcu. However, I
only get value over the parameter I specified and Slave Id. How can I get all the data
at once? without entering any parameters. Then I will transfer and filter with MQTT. if
(!mb.slave()) { mb.readHreg(2, 2450, val0, 1, cb); // Slave id is 1 and register address is
3926 and //we are reading 2 bytes from the register and saving in val while
(mb.slave()) { // Check if transaction is active …

that with modbus you have to request a register and the amount of values you want to
read starting from that register.

To read more information you send another request with the next register and the
amount of values.

You have to repeat this for all information you want.

Furthermore I told you already to post the datasheet of your device describing the
protocol you want to read.
If you would do so - someone could help you.

6 ay sonra

Kapattı, 20 Tem 2023 tarihinde

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

11.7 bin 1
görüntüleme bağlantı

Yanıtla

İlgili konular

Konu Yanıtlar Görüntüleme Aktivite

How to read RS485 data in arduino


3 24.8 bin Eyl 2020
Networking, Protocols, and Devices

Communicating with sensor over RS485 9 782 Mar 2020


Programming

problems with MAX485 module 10 4.9 bin Kas 2016


General Guidance

TTL to RS485 tranceiver faulty outputs 2 569 Tem 2019


Networking, Protocols, and Devices

Arduino Uno with RS485 TTL module 6 1.9 bin Haz 2023
Networking, Protocols, and Devices

Back to top

Help Center Distributors FOLLOW US

Contact Us Careers

Trademark & Copyright

Brand Guidelines

© 2025 Arduino Terms of Service Privacy Policy Security Cookie Settings

You might also like