Home

Awesome

Sensirion Raspberry Pi I²C SFM-SF06 Driver

The repository provides a driver for setting up a sensor of the SFM-SF06 family to run on a Raspberry Pi over I²C.

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

Click here to learn more about the Sensirion SFM-SF06 sensor family.

Not all sensors of this driver family support all measurements. In case a measurement is not supported by all sensors, the products that support it are listed in the API description.

Supported sensor types

Sensor nameI²C Addresses
SFM43000x2A, 0x2B, 0x2C, 0x2D
SFM31190x29
SFM30030x28, 0x2D
SFM30130x2F
SFM30190x2E

The following instructions and examples use a SFM4300.

Connect the sensor

Your sensor has 6 different connectors: ADDR, SDA, GND, VDD, SCL, IRQn. Use the following pins to connect your SFM-SF06:

SFM-SF06Cable ColorRaspberry Pi
ADDRPin
SDAPin 3
GNDPin 6
VDDPin 1
SCLPin 5
IRQnPin
<img src="images/raspi-i2c-pinout-3.3V.png" width="400px">

Detailed sensor pinout

<img src="images/pinout_SFM4300.png" width="300px">
PinCable ColorNameDescriptionComments
1ADDRsee data sheet section 4.1
2SDAI2C: Serial data input / outputSerial data, bidirectional
3GNDGround
4VDDSupply Voltage3.0V to 5.0V
5SCLI2C: Serial clock input
6IRQnActive low. see data sheet section 3.3

Quick start example

Troubleshooting

Building driver failed

If the execution of make in the compilation step 3 fails with something like

 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 ./sfm_sf06_i2c_example_usage but do not get sensor readings but something like this instead

Error executing stop_continuous_measurement(): -1
Error executing read_product_identifier(): -1
Error executing start_O2_continuous_measurement(): -1
...

then go through the below troubleshooting steps.

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!

We develop and test this driver using our company internal tools (version control, continuous integration, code review etc.) and automatically synchronize the master branch with GitHub. But this doesn't mean that we don't respond to issues or don't accept pull requests on GitHub. In fact, you're very welcome to open issues or create pull requests :)

This Sensirion library uses clang-format 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.

clang-format -i *.c *.h

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

License

See LICENSE.