Skip to content

C driver to work with the Sensirion's SFC6xxx mass flow controller or SFM6xxx sensor via UART on Raspberry-Pi

License

Notifications You must be signed in to change notification settings

Sensirion/raspberry-pi-uart-sfx6xxx

Repository files navigation

Sensirion Raspberry Pi UART SFX6XXX Driver

The repository provides a driver for setting up a mass flow controller of the SFC6XXX family or a gas flow sensor of the SFM6XXX family to run on a Raspberry Pi over UART using the SHDLC protocol.

Click here to learn more about the Sensirion SFC6XXX mass flow controller family.

Click here to learn more about the Sensirion SFM6XXX gas flow sensor family.

Supported sensor types

The following instructions and examples use a SFC6000.

Connect the sensor

Please note that the sensor needs to be connected to a 24V power supply.

Connecting the Sensor over USB

Plug in the evaluation kit cable to power and connect the USB port to your Raspberry Pi.

Please note that due to the delays introduced by the FTDI driver you can reach a maximum sampling frequency of about 20Hz with this setup.

Connecting the Sensor over RS485 converter

With this connection setup you can reach a sampling frequency of 100Hz or more.

To connect the sensor to your Raspberry Pi serial interface you need a RS485 to RS232 converter. For example, you can use following material:

Wire the sensor to the RS485 converter using the M8 socket to Bare End Cable:

Sensor Pin Cable Color Name Converter connection Comments
1 brown VDD - Connect to external power supply (+24V).
2 white D+ A
3 black D- B
4 blue GND Ground Connect the Ground of the external power supply to the adapter ground as well

Wire the RS485 converter to your Raspberry Pi using the Grove to pin header cable:

Converter Cable Color Raspberry Pi Pin Comments
TXD yellow Pin 10 (RXD) UART communication, cross over
RXD white Pin 8 (TXD) UART communication, cross over
5V red Pin 2 (VDD) Power supply for the RS485 converter
GND black Pin 6 (GND)

Note: Make sure to configure your hardware serial interface on your Raspberry Pi.

Note: Make sure to connect serial pins as cross-over (RXD of converter -> TXD on Raspberry Pi; TXD of converter -> RXD pin of Raspberry Pi)

Custom setup - sensor pinout

The M8 connector of your SFX6XXX has the following pinout:

Pin Cable Color Name Description Comments
1 brown VDD Supply Voltage +24V
2 white D+
3 black D-
4 blue GND Ground


Quick start example

  • Install the Raspberry Pi OS on to your Raspberry Pi

  • Download the SFX6XXX driver from Github and extract the .zip on your Raspberry Pi

  • Connect the SFX6XXX sensor as explained in the section above

  • Check that the correct serial port is set in the define in sensirion_uart_portdescriptor.h

    • For connection over USB (in case you have other devices connected check the USB number)

      #define SERIAL_0 "/dev/ttyUSB0"

    • For connection over UART Pins using the RS485 Converter

      #define SERIAL_0 "/dev/serial0"

  • Compile the driver

    1. Open a terminal

    2. Navigate to the driver directory. E.g. cd ~/raspberry-pi-uart-sfx6xxx

    3. Navigate to the subdirectory example-usage.

    4. Run the make command to compile the driver

      Output:

      rm -f sfx6xxx_uart_example_usage
      cc -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC -I. -o sfx6xxx_uart_example_usage sfx6xxx_uart.h sfx6xxx_uart.c sensirion_uart_hal.h sensirion_shdlc.h sensirion_shdlc.c \ 
          sensirion_uart_hal.c sensirion_config.h sensirion_common.h sensirion_common.c sfx6xxx_uart_example_usage.c
      
  • Test your connected sensor

    • Run ./sfx6xxx_uart_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

 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

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.