Advertisement
Guest User

Sender

a guest
Dec 1st, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include "EBYTE.h"
  2.  
  3. #define PIN_M0 18 // pin 18 on the ESP
  4. #define PIN_M1 19 // pin 19 on the ESP
  5. #define PIN_AX 21 // pin 21 on the ESP
  6.  
  7. struct DATA {
  8. // due to how 32 bit MCU and 8-bit MCU pack structs
  9. // you will need same data type for everything
  10. // or try EasyTransfer.h
  11. uint16_t Count;
  12. uint16_t Bits34;
  13. uint16_t Bits35;
  14. uint16_t Volts34;
  15. uint16_t Volts35;
  16.  
  17. };
  18.  
  19. DATA MyData;
  20.  
  21.  
  22. // create the transceiver object, passing in the serial and pins
  23. // pin TX2 on ESP32 connect to EBYTE Rx
  24. // pin RX2 on ESP32 connect to EBYTE Tx
  25. EBYTE Transceiver(&Serial2, PIN_M0, PIN_M1, PIN_AX);
  26.  
  27. void setup() {
  28.  
  29. Serial.begin(9600);
  30.  
  31. while (!Serial) {}
  32.  
  33. Serial2.begin(9600);
  34.  
  35. Serial.println("Starting Sender");
  36. while (!Serial) {}
  37. Transceiver.init();
  38. Transceiver.PrintParameters();
  39.  
  40. }
  41.  
  42. void loop() {
  43.  
  44. // measure some data and save to the structure
  45. MyData.Count++;
  46. MyData.Bits34 = analogRead(34);
  47. MyData.Bits35 = analogRead(35);
  48. MyData.Volts34 = MyData.Bits34 * ( 3.3 / 4096.0 ) * 100;
  49. MyData.Volts35 = MyData.Bits35 * ( 3.3 / 4096.0 ) * 100;;
  50.  
  51. Serial2.write((uint8_t*) &MyData, sizeof(MyData));
  52.  
  53.  
  54. // let the use know something was sent
  55. Serial.print("Sending: "); Serial.println(MyData.Count);
  56.  
  57. delay(500);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement