Skip to content

Commit

Permalink
Merge branch 'embedded-hal'
Browse files Browse the repository at this point in the history
* embedded-hal:
  Rewrite to use embedded_hal & support no_std
  • Loading branch information
kelnos committed Aug 25, 2021
2 parents f3f3530 + 4dc9427 commit 8a7254e
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 180 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ jobs:
matrix:
rust:
- stable
- 1.40.0
- 1.46.0
target:
- arm-unknown-linux-gnueabihf
- armv7-unknown-linux-gnueabihf
- x86_64-unknown-linux-gnu
feature_flags:
- ''
- '--no-default-features'
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -42,4 +45,4 @@ jobs:
with:
use-cross: true
command: test
args: --release --target=${{ matrix.target }}
args: --release --target=${{ matrix.target }} ${{ matrix.feature_flags }}
17 changes: 13 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
[package]
name = "sen0177"
description = "Read air quality data from the SEN0177 sensor"
version = "0.1.1"
version = "0.2.0"
authors = ["Brian J. Tarricone <[email protected]>"]
homepage = "https://github.com/kelnos/sen0177-rs"
repository = "https://github.com/kelnos/sen0177-rs"
license = "Apache-2.0"
readme = "README.md"
categories = [ "embedded", "hardware-support" ]
keywords = [ "air-quality", "sensor", "sen0177" ]
categories = [ "embedded", "hardware-support", "no-std" ]
keywords = [ "air-quality", "embedded-hal", "sensor", "sen0177" ]
edition = "2018"

[features]
default = [ "std" ]
# Provides impl for std types like std::error::Error
std = []

[dependencies]
embedded-hal = "0.2"
nb = "1"

[dev-dependencies]
linux-embedded-hal = "0.3"
serial = "0.4"
serial-core = "0.4"
53 changes: 2 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,12 @@
# sen0177

`sen0177` is a Rust library/crate that reads air quality data from the
SEN0177 air quality sensor.

[![crates.io][crates-shield]][crates-url]
[![Documentation][docs-shield]][docs-url]
[![Apache 2.0][license-shield]][license-url]
[![Build Status][build-shield]][build-url]

## Prerequisites

* You've connected the sensor to a UART on a Linux-based device, and
that UART is enabled and available from the kernel as a TTY device
node.

## Installation

Include the following in your `Cargo.toml` file:

```toml
[dependencies]
sen0177 = "<see tags for latest version>"
```

## Usage

```rust,no_run
use sen0177::{Reading, Sen0177};
const SERIAL_PORT: &str = "/dev/ttyS0";
let mut sensor = Sen0177::open(SERIAL_PORT).expect("Failed to open device");
let reading = sensor.read().expect("Failed to read sensor data");
println!("PM1: {}µg/m³, PM2.5: {}µg/m³, PM10: {}µg/m³",
reading.pm1(), reading.pm2_5(), reading.pm10());
```

Note that the serial device occasionally returns bad data. If you
recieve `Sen0177::InvalidData` or `Sen0177::ChecksumMismatch` from the
`read()` call, a second try will usually succeed.

## Gotchas

### Raspberry Pi

If you're using this with a Raspberry Pi, note that by default the
primary GPIO pins are set up as a Linux serial console. You will need
to disable that (by editing `/boot/cmdline.txt`) before this will work.
Instead of using a specifiy TTY device node, you should use
`/dev/serial0`, which is a symlink to the proper device.

Alternatively, you can use the second UART, but you'll need to load an overlay
to assign it to GPIO pins. See [UART configuration][rpi-uart-config] and the
[UART-related overlays][rpi-overlays] for more information.
`sen0177` is a Rust library/crate that reads air quality data from the
SEN0177 air quality sensor.

[crates-shield]: https://img.shields.io/crates/v/sen0177.svg
[crates-url]: https://crates.io/crates/sen0177
Expand All @@ -62,6 +16,3 @@ to assign it to GPIO pins. See [UART configuration][rpi-uart-config] and the
[license-url]: https://github.com/kelnos/sen0177-rs/blob/master/LICENSE
[build-shield]: https://img.shields.io/github/workflow/status/kelnos/sen0177-rs/CI
[build-url]: https://github.com/kelnos/sen0177-rs/actions

[rpi-uart-config]: https://www.raspberrypi.org/documentation/configuration/uart.md
[rpi-overlays]: https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README
Loading

0 comments on commit 8a7254e

Please sign in to comment.