Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Arduino source code for KC868-A2]-05 RS485
#2
Photo 
(03-02-2023, 06:54 AM)KinCony Support Wrote:
Code:
//A2
#define A2_RS485RX  35
#define A2_RS485TX  32
void setup() {
  Serial.begin(115200);
  Serial2.begin(115200,SERIAL_8N1,A2_RS485RX,A2_RS485TX);

   Serial2.println("RS485 SEND is OK!!");
   Serial2.println("******************");
 
}

void loop() {
  /*print the received data of RS485 port*/
  while(Serial2.available()>0)
   {
    Serial2.print((char)Serial2.read());//Read rs485 receive data  and print it
   }
  delay(200);
}

Hello there
I used this example to send "ON" and "OFF" strings to Arduino Uno via TTL to RS485 module. The Arduino Uno code as below.. However, I received nothing.. Can you please help me solve this issue

Code:
#include <SoftwareSerial.h>

#define MCB_ID 1
#define RS_RO 6
#define RS_DI 7
#define RS_DE_RE 8

SoftwareSerial RS_MCB(RS_DI, RS_RO);

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(RS_DE_RE, OUTPUT);
  Serial.begin(9600);
  RS_MCB.begin(9600);
  digitalWrite(RS_DE_RE, LOW);
  Serial.print("RS_MCB is ready..."); 
}

// the loop function runs over and over again forever
void loop() {
  if (RS_MCB.available() > 0)
  {
    String command = "";
   
    while (RS_MCB.available()){
      command += char(RS_MCB.read());
    }
    Serial.flush();
    Serial.print("RS_MCB command = ");
    Serial.println(command);
   
    if(command == 'ON')
    {
      Serial.println("LED ON");
      digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
    }
    else if(command == 'OFF')
    {
      Serial.println("LED OFF");
      digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
    }
  } 
  delay(1000);                      // wait for a second
}
Reply


Messages In This Thread
RE: [Arduino source code for KC868-A2]-05 RS485 - by ktmustafa - 07-11-2024, 05:51 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)