Advertisement
safwan092

R200_simple_read_arduino_uno

Jan 12th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. unsigned char ReadMulti[10] = {0XAA, 0X00, 0X27, 0X00, 0X03, 0X22, 0XFF, 0XFF, 0X4A, 0XDD};
  2. unsigned int timeSec = 0;
  3. unsigned int timemin = 0;
  4. unsigned int dataAdd = 0;
  5. unsigned int incomedate = 0;
  6. unsigned int parState = 0;
  7. unsigned int codeState = 0;
  8.  
  9. void setup() {
  10. pinMode(LED_BUILTIN, OUTPUT);
  11. Serial.begin(115200);
  12. Serial.println("Hello world.");
  13. Serial.write(ReadMulti, 10);
  14. }
  15.  
  16. void loop() {
  17. timeSec ++ ;
  18. if (timeSec >= 50000) {
  19. timemin ++;
  20. timeSec = 0;
  21. if (timemin >= 20) {
  22. timemin = 0;
  23. digitalWrite(LED_BUILTIN, HIGH);
  24. Serial.write(ReadMulti, 10);
  25. digitalWrite(LED_BUILTIN, LOW);
  26. }
  27. }
  28. if (Serial.available() > 0) {
  29. incomedate = Serial.read();
  30. if ((incomedate == 0x02) & (parState == 0)) {
  31. parState = 1;
  32. }
  33. else if ((parState == 1) & (incomedate == 0x22) & (codeState == 0)) {
  34. codeState = 1;
  35. dataAdd = 3;
  36. }
  37. else if (codeState == 1) {
  38. dataAdd ++;
  39. if (dataAdd == 6) {
  40. Serial.print("RSSI:");
  41. Serial.println(incomedate, HEX);
  42. }
  43. else if ((dataAdd == 7) | (dataAdd == 8)) {
  44. if (dataAdd == 7) {
  45. Serial.print("PC:");
  46. Serial.print(incomedate, HEX);
  47. }
  48. else {
  49. Serial.println(incomedate, HEX);
  50. }
  51. }
  52. else if ((dataAdd >= 9) & (dataAdd <= 20)) {
  53. if (dataAdd == 9) {
  54. Serial.print("EPC:");
  55. }
  56. Serial.print(incomedate, HEX);
  57. }
  58. else if (dataAdd >= 21) {
  59. Serial.println(" ");
  60. dataAdd = 0;
  61. parState = 0;
  62. codeState = 0;
  63. }
  64. }
  65. else {
  66. dataAdd = 0;
  67. parState = 0;
  68. codeState = 0;
  69. }
  70. }
  71.  
  72. }//end of LOOP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement