Skip to content

Commit

Permalink
Generate SEN66 driver from SEN66 model version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Driver Generator 2 committed Oct 30, 2024
0 parents commit a7797a5
Show file tree
Hide file tree
Showing 22 changed files with 2,065 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4
AlignAfterOpenBracket: Align
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
IndentCaseLabels: true
SpacesBeforeTrailingComments: 2
PointerAlignment: Left
AlignEscapedNewlines: Left
ForEachMacros: ['TEST_GROUP', 'TEST']
...
10 changes: 10 additions & 0 deletions .github/workflows/github_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Github Release

on:
push:
tags:
- '*'

jobs:
github-release:
uses: sensirion/.github/.github/workflows/driver.common.github_release.yml@main
21 changes: 21 additions & 0 deletions .github/workflows/raspberry_quality_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Quality check

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
driver-quality:
uses: sensirion/.github/.github/workflows/driver.c.check.yml@main

todo-check:
if: github.event_name == 'push' && github.ref != 'refs/head/main'
uses: sensirion/.github/.github/workflows/driver.common.todo_check.yml@main

code-generation-check:
if: github.event_name == 'push' && github.ref != 'refs/head/main'
uses: sensirion/.github/.github/workflows/driver.generated.metadata_check.yml@main
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/example-usage/sen66_i2c_example_usage
/tests/sen66_test_hw_i2c
/tests/sen66_test_sw_i2c
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CHANGELOG

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0] - 2024-10-31

### Added

- Add product picture
- Add interfaces to start, stop and read measurements.
- Add interfaces to read product name, serial number and version

[Unreleased]: https://github.com/Sensirion/raspberry-pi-i2c-sen66/compare/0.1.0...HEAD
[0.1.0]: https://github.com/Sensirion/raspberry-pi-i2c-sen66/releases/tag/0.1.0
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2024, Sensirion AG
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
167 changes: 167 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Sensirion Raspberry Pi I²C SEN66 Driver

The repository provides a driver for setting up a SEN66 sensor to run on a Raspberry Pi over I²C.

<img src="images/sen6x.png" width="300px">

Click [here](https://sensirion.com/sen6x-air-quality-sensor-platform) to learn more about the Sensirion SEN66 sensor.


unknown


The default I²C address of [SEN66](https://www.sensirion.com/products/catalog/SEN6x) is **0x6B**.



## Connect the sensor

Your sensor has 4 different connectors: VDD, GND, SDA, SCL.
Use the following pins to connect your SEN66:

| *SEN66* | *Cable Color* | *Raspberry Pi* |
| :----------------: | -------------- | ------------------ |
| VDD | red | Pin 1
| GND | black | Pin 6
| SDA | green | Pin 3
| SCL | yellow | Pin 5


<img src="images/raspi-i2c-pinout-3.3V.png" width="400px">


### Detailed sensor pinout

<img src="images/sen6x-pinout.png" width="300px">

| *Pin* | *Cable Color* | *Name* | *Description* | *Comments* |
|-------|---------------|:------:|----------------|------------|
| 1 | red | VDD | Supply Voltage | 3.3V ±10%
| 2 | black | GND | Ground |
| 3 | green | SDA | I2C: Serial data input / output | TTL 5V compatible
| 4 | yellow | SCL | I2C: Serial clock input | TTL 5V compatible
| 5 | | NC | Do not connect |
| 6 | | NC | Do not connect |



## Quick start example

- [Install the Raspberry Pi OS on to your Raspberry Pi](https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up)
- [Enable the I²C interface in the raspi-config](https://www.raspberrypi.org/documentation/configuration/raspi-config.md)
- Download the SEN66 driver from [Github](https://github.com/Sensirion/raspberry-pi-i2c-sen66) and extract the `.zip` on your Raspberry Pi
- Connect the SEN66 sensor as explained in the [section above](#connect-the-sensor)

- Compile the driver
1. Open a [terminal](https://projects.raspberrypi.org/en/projects/raspberry-pi-using/8)
2. Navigate to the driver directory. E.g. `cd ~/raspberry-pi-i2c-sen66`
3. Navigate to the subdirectory example-usage.
4. Run the `make` command to compile the driver

Output:
```
rm -f sen66_i2c_example_usage
cc -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC -I. -o sen66_i2c_example_usage sen66_i2c.h sen66_i2c.c sensirion_i2c_hal.h sensirion_i2c.h sensirion_i2c.c \
sensirion_i2c_hal.c sensirion_config.h sensirion_common.h sensirion_common.c sen66_i2c_example_usage.c
```
- Test your connected sensor
- Run `./sen66_i2c_example_usage` in the same directory you used to
compile the driver. You should see the measurement values in the console.
## Troubleshooting
### Building driver failed
If the execution of `make` in the compilation step 3 fails with something like
```bash
make: command not found
```

your RaspberryPi likely does not have the build tools installed. Proceed as follows:

```
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential
```


### Initialization failed

If you run `./sen66_i2c_example_usage` but do not get sensor readings but something like this instead

```
Error executing device_reset(): -1
Error executing get_serial_number(): -1
Error executing start_continuous_measurement(): -1
...
```
then go through the below troubleshooting steps.


- Ensure that you connected the sensor correctly: All cables are fully
plugged in and connected to the correct pin.
- Ensure that I²C is enabled on the Raspberry Pi. For this redo the steps on
"Enable the I²C interface in the raspi-config" in the guide above.
- Ensure that your user account has read and write access to the I²C device.
If it only works with user root (`sudo ./sen66_i2c_example_usage`), it's
typically due to wrong permission settings. See the next chapter how to solve this.

### Missing I²C permissions

If your user is missing access to the I²C interface you should first verfiy
the user belongs to the `i2c` group.

```
$ groups
users input some other groups etc
```
If `i2c` is missing in the list add the user and restart the Raspberry Pi.

```
$ sudo adduser your-user i2c
Adding user `your-user' to group `i2c' ...
Adding user your-user to group i2c
Done.
$ sudo reboot
```

If that did not help you can make globally accessible hardware interfaces
with a udev rule. Only do this if everything else failed and you are
reasoably confident you are the only one having access to your Pi.

Go into the `/etc/udev/rules.d` folder and add a new file named
`local.rules`.
```
$ cd /etc/udev/rules.d/
$ sudo touch local.rules
```
Then add a single line `ACTION=="add", KERNEL=="i2c-[0-1]*", MODE="0666"`
to the file with your favorite editor.
```
$ sudo vi local.rules
```

## Contributing

**Contributions are welcome!**

This Sensirion library uses
[`clang-format`](https://releases.llvm.org/download.html) to standardize the
formatting of all our `.c` and `.h` files. Make sure your contributions are
formatted accordingly:

The `-i` flag will apply the format changes to the files listed.

```bash
clang-format -i *.c *.h
```

Note that differences from this formatting will result in a failed build until
they are fixed.


## License

See [LICENSE](LICENSE).
23 changes: 23 additions & 0 deletions example-usage/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
src_dir = ..
common_sources = ${src_dir}/sensirion_config.h ${src_dir}/sensirion_common.h ${src_dir}/sensirion_common.c
i2c_sources = ${src_dir}/sensirion_i2c_hal.h ${src_dir}/sensirion_i2c.h ${src_dir}/sensirion_i2c.c
driver_sources = ${src_dir}/sen66_i2c.h ${src_dir}/sen66_i2c.c

i2c_implementation ?= ${src_dir}/sensirion_i2c_hal.c

CFLAGS = -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC -I${src_dir} -I.

ifdef CI
CFLAGS += -Werror
endif

.PHONY: all clean

all: sen66_i2c_example_usage

sen66_i2c_example_usage: clean
$(CC) $(CFLAGS) -o $@ ${driver_sources} ${i2c_sources} \
${i2c_implementation} ${common_sources} sen66_i2c_example_usage.c

clean:
$(RM) sen66_i2c_example_usage
Loading

0 comments on commit a7797a5

Please sign in to comment.