Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RS485 issue
#1
Hi Kincony,
I have bought some of your B4M modules, and try to use the RS485 port.
I try to run the code here: https://www.kincony.com/forum/showthread.php?tid=8934

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* RS485 Communication Test
*
* This program is a simple test for RS485 communication using ESP32-S3.
* It will send a message over RS485 and then read incoming messages.
* The TXD pin is defined as GPIO 18 and RXD pin is defined as GPIO 8.
*/

#include <HardwareSerial.h>

// Define RS485 pins
#define RS485_RXD 39
#define RS485_TXD 38

// Create a hardware serial object
HardwareSerial rs485Serial(1);

void setup() {
  // Start serial communication for debugging
  Serial.begin(115200);
  while (!Serial);

  // Initialize RS485 Serial communication
  rs485Serial.begin(9600, SERIAL_8N1, RS485_RXD, RS485_TXD);
 
 
}

void loop() {
  // Send a test message
  rs485Serial.println("Hello from KinCony B8M!");

  // Wait for a short period
  delay(1000);

  // Check if data is available to read
  if (rs485Serial.available()) {
    String receivedMessage = "";
    while (rs485Serial.available()) {
      char c = rs485Serial.read();
      receivedMessage += c;
    }
    // Print the received message
    Serial.print("Received: ");
    Serial.println(receivedMessage);
  } else
  {
    Serial.println("RS485 is not available");
  }

  // Wait before sending the next message
  delay(2000);
}


but cannot receive the data from RS485 port. The log shows that port is not available.
Can you help me troubleshoot this issue?

Best regards,
Hai Pham
Reply


Messages In This Thread
RS485 issue - by haipt2489 - Today, 11:10 AM
RE: RS485 issue - by admin - Today, 11:12 AM
RE: RS485 issue - by haipt2489 - Today, 11:15 AM
RE: RS485 issue - by admin - 11 hours ago
RE: RS485 issue - by haipt2489 - 11 hours ago
RE: RS485 issue - by admin - 11 hours ago

Forum Jump:


Users browsing this thread:
1 Guest(s)