RS485_SP485EEN.ino 916 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Description: Use RS485 Unit for serial communication, continuously send "Hello", and display the received content on the screen.
  3. */
  4. #include <M5Stack.h>
  5. #define RX_PIN 16
  6. #define TX_PIN 17
  7. #define X_OFF 160
  8. #define Y_OFF 30
  9. int i=0,s=0;
  10. void header(const char *string, uint16_t color){
  11. M5.Lcd.fillScreen(color);
  12. M5.Lcd.setTextSize(1);
  13. M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLUE);
  14. M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLUE);
  15. M5.Lcd.setTextDatum(TC_DATUM);
  16. M5.Lcd.drawString(string, 160, 3, 4);
  17. }
  18. void setup() {
  19. M5.begin();
  20. M5.Power.begin();
  21. header("RS485 Unit test", TFT_BLACK);
  22. M5.Lcd.setTextFont(2);
  23. M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
  24. Serial.begin(115200);
  25. Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);
  26. }
  27. void loop() {
  28. Serial2.write("Hello\n");
  29. if(Serial2.available()){
  30. M5.Lcd.print(char(Serial2.read()));
  31. }
  32. delay(100);
  33. }