Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Arduino source code for KC868-A2]-05 RS485
#1
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);
}


Attached Files
.zip   KC868-A2.zip (Size: 3.15 KB / Downloads: 224)
Reply
#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
#3
if our code work well, you can modify code based on our code.
Reply
#4
(07-12-2024, 12:06 AM)admin Wrote: if our code work well, you can modify code based on our code.

I used the KC868 A2 as a master. With your code, I send "ON" or "OFF" to the Arduino Uno which connects to the KC868 A2 by using TTL to RS485 module.  Arduino Uno has to receive these strings and turn the built-in LED On or Off.. However, the Uno received nothing...
Reply
#5
you can use USB-RS485 cable to debug. whether KC868-A2 have sent out string, use PC serial port debug tool to monitor.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)