UART TTL to RS485 Two-way Converter Module + Nodemcu - Projects Networking, Protocols, and Devices - Arduino Forum
UART TTL to RS485 Two-way Converter Module + Nodemcu - Projects Networking, Protocols, and Devices - Arduino Forum
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ı
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
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?
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?
// ESP8266 SoftwareSerial
// https://circuits4you.com/2016/12/14/software-serial-esp8266/
#include <SoftwareSerial.h>
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
horace:
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
sefaguntepe:
9600 - 8 - Even - 1
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
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.
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
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
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
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.
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];
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
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.
sefaguntepe:
Can I see all the data coming from the machine? In my previous work, I could only
see the parameters I set.
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.
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
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
Arduino Uno with RS485 TTL module 6 1.9 bin Haz 2023
Networking, Protocols, and Devices
Back to top
Contact Us Careers
Brand Guidelines