Skip to content

Commit

Permalink
Merge 1df6e38 into 9683c5a
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Apr 23, 2024
2 parents 9683c5a + 1df6e38 commit 4087507
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
44 changes: 29 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,44 @@

# Installing

Stable library from PyPi:
**Note** The code in this repository supports both the Enviro+ and Enviro Mini boards. _The Enviro Mini board does not have the Gas sensor or the breakout for the PM sensor._

* Just run `sudo pip install pms5003`
![Enviro Plus pHAT](https://raw.githubusercontent.com/pimoroni/enviroplus-python/main/Enviro-Plus-pHAT.jpg)
![Enviro Mini pHAT](https://raw.githubusercontent.com/pimoroni/enviroplus-python/main/Enviro-mini-pHAT.jpg)

Latest/development library from GitHub:
:warning: This library now supports Python 3 only, Python 2 is EOL - https://www.python.org/doc/sunset-python-2/

## Install and configure dependencies from GitHub:

* `git clone https://github.com/pimoroni/pms5003-python`
* `cd pms5003-python`
* `sudo ./install.sh`

# Requirements
* `./install.sh`

The serial port on your Raspberry Pi must be enabled:
**Note** Libraries will be installed in the "pimoroni" virtual environment, you will need to activate it to run examples:

```
# Disable serial terminal over /dev/ttyAMA0
sudo raspi-config nonint do_serial 1
# Enable serial port
raspi-config nonint set_config_var enable_uart 1 /boot/config.txt
source ~/.virtualenvs/pimoroni/bin/activate
```

And additionally be using a full UART (versus the default miniUART):
**Note** Raspbian/Raspberry Pi OS Lite users may first need to install git: `sudo apt install git`

## Or... Install from PyPi and configure manually:

* `python3 -m venv --system-site-packages $HOME/.virtualenvs/pimoroni`
* Run `python3 -m pip install pms5003`

**Note** this will not perform any of the required configuration changes on your Pi, you may additionally need to:

### Bookworm

* Enable serial: `raspi-config nonint do_serial_hw 0`
* Disable serial terminal: `raspi-config nonint do_serial_cons 1`
* Add `dtoverlay=pi3-miniuart-bt` to your `/boot/config.txt`

### Bullseye

Add the line `dtoverlay=pi3-miniuart-bt` to your `/boot/config.txt`
* Enable serial: `raspi-config nonint set_config_var enable_uart 1 /boot/config.txt`
* Disable serial terminal: `sudo raspi-config nonint do_serial 1`
* Add `dtoverlay=pi3-miniuart-bt` to your `/boot/config.txt`

This will switch Bluetooth over to miniUART, see https://www.raspberrypi.org/documentation/configuration/uart.md for more details.
In both cases the last line will switch Bluetooth over to miniUART, see https://www.raspberrypi.org/documentation/configuration/uart.md for more details.
17 changes: 4 additions & 13 deletions pms5003/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@

OUTL = gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE)
OUTH = gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.ACTIVE)
PLATFORMS = {
"Radxa ROCK 5B": {"enable": ("PIN_15", OUTH), "reset": ("PIN_13", OUTL)},
"Raspberry Pi 5": {"enable": ("PIN15", OUTH), "reset": ("PIN13", OUTL)},
"Raspberry Pi 4": {"enable": ("GPIO22", OUTH), "reset": ("GPIO27", OUTL)},
"Raspberry Pi Zero W": {"enable": ("GPIO22", OUTH), "reset": ("GPIO27", OUTL)}
}


class ChecksumMismatchError(RuntimeError):
Expand Down Expand Up @@ -97,17 +91,14 @@ def __str__(self):


class PMS5003:
def __init__(self, device="/dev/ttyAMA0", baudrate=9600, pin_enable=None, pin_reset=None):
def __init__(self, device="/dev/ttyAMA0", baudrate=9600, pin_enable="GPIO22", pin_reset="GPIO27"):
self._serial = None
self._device = device
self._baudrate = baudrate

if pin_enable is not None and pin_reset is not None:
gpiodevice.friendly_errors = True
self._pin_enable = gpiodevice.get_pin(pin_enable, "PMS5003_en", OUTH)
self._pin_reset = gpiodevice.get_pin(pin_reset, "PMS5003_rst", OUTL)
else:
self._pin_enable, self._pin_reset = gpiodevice.get_pins_for_platform(PLATFORMS)
gpiodevice.friendly_errors = True
self._pin_enable = gpiodevice.get_pin(pin_enable, "PMS5003_en", OUTH)
self._pin_reset = gpiodevice.get_pin(pin_reset, "PMS5003_rst", OUTL)

self.setup()

Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,8 @@ ignore = [
[tool.pimoroni]
apt_packages = []
configtxt = []
commands = []
commands = [
"printf \"Setting up serial for PMS5003..\\n\"",
"sudo raspi-config nonint do_serial_cons 1",
"sudo raspi-config nonint do_serial_hw 0"
]
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def gpiod():
def gpiodevice():
gpiodevice = mock.Mock()
gpiodevice.get_pins_for_platform.return_value = [(mock.Mock(), 0), (mock.Mock(), 0)]
gpiodevice.get_pin.return_value = (mock.Mock(), 0)

sys.modules['gpiodevice'] = gpiodevice
yield gpiodevice
Expand Down

0 comments on commit 4087507

Please sign in to comment.