From f2c99a11b20a055c3cc49cfdca5eb8309d2a6aae Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Fri, 17 Apr 2020 14:32:24 +0200 Subject: [PATCH 1/3] Support atmelsam devices, WIP #8 --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 70ad59f..1f4f9ee 100644 --- a/README.md +++ b/README.md @@ -232,8 +232,9 @@ See issue [#4][GH4] for inspiration. PRs are welcomed. ## Changelog - Work in progress - - Support the PMS5003 S/ST/T variants [#10][GH10] - - Use Serial1 as "SoftwareSerial" for ESP32, [#7][GH7] + - Support `atmelsam` devices [#8][GH8]/[PR12][] + - Support the PMS5003 S/ST/T sensors [#10][GH10] + - Use Serial1 as "SoftwareSerial" for ESP32, [#7][GH7]/[PR9][] - 1.0.1 - Fix broken SoftwareSerial for ESP8266, [#6][GH6] - ESP8266 use EspSoftwareSerial@>=6.7.1 @@ -242,4 +243,7 @@ See issue [#4][GH4] for inspiration. PRs are welcomed. [GH6]: https://github.com/avaldebe/PMserial/issues/6 [GH7]: https://github.com/avaldebe/PMserial/issues/7 +[GH8]: https://github.com/avaldebe/PMserial/issues/8 +[PR9]: https://github.com/avaldebe/PMserial/pull/9 [GH10]: https://github.com/avaldebe/PMserial/issues/10 +[PR12]: https://github.com/avaldebe/PMserial/pull/12 From 4e2385f90105c5cdd484ad99f4983fb73d620af3 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Fri, 17 Apr 2020 15:48:46 +0200 Subject: [PATCH 2/3] add mkrwifi1010 board, #8 --- .vscode/settings.json | 2 ++ examples/HardwareSerial/README.md | 18 ++++++++++++++++++ examples/HardwareSerial/platformio.ini | 5 +++++ examples/debug/README.md | 1 + examples/debug/platformio.ini | 5 +++++ 5 files changed, 31 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 440ac7d..bc1e618 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,9 +19,11 @@ "megaatmega", "mhetesp", "minikit", + "mkrwifi", "nbar", "nbin", "rhum", + "samd", "uint" ] } \ No newline at end of file diff --git a/examples/HardwareSerial/README.md b/examples/HardwareSerial/README.md index bf41d63..fc765ac 100644 --- a/examples/HardwareSerial/README.md +++ b/examples/HardwareSerial/README.md @@ -152,3 +152,21 @@ platformio run -e esp32minikit -t upload # open serial monitor platformio run -e esp32minikit -t monitor ``` + +## Arduino `mkrwifi1010` + +**Note** This is a 3.3V board, and the PMS5003 requires 5V. +You need provide 5V for the fan to operate properly. + +- Serial1 on pins 13 (RX) and 14 (TX). + +```bash +# compile +platformio run -e mkrwifi1010 + +# upload +platformio run -e mkrwifi1010 -t upload + +# open serial monitor +platformio run -e mkrwifi1010 -t monitor +``` \ No newline at end of file diff --git a/examples/HardwareSerial/platformio.ini b/examples/HardwareSerial/platformio.ini index 22c4d72..0ef125d 100644 --- a/examples/HardwareSerial/platformio.ini +++ b/examples/HardwareSerial/platformio.ini @@ -48,3 +48,8 @@ board = esp01 platform = espressif32 board = mhetesp32minikit build_flags = -D USE_HWSERIAL2 + +[env:mkrwifi1010] +platform = atmelsam +board = mkrwifi1010 +build_flags = -D USE_HWSERIAL1 \ No newline at end of file diff --git a/examples/debug/README.md b/examples/debug/README.md index 1f540de..751ba34 100644 --- a/examples/debug/README.md +++ b/examples/debug/README.md @@ -10,6 +10,7 @@ with calls to some special debugging methods. ## Boards tested - AVR: `uno`, `leonardo`, `megaatmega2560` +- SAMD: `mkrwifi1010` - STM32: `bluepill_f103c8`, `maple_mini_b20` - ESP8266: `esp01`, `esp01_1m`, `d1_mini` - ESP32: `mhetesp32minikit`, `m5stack-core-esp32` diff --git a/examples/debug/platformio.ini b/examples/debug/platformio.ini index d2df58b..3a91586 100644 --- a/examples/debug/platformio.ini +++ b/examples/debug/platformio.ini @@ -76,3 +76,8 @@ build_flags = -D PMS_RX=23 -D PMS_TX=19 ; esp32 (1.25Mb) platform = espressif32 board = m5stack-core-esp32 + +[env:mkrwifi1010] +platform = atmelsam +board = mkrwifi1010 +build_flags = -D USE_HWSERIAL1 \ No newline at end of file From b6e5df31c369695d8568ac95373333b5a91776c2 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Fri, 17 Apr 2020 19:12:37 +0200 Subject: [PATCH 3/3] update example info --- .vscode/settings.json | 5 ++ README.md | 20 +++--- examples/HardwareSerial/README.md | 84 +++++++++++++++++++++----- examples/HardwareSerial/platformio.ini | 2 +- examples/SoftwareSerial/README.md | 71 ++++++++++++++++++---- examples/SoftwareSerial/platformio.ini | 2 +- 6 files changed, 146 insertions(+), 38 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bc1e618..dfb35d9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ "CKSUM", "HCHO", "HWSERIAL", + "Hzatmega", "MCU", "PMSA", "PMSerial", @@ -11,6 +12,8 @@ "SERIALPM", "UART", "USART", + "atmelavr", + "atmelsam", "bluepill", "chlen", "datasheet", @@ -24,6 +27,8 @@ "nbin", "rhum", "samd", + "stlink", + "ststm", "uint" ] } \ No newline at end of file diff --git a/README.md b/README.md index 1f4f9ee..a48acc1 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ The sensor type inference does not cover the `PMS5003S` and `PMS5003T` variants, ### PMSx003 on HardwareSerial -```arduino +```c++ #include SerialPM pms(PMSx003, Serial); // PMSx003, UART @@ -83,7 +83,7 @@ Setup for different MCU is covered on the [HardwareSerial][] example. ### PMSx003 on SoftwareSerial -```arduino +```c++ #include SerialPM pms(PMSx003, 10, 11); // PMSx003, RX, TX @@ -108,30 +108,30 @@ Setup for different MCU is covered on the [SoftwareSerial][] example. On some ESP32 boards Serial1 default pins are connected to the flash. Using the standard constructor will cause a crash, see [espressif/arduino-esp32#148](https://github.com/espressif/arduino-esp32/issues/148). -```Arduino +```c++ // will crash the ESP32 SerialPM pms(PMSx003, Serial1); -```` +``` Fortunately, it is possible to define alternative for pins by calling: -```Arduino +```c++ // define Serial1 pins Serial1.begin(9600, SERIAL_8N1, , ); ``` The PMSerial library uses this feature to implement the flexibility of SoftwareSerial -```Arduino +```c++ // define Serial1 pins SerialPM pms(PMSx003, , ); -```` +``` The [SoftwareSerial example][esp32hw] uses Serial1 on pins 23 (RX) and 19 (TX). The [HardwareSerial example][esp32hw] uses Serial2. -[esp32hw]: examples/HardwareSerial/README.md#mhetesp32minikit -[esp32sw]: examples/SoftwareSerial/README.md#mhetesp32minikit +[esp32hw]: examples/HardwareSerial/README.md#esp32-minikit +[esp32sw]: examples/SoftwareSerial/README.md#esp32-minikit ## Advanced usage @@ -215,7 +215,7 @@ The available status/error codes and pre-defined error messages are: For easy of use, the error message are pre-defined with `#define`. See the [examples](examples/) for error handling implementation. -## Contribute back +## Contribute If you have read this far, this is the library for your project or you can not figure out how to use it. In any case, I can use your help. diff --git a/examples/HardwareSerial/README.md b/examples/HardwareSerial/README.md index fc765ac..114b6a7 100644 --- a/examples/HardwareSerial/README.md +++ b/examples/HardwareSerial/README.md @@ -2,13 +2,21 @@ Read PMS5003 sensor on Serial/Serial1/Serial2, depending on the board. -## Arduino `leonardo` +## [Arduino Leonardo](https://docs.platformio.org/en/latest/boards/atmelavr/leonardo.html) **Note** This is a 5V board, and the PMS5003 RX/TX pins are 3.3V. You need to add a logic level converter, or use a 3.3V version of this board. - Serial1 on pins 0 (RX) and 1 (TX). +```ini +[env:leonardo] +framework = arduino +platform = atmelavr +board = leonardo +build_flags = -D USE_HWSERIAL1 +``` + ```bash # compile platformio run -e leonardo @@ -20,7 +28,7 @@ platformio run -e leonardo -t upload platformio run -e leonardo -t monitor ``` -## Arduino `mega2560` +## [Arduino Mega 2560](https://docs.platformio.org/en/latest/boards/atmelavr/megaatmega2560.html) **Note** This is a 5V board, and the PMS5003 RX/TX pins are 3.3V. You need to add a logic level converter, or use a 3.3V version of this board. @@ -31,6 +39,14 @@ You need to add a logic level converter, or use a 3.3V version of this board. This example uses Serial1. +```ini +[env:mega2560] +framework = arduino +platform = atmelavr +board = megaatmega2560 +build_flags = -D USE_HWSERIAL1 +``` + ```bash # compile platformio run -e mega2560 @@ -42,7 +58,7 @@ platformio run -e mega2560 -t upload platformio run -e mega2560 -t monitor ``` -## STM32 `genericSTM32F103C8` +## [STM32F103C8](https://docs.platformio.org/en/latest/boards/ststm32/genericSTM32F103C8.html) **Note** This is a 3.3V board, and the PMS5003 requires 5V. You need provide 5V for the fan to operate properly. @@ -53,6 +69,15 @@ You need provide 5V for the fan to operate properly. This example uses Serial1. +```ini +[env:genericSTM32F103C8] +framework = arduino +platform = ststm32 +board = genericSTM32F103C8 +upload_protocol = stlink +build_flags = -D USE_HWSERIAL1 +``` + ```bash # compile platformio run -e genericSTM32F103C8 @@ -64,7 +89,7 @@ platformio run -e genericSTM32F103C8 -t upload platformio run -e genericSTM32F103C8 -t monitor ``` -## STM32 `maple_mini` +## [STM32 Maple Mini](https://docs.platformio.org/en/latest/boards/ststm32/maple_mini_b20.html) **Note** This is a 3.3V board, and the PMS5003 requires 5V. You need provide 5V for the fan to operate properly. @@ -75,6 +100,14 @@ You need provide 5V for the fan to operate properly. This example uses Serial2. +```ini +[env:maple_mini] +framework = arduino +platform = ststm32 +board = maple_mini_b20 +build_flags = -D USE_HWSERIAL2 +``` + ```bash # compile platformio run -e maple_mini @@ -86,7 +119,7 @@ platformio run -e maple_mini -t upload platformio run -e maple_mini -t monitor ``` -## ESP8266 `esp01` +## [ESP8266 ESP-01 512k](https://docs.platformio.org/en/latest/boards/espressif8266/esp01.html) **Note** This is a 3.3V board, and the PMS5003 requires 5V. @@ -96,6 +129,13 @@ This example used Serial for communicating with the sensor and printing the sensor values. Some garbage between printouts is to be expected. +```ini +[env:esp01] +framework = arduino +platform = espressif8266 +board = esp01 +``` + ```bash # compile platformio run -e esp01 @@ -107,7 +147,7 @@ platformio run -e esp01 -t upload platformio run -e esp01 -t monitor ``` -## ESP32 `mhetesp32minikit` +## [ESP32 MiniKit](https://docs.platformio.org/en/latest/boards/espressif32/mhetesp32minikit.html) **Note** This is a 3.3V board, and the PMS5003 requires 5V. You need provide 5V for the fan to operate properly. @@ -118,29 +158,37 @@ You need provide 5V for the fan to operate properly. On some ESP32 boards Serial1 default pins are connected to the flash. Using the standard constructor will cause a crash, see [espressif/arduino-esp32#148](https://github.com/espressif/arduino-esp32/issues/148). -```Arduino +```c++ // will crash the ESP32 SerialPM pms(PMSx003, Serial1); -```` +``` Fortunately, it is possible to define alternative for pins by calling: -```Arduino +```c++ // define Serial1 pins Serial1.begin(9600, SERIAL_8N1, , ); ``` The PMSerial library uses this feature to implement the flexibility of SoftwareSerial -```Arduino +```c++ // define Serial1 pins SerialPM pms(PMS5003, , ); -```` +``` The [SoftwareSerial example][esp32sw] uses Serial1 on pins 23 (RX) and 19 (TX). This example uses Serial2. -[esp32sw]: ../SoftwareSerial/README.md#mhetesp32minikit +[esp32sw]: ../SoftwareSerial/README.md#esp32-minikit + +```ini +[env:esp32minikit] +framework = arduino +platform = espressif32 +board = mhetesp32minikit +build_flags = -D USE_HWSERIAL2 +``` ```bash # compile @@ -153,13 +201,21 @@ platformio run -e esp32minikit -t upload platformio run -e esp32minikit -t monitor ``` -## Arduino `mkrwifi1010` +## [Arduino MKR WiFi 1010](https://docs.platformio.org/en/latest/boards/atmelsam/mkrwifi1010.html) **Note** This is a 3.3V board, and the PMS5003 requires 5V. You need provide 5V for the fan to operate properly. - Serial1 on pins 13 (RX) and 14 (TX). +```ini +[env:mkrwifi1010] +framework = arduino +platform = atmelsam +board = mkrwifi1010 +build_flags = -D USE_HWSERIAL1 +``` + ```bash # compile platformio run -e mkrwifi1010 @@ -169,4 +225,4 @@ platformio run -e mkrwifi1010 -t upload # open serial monitor platformio run -e mkrwifi1010 -t monitor -``` \ No newline at end of file +``` diff --git a/examples/HardwareSerial/platformio.ini b/examples/HardwareSerial/platformio.ini index 0ef125d..621c48a 100644 --- a/examples/HardwareSerial/platformio.ini +++ b/examples/HardwareSerial/platformio.ini @@ -44,7 +44,7 @@ build_flags = -D USE_HWSERIAL2 platform = espressif8266 board = esp01 -[env:mhetesp32minikit] +[env:esp32minikit] platform = espressif32 board = mhetesp32minikit build_flags = -D USE_HWSERIAL2 diff --git a/examples/SoftwareSerial/README.md b/examples/SoftwareSerial/README.md index 489f646..ad9f30e 100644 --- a/examples/SoftwareSerial/README.md +++ b/examples/SoftwareSerial/README.md @@ -2,13 +2,20 @@ Read PMS5003 sensor on SWSerial -## Arduino `uno` +## [Arduino Uno](https://docs.platformio.org/en/latest/boards/atmelavr/uno.html) **Note** This is a 5V board, and the PMS5003 RX/TX pins are 3.3V. You need to add a logic level converter, or use a 3.3V version of this board. - SWSerial on pins 10 (RX) and 11 (TX). +```ini +[env:uno] +framework = arduino +platform = atmelavr +board = uno +``` + ```bash # compile platformio run -e uno @@ -20,7 +27,7 @@ platformio run -e uno -t upload platformio run -e uno -t monitor ``` -## Arduino `mini168_3V3` +## [Arduino Pro Mini (ATmega168, 3.3V, 8 MHz)](https://docs.platformio.org/en/latest/boards/atmelavr/pro8MHzatmega168.html) 3.3V/8Mhz version of the pro mini board with an ATmega168. **Note** This is a 3.3V board, and the PMS5003 requires 5V. @@ -28,6 +35,13 @@ You need provide 5V for the fan to operate properly. - SWSerial on pins 10 (RX) and 11 (TX). +```ini +[env:mini168_3V3] +framework = arduino +platform = atmelavr +board = pro8MHzatmega168 +``` + ```bash # compile platformio run -e mini168_3V3 @@ -39,7 +53,7 @@ platformio run -e mini168_3V3 -t upload platformio run -e mini168_3V3 -t monitor ``` -## Arduino `mini328_3V3` +## [Arduino Pro Mini (ATmega328, 3.3V, 8 MHz)](https://docs.platformio.org/en/latest/boards/atmelavr/pro8MHzatmega328.html) 3.3V/8Mhz version of the pro mini board with an ATmega328. **Note** This is a 3.3V board, and the PMS5003 requires 5V. @@ -47,6 +61,13 @@ You need provide 5V for the fan to operate properly. - SWSerial on pins 10 (RX) and 11 (TX). +```ini +[env:mini328_3V3] +framework = arduino +platform = atmelavr +board = pro8MHzatmega328 +``` + ```bash # compile platformio run -e mini328_3V3 @@ -58,7 +79,7 @@ platformio run -e mini328_3V3 -t upload platformio run -e mini328_3V3 -t monitor ``` -## ESP8266 `esp01` +## [ESP8266 ESP-01 512k](https://docs.platformio.org/en/latest/boards/espressif8266/esp01.html) **Note** This is a 3.3V board, and the PMS5003 requires 5V. @@ -67,6 +88,15 @@ platformio run -e mini328_3V3 -t monitor [issue6]: https://github.com/avaldebe/PMserial/issues/6 +```ini +[env:esp01] +framework = arduino +platform = espressif8266 +lib_deps = EspSoftwareSerial@>=6.7.1 +board = esp01 +build_flags = -D PMS_RX=2 -D PMS_TX=0 +``` + ```bash # compile platformio run -e esp01 @@ -78,13 +108,22 @@ platformio run -e esp01 -t upload platformio run -e esp01 -t monitor ``` -## ESP8266 `d1_mini` +## [WeMos D1 mini](https://docs.platformio.org/en/latest/boards/espressif8266/d1_mini.html) **Note** This is a 3.3V board, and the PMS5003 requires 5V. - SWSerial on pins GPIO13/D7 (RX) and GPIO12/D6 (TX). - Needs [EspSoftwareSerial@>=6.7.1][issue6] +```ini +[env:d1_mini] +framework = arduino +platform = espressif8266 +lib_deps = EspSoftwareSerial@>=6.7.1 +board = d1_mini +build_flags = -D PMS_RX=D7 -D PMS_TX=D6 +``` + ```bash # compile platformio run -e d1_mini @@ -96,7 +135,7 @@ platformio run -e d1_mini -t upload platformio run -e d1_mini -t monitor ``` -## ESP32 `mhetesp32minikit` +## [ESP32 MiniKit](https://docs.platformio.org/en/latest/boards/espressif32/mhetesp32minikit.html) **Note** This is a 3.3V board, and the PMS5003 requires 5V. You need provide 5V for the fan to operate properly. @@ -107,29 +146,37 @@ You need provide 5V for the fan to operate properly. On some ESP32 boards Serial1 default pins are connected to the flash. Using the standard constructor will cause a crash, see [espressif/arduino-esp32#148](https://github.com/espressif/arduino-esp32/issues/148). -```Arduino +```c++ // will crash the ESP32 SerialPM pms(PMSx003, Serial1); -```` +``` Fortunately, it is possible to define alternative for pins by calling: -```Arduino +```c++ // define Serial1 pins Serial1.begin(9600, SERIAL_8N1, , ); ``` The PMSerial library uses this feature to implement the flexibility of SoftwareSerial -```Arduino +```c++ // define Serial1 pins SerialPM pms(PMS5003, , ); -```` +``` This example uses Serial1 on pins 23 (RX) and 19 (TX). The [HardwareSerial example][esp32hw] uses Serial2 directly. -[esp32hw]: ../HardwareSerial/README.md#mhetesp32minikit +[esp32hw]: ../HardwareSerial/README.md#esp32-minikit + +```ini +[env:esp32minikit] +framework = arduino +platform = espressif32 +board = mhetesp32minikit +build_flags = -D PMS_RX=23 -D PMS_TX=19 +``` ```bash # compile diff --git a/examples/SoftwareSerial/platformio.ini b/examples/SoftwareSerial/platformio.ini index 3eae29a..a238ed3 100644 --- a/examples/SoftwareSerial/platformio.ini +++ b/examples/SoftwareSerial/platformio.ini @@ -43,7 +43,7 @@ lib_deps = EspSoftwareSerial@>=6.7.1 board = d1_mini build_flags = -D PMS_RX=D7 -D PMS_TX=D6 -[env:mhetesp32minikit] +[env:esp32minikit] platform = espressif32 board = mhetesp32minikit build_flags = -D PMS_RX=23 -D PMS_TX=19