Skip to content

Commit

Permalink
Merge pull request #12 from avaldebe/atmelsam
Browse files Browse the repository at this point in the history
HardwareSerial example for Arduino MKRWifi 1010 (atmelsam), close #8
  • Loading branch information
avaldebe committed Apr 24, 2020
2 parents 47abb93 + b6e5df3 commit 2de7dba
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"CKSUM",
"HCHO",
"HWSERIAL",
"Hzatmega",
"MCU",
"PMSA",
"PMSerial",
"Plantower",
"SERIALPM",
"UART",
"USART",
"atmelavr",
"atmelsam",
"bluepill",
"chlen",
"datasheet",
Expand All @@ -19,9 +22,13 @@
"megaatmega",
"mhetesp",
"minikit",
"mkrwifi",
"nbar",
"nbin",
"rhum",
"samd",
"stlink",
"ststm",
"uint"
]
}
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The sensor type inference does not cover the `PMS5003S` and `PMS5003T` variants,

### PMSx003 on HardwareSerial

```arduino
```c++
#include <PMserial.h>
SerialPM pms(PMSx003, Serial); // PMSx003, UART

Expand All @@ -83,7 +83,7 @@ Setup for different MCU is covered on the [HardwareSerial][] example.
### PMSx003 on SoftwareSerial
```arduino
```c++
#include <PMserial.h>
SerialPM pms(PMSx003, 10, 11); // PMSx003, RX, TX
Expand All @@ -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, <RX>, <TX>);
```

The PMSerial library uses this feature to implement the flexibility of SoftwareSerial

```Arduino
```c++
// define Serial1 pins
SerialPM pms(PMSx003, <RX>, <TX>);
````
```
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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
98 changes: 86 additions & 12 deletions examples/HardwareSerial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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, <RX>, <TX>);
```

The PMSerial library uses this feature to implement the flexibility of SoftwareSerial

```Arduino
```c++
// define Serial1 pins
SerialPM pms(PMS5003, <RX>, <TX>);
````
```
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
Expand All @@ -152,3 +200,29 @@ platformio run -e esp32minikit -t upload
# open serial monitor
platformio run -e esp32minikit -t monitor
```

## [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

# upload
platformio run -e mkrwifi1010 -t upload

# open serial monitor
platformio run -e mkrwifi1010 -t monitor
```
7 changes: 6 additions & 1 deletion examples/HardwareSerial/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ build_flags = -D USE_HWSERIAL2
platform = espressif8266
board = esp01

[env:mhetesp32minikit]
[env:esp32minikit]
platform = espressif32
board = mhetesp32minikit
build_flags = -D USE_HWSERIAL2

[env:mkrwifi1010]
platform = atmelsam
board = mkrwifi1010
build_flags = -D USE_HWSERIAL1
Loading

0 comments on commit 2de7dba

Please sign in to comment.