Advertisement
gaetanopeti

Arduino Rx

Mar 15th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. ///Rx//COM4
  2. #include <SoftwareSerial.h>
  3. SoftwareSerial s(3,2);
  4.  
  5. //Storing variables.
  6. char mystr[6]; //Hello_
  7. char mystr2_rx[10]; //MyFliends_
  8. char n1[1]; //'\n'
  9. char n2[1]; //'\n'
  10.  
  11.  
  12. void setup() {
  13. // Begin the Serial at 9600 Baud
  14. Serial.begin(9600);
  15. s.begin(9600);
  16. }
  17.  
  18. void loop() {
  19.  
  20. char rc;
  21.  
  22. if(s.available()) {
  23. //rc = s.read(); //reading from serial buffer one byte everytime
  24. //Serial.print("The size of rc is: "); Serial.println(rc);
  25.  
  26.  
  27. s.readBytes(mystr,7); //Read the serial data and store in var //including space
  28. //s.readBytes(n1,1); // '\n'
  29. Serial.println(mystr); //Print data on Serial Monitor
  30. //Serial.println(n1); //'\n'
  31. delay(1000);
  32.  
  33.  
  34.  
  35. //Serial.print("rc: "); Serial.println(rc);
  36. s.readBytes(mystr2_rx,11);
  37. //s.readBytes(n2,1); //'\n'
  38. Serial.println(mystr2_rx); //Print data on Serial Monitor
  39. //Serial.println(n2);
  40. delay(1000);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement