Replies: 3 comments
-
No that board is designed to be interfaced with a dev board or ESPHome device where it interfaces to directly using TTL, this integration has been designed to use direct ethernet, TCP Modbus or USB modbus devices which interface easily with home assistant. Nothing is impossible but the amount of work to interface it just wouldn't be credible. |
Beta Was this translation helpful? Give feedback.
-
It looks like that's an ESP32 microprocessor, connected to an RS-485 level converter? If you fancy writing some software which runs on the ESP32 which talks USB and pretends to be a serial device, I'm sure you could make it work. There are probably some Arduino libraries which make it fairly easy. At that point, you could just connect as with any other USB to serial adapter. But, given that you can buy something which already does this for a few dollars, is that really worth the time? |
Beta Was this translation helpful? Give feedback.
-
There's a few options here:
#include <WiFi.h>
#define RX_PIN 4
#define TX_PIN 6
#define DE_PIN 2 // Define the DE pin for RS485
#define RE_PIN 3 // Define the RE pin for RS485
#define BAUDRATE 9600
// wifi config
const char* ssid = "SSID";
const char* password = "PASSWORD";
// ethernet config
const IPAddress local_IP(10, 0, 10, 249);
const IPAddress gateway(10, 0, 10, 1);
const IPAddress subnet(255, 255, 255, 0);
const IPAddress primaryDNS(8, 8, 8, 8);
const IPAddress secondaryDNS(8, 8, 4, 4);
const int serverPort = 502;
#define BUFFER_SIZE 1024
// global objects
WiFiServer server;
byte buff[BUFFER_SIZE];
void setup() {
pinMode(DE_PIN, OUTPUT);
pinMode(RE_PIN, OUTPUT);
digitalWrite(DE_PIN, LOW); // Default to receive mode
digitalWrite(RE_PIN, LOW); // Default to receive mode
// init serial ports
Serial.begin(115200);
Serial1.begin(BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
// init wifi connection
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("Failed to configure network settings");
}
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.printf("connecting to WiFi network %s\n\r", ssid);
delay(500);
}
Serial.println("connected to WiFi");
Serial.print("IP adddr: ");
Serial.println(WiFi.localIP());
delay(1000);
//start server
server = WiFiServer(serverPort);
server.begin();
delay(1000);
Serial.println("server started");
}
void loop() {
// wait for client
WiFiClient client = server.available();
if (!client)
return;
Serial.println("client connected");
while (client.connected()) {
int size = 0;
// read data from wifi client and send to serial
while ((size = client.available())) {
size = (size >= BUFFER_SIZE ? BUFFER_SIZE : size);
client.read(buff, size);
Serial.printf("TCP->SER %d ", size);
for (int i = 0; i < size; i++) {
Serial.printf("0x%02x, ", buff[i]);
}
Serial.println();
// Enable RS485 driver (DE high, RE low) to transmit
digitalWrite(DE_PIN, HIGH);
Serial1.write(buff, size);
Serial1.flush();
// Disable RS485 driver (DE low, RE low) after transmission
digitalWrite(DE_PIN, LOW);
}
// read data from serial and send to wifi client
while ((size = Serial1.available())) {
size = (size >= BUFFER_SIZE ? BUFFER_SIZE : size);
Serial1.readBytes(buff, size);
Serial.printf("TCP<-SER %d ", size);
for (int i = 0; i < size; i++) {
Serial.printf("0x%02x, ", buff[i]);
}
Serial.println();
client.write(buff, size);
client.flush();
}
}
Serial.println("client disconnected");
client.stop();
}
|
Beta Was this translation helpful? Give feedback.
-
Hi, apologies for newbie question, but I'm wondering if this integration could be made to work using an m5stack Atom RS485 to TTL/Wifi converter like this: https://shop.m5stack.com/products/atom-rs485-kit?variant=34787900194980? If so, what would be required to make it work? Thank you!
Beta Was this translation helpful? Give feedback.
All reactions