Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Parsing The Data from Rasberry Pi to Arduino for controlling 8 Relay

My project Bidirectional Communicate between Arduino and Rasberry Pi for implementing many AC Applications, sofar the read from Arduino to Rasberry Pi has been solved

The only Problem now is parsing the data receving from the Rasberry Pi to the Arduino Mega, i have follow others guidance but it seem to be a little stuck, currently i had not used the char Parsing method like Robin2 Example 5 from [ Parsing Serial Data and separating it into variables] But using the String lib SubString method to count the byte for getting the data

In Rasberry Pi i have the code like the below:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# yes i could remove the semicolons, i did that for various method testing
Res = re1 +','+ re2 +','+ re3 +','+ re4 +','+ re5 +','+ re6 +','+ re7 +','+ re8
ser.write(b"Res\n")

it will output a series like re1onn,re2off,re3on….re8off

Which i have the following code from the Arduino side

// all the variable has been defined above
 if (Serial.available()) 
  {
    command = Serial.readStringUntil('\n');
    command.trim();
    if (command.substring(0,8) == "re1onn") {
      digitalWrite(re1, LOW);
    } else if (command.substring(0,8) == "re1off") {
      digitalWrite(re1, HIGH);
    }
    if (command.substring(10,18) == "re2on") {
      digitalWrite(re2, LOW);
    } else if (command.substring(10,18) == "re2off") {
      digitalWrite(re2, HIGH);
    }

Can u guys check my method?

Merry Xmas everyone <3

>Solution :

You may send strings like 11111111, 01101111, … etc. where 1 means on and 0 means off and their position represents the relay number.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading