Skip to content

Commit

Permalink
ESP8266 use EspSoftwareSerial@>=6.7.1, see #6
Browse files Browse the repository at this point in the history
  • Loading branch information
avaldebe committed Apr 15, 2020
1 parent 437c6e2 commit f4ea89e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 50 deletions.
101 changes: 51 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Arduino library for PM sensors with serial interface

## Sensors

[Plantower][] | Tested Works | Doesn't Work | Not Tested | Datasheet | Notes
------------------ | :----------: | :----------: | :---------: | --------- | -----
PMS1003 (aka G1) | | | X | [en][g1aqmd], [cn][g1lcsc] |
PMS3003 (aka G3) | X | | | [en][g3aqmon], [cn][g3lcsc] | No passive mode read
PMS5003 (aka G5) | X | | | [en][g5aqmd], [cn][g5lcsc] |
PMS7003 (aka G7) | X | | | [cn][g7lcsc] |
PMSA003 (aka G10) | | | X | [cn][gAlcsc] |
| [Plantower][] | Tested Works | Doesn't Work | Not Tested | Datasheet | Notes |
| ----------------- | :----------: | :----------: | :--------: | --------------------------- | -------------------- |
| PMS1003 (aka G1) | | | X | [en][g1aqmd], [cn][g1lcsc] |
| PMS3003 (aka G3) | X | | | [en][g3aqmon], [cn][g3lcsc] | No passive mode read |
| PMS5003 (aka G5) | X | | | [en][g5aqmd], [cn][g5lcsc] |
| PMS7003 (aka G7) | X | | | [cn][g7lcsc] |
| PMSA003 (aka G10) | | | X | [cn][gAlcsc] |

[plantower]: http://www.plantower.com/
[g1aqmd]: http://www.aqmd.gov/docs/default-source/aq-spec/resources-page/plantower-pms1003-manual_v2-5.pdf?sfvrsn=2
Expand All @@ -25,23 +25,24 @@ PMSA003 (aka G10) | | | X | [cn][gAlcsc] |

## Compatibility

MCU | Tested Works | Doesn't Work | Not Tested | Examples | Notes
------------------ | :----------: | :----------: | :---------: | -------- | -----
Atmega328 @ 8MHz | X | | | [SoftwareSerial][] |
Atmega328 @ 16MHz | | | X | [SoftwareSerial][] |
ATmega168 @ 8MHz | | | X | [SoftwareSerial][] |
Atmega168 @ 16MHz | | | X | |
Atmega32u4 @ 8MHz | | | X | |
Atmega32u4 @ 16MHz | | | X | [HardwareSerial][] |
Atmega2560 @ 16MHz | X | | | [HardwareSerial][] |
STM32f103c8 | | | X | |
STM32f103cb | | | X | [HardwareSerial][] |
ESP8266 | X | | | [HardwareSerial][] [SoftwareSerial][] [OLED 64x48][] |
ESP32 | | | X | [HardwareSerial][] [OLED 64x48][] | Serial1 not supported
| MCU | Tested Works | Doesn't Work | Not Tested | Examples | Notes |
| ------------------ | :----------: | :----------: | :--------: | ----------------------------------------------------- | ----------------------------------------- |
| Atmega328 @ 8MHz | X | | | [SoftwareSerial][] |
| Atmega328 @ 16MHz | | | X | [SoftwareSerial][] |
| ATmega168 @ 8MHz | | | X | [SoftwareSerial][] |
| Atmega168 @ 16MHz | | | X | |
| Atmega32u4 @ 8MHz | | | X | |
| Atmega32u4 @ 16MHz | | | X | [HardwareSerial][] |
| Atmega2560 @ 16MHz | X | | | [HardwareSerial][] |
| STM32f103c8 | | | X | |
| STM32f103cb | | | X | [HardwareSerial][] |
| ESP8266 | X | | | [HardwareSerial][] [SoftwareSerial][] [OLED 64x48][] | needs [EspSoftwareSerial@>=6.7.1][issue6] |
| ESP32 | | | X | [HardwareSerial][] [OLED 64x48][] | Serial1 not supported |

[SoftwareSerial]: examples/SoftwareSerial/README.md
[HardwareSerial]: examples/HardwareSerial/README.md
[OLED 64x48]: examples/OLED_64x48/README.md
[issue6]: https://github.com/avaldebe/PMserial/issues/6

## Usage

Expand Down Expand Up @@ -100,11 +101,11 @@ The `PMSx003` message/protocol on the examples will
determine the message length automatically.
The available protocols are:

message/protocol | length | PM | NC | sensors (aliases)
----------------- | -------- | :--: | :--: | -----------------
`PLANTOWER_32B` | 32 bytes | X | X | `PMS1003`, `PMS5003`, `PMS7003`, `PMSA003`
`PLANTOWER_24B` | 24 bytes | X | | `PMS3003`
`PLANTOWER_AUTO` | self discovery| X |auto| `PMSx003`
| message/protocol | length | PM | NC | sensors (aliases) |
| ---------------- | -------------- | :---: | :---: | ------------------------------------------ |
| `PLANTOWER_32B` | 32 bytes | X | X | `PMS1003`, `PMS5003`, `PMS7003`, `PMSA003` |
| `PLANTOWER_24B` | 24 bytes | X | | `PMS3003` |
| `PLANTOWER_AUTO` | self discovery | X | auto | `PMSx003` |

### PMSx003 reading

Expand All @@ -117,20 +118,20 @@ and PM/NC measurements were successfully decoded.
All measurements found in the sensor message
will be decoded and stored in following member variables:

variable | type[len] | measurement | particle diameter | unit | Notes
-------- | ---------- | ---------- | ----------------- | ---- | -----
`pm01` | `uint16_t` | PM | <= 1.0 µm | µg/m3 | PM1.0, ultra fine particles
`pm25` | `uint16_t` | PM | <= 2.5 µm | µg/m3 | PM2.5, fine particles
`pm10` | `uint16_t` | PM | <= 10 µm | µg/m3 | PM10
`n0p3` | `uint16_t` | NC | >= 0.3 µm | #/100cm3 |
`n0p5` | `uint16_t` | NC | >= 0.5 µm | #/100cm3 |
`n1p0` | `uint16_t` | NC | >= 1.0 µm | #/100cm3 |
`n2p5` | `uint16_t` | NC | >= 2.5 µm | #/100cm3 |
`n5p0` | `uint16_t` | NC | >= 5.0 µm | #/100cm3 |
`n10p0` | `uint16_t` | NC | >= 10 µm | #/100cm3 |
`pm` |`uint16_t[3]`|PM | <= 1,2.5,10 µm | µg/m3 | array containing `pm01,pm25,pm10`
`nc` |`uint16_t[6]`|NC | >= 0.3,0.5,1,5,10 µm|#/100cm3| array containing `n0p3,..,n10p0`
`data` |`uint16_t[9]`|PM/NC | | | all PM/NC data `pm01,..,n10p0`
| variable | type[len] | measurement | particle diameter | unit | Notes |
| -------- | ------------- | ----------- | -------------------- | -------- | --------------------------------- |
| `pm01` | `uint16_t` | PM | <= 1.0 µm | µg/m3 | PM1.0, ultra fine particles |
| `pm25` | `uint16_t` | PM | <= 2.5 µm | µg/m3 | PM2.5, fine particles |
| `pm10` | `uint16_t` | PM | <= 10 µm | µg/m3 | PM10 |
| `n0p3` | `uint16_t` | NC | >= 0.3 µm | #/100cm3 |
| `n0p5` | `uint16_t` | NC | >= 0.5 µm | #/100cm3 |
| `n1p0` | `uint16_t` | NC | >= 1.0 µm | #/100cm3 |
| `n2p5` | `uint16_t` | NC | >= 2.5 µm | #/100cm3 |
| `n5p0` | `uint16_t` | NC | >= 5.0 µm | #/100cm3 |
| `n10p0` | `uint16_t` | NC | >= 10 µm | #/100cm3 |
| `pm` | `uint16_t[3]` | PM | <= 1,2.5,10 µm | µg/m3 | array containing `pm01,pm25,pm10` |
| `nc` | `uint16_t[6]` | NC | >= 0.3,0.5,1,5,10 µm | #/100cm3 | array containing `n0p3,..,n10p0` |
| `data` | `uint16_t[9]` | PM/NC | | | all PM/NC data `pm01,..,n10p0` |

For an efficient use of memory, the `data`, `pm` and `nc` arrays and the
individual measurement variables are implemented with a union/struct combination.
Expand All @@ -142,17 +143,17 @@ The `pms.status` member variable contains the status and eventual error code
resulting from the last sensor read.
The available status/error codes and pre-defined error messages are:

status/error code | error message | pre-defined text
----------------------- | -------------- | -----------------
`pms.OK` |
`pms.ERROR_TIMEOUT` | `PMS_ERROR_TIMEOUT` | "Sensor read timeout"
`pms.ERROR_PMS_TYPE` | `PMS_ERROR_PMS_TYPE` | "Wrong PMSx003 sensor type"
`pms.ERROR_MSG_UNKNOWN` | `PMS_ERROR_MSG_UNKNOWN` | "Unknown message protocol"
`pms.ERROR_MSG_HEADER` | `PMS_ERROR_MSG_HEADER` | "Incomplete message header"
`pms.ERROR_MSG_BODY` | `PMS_ERROR_MSG_BODY` | "Incomplete message body"
`pms.ERROR_MSG_START` | `PMS_ERROR_MSG_START` | "Wrong message start"
`pms.ERROR_MSG_LENGTH` | `PMS_ERROR_MSG_LENGTH` | "Message too long"
`pms.ERROR_MSG_CKSUM` | `PMS_ERROR_MSG_CKSUM` | "Wrong message checksum"
| status/error code | error message | pre-defined text |
| ----------------------- | ----------------------- | --------------------------- |
| `pms.OK` |
| `pms.ERROR_TIMEOUT` | `PMS_ERROR_TIMEOUT` | "Sensor read timeout" |
| `pms.ERROR_PMS_TYPE` | `PMS_ERROR_PMS_TYPE` | "Wrong PMSx003 sensor type" |
| `pms.ERROR_MSG_UNKNOWN` | `PMS_ERROR_MSG_UNKNOWN` | "Unknown message protocol" |
| `pms.ERROR_MSG_HEADER` | `PMS_ERROR_MSG_HEADER` | "Incomplete message header" |
| `pms.ERROR_MSG_BODY` | `PMS_ERROR_MSG_BODY` | "Incomplete message body" |
| `pms.ERROR_MSG_START` | `PMS_ERROR_MSG_START` | "Wrong message start" |
| `pms.ERROR_MSG_LENGTH` | `PMS_ERROR_MSG_LENGTH` | "Message too long" |
| `pms.ERROR_MSG_CKSUM` | `PMS_ERROR_MSG_CKSUM` | "Wrong message checksum" |

For easy of use, the error message are pre-defined with `#define`.
See the [examples](examples/) for an error handling implementation.
Expand Down
4 changes: 4 additions & 0 deletions examples/SoftwareSerial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ platformio run -e mini328_3V3 -t monitor
**Note** This is a 3.3V board, and the PMS5003 requires 5V.

- SWSerial on pins GPIO2 (RX) and GPIO0 (TX).
- Needs [EspSoftwareSerial@>=6.7.1][issue6]

[issue6]: https://github.com/avaldebe/PMserial/issues/6

```bash
# compile
Expand All @@ -80,6 +83,7 @@ platformio run -e esp01 -t monitor
**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]

```bash
# compile
Expand Down
2 changes: 2 additions & 0 deletions examples/SoftwareSerial/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ board = pro8MHzatmega328
[env:esp01]
; ESP8266, 512kB flash
platform = espressif8266
lib_deps = EspSoftwareSerial@>=6.7.1
board = esp01
build_flags = -D PMS_RX=2 -D PMS_TX=0

[env:d1_mini]
; ESP8266, 4096kB flash
platform = espressif8266
lib_deps = EspSoftwareSerial@>=6.7.1
board = d1_mini
build_flags = -D PMS_RX=D7 -D PMS_TX=D6
4 changes: 4 additions & 0 deletions examples/debug/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ with calls to some special debugging methods.
- ESP8266: `esp01`, `esp01_1m`, `d1_mini`
- ESP32: `mhetesp32minikit`, `m5stack-core-esp32`

Please note that the ESP8266 boards need [EspSoftwareSerial@>=6.7.1][issue6]

[issue6]: https://github.com/avaldebe/PMserial/issues/6

## Debugging methods

Two additional methods are compiled with the `PMS_DEBUG` directive.
Expand Down
3 changes: 3 additions & 0 deletions examples/debug/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@ board = maple_mini_b20
[env:esp01]
; esp8266 (512Kb)
platform = espressif8266
lib_deps = EspSoftwareSerial@>=6.7.1
board = esp01

[env:aqmon]
; esp8266 (1Mb)
platform = espressif8266
lib_deps = EspSoftwareSerial@>=6.7.1
board = esp01_1m
upload_resetmethod = nodemcu
build_flags = -D USE_HWSERIAL

[env:d1_mini]
; esp8266 (4Mb)
platform = espressif8266
lib_deps = EspSoftwareSerial@>=6.7.1
board = d1_mini
build_flags = -D PMS_RX=D7 -D PMS_TX=D6

Expand Down

0 comments on commit f4ea89e

Please sign in to comment.