Home

Awesome

Sensirion UART SFX6XXX Arduino Library

This is the Sensirion SFX6XXX library for Arduino allowing you to communicate with a sensor of the SFX6XXX family over UART using the SHDLC protocol.

<center><img src="images/product-image-sfx6xxx.png" width="300px"></center>

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.

Installation of the library

This library can be installed using the Arduino Library manager: Start the Arduino IDE and open the Library Manager via

SketchInclude LibraryManage Libraries...

Search for the Sensririon UART SFX6XXX library in the Filter your search... field and install it by clicking the install button.

If you cannot find it in the library manager, download the latest release as .zip file and add it to your Arduino IDE via

SketchInclude LibraryAdd .ZIP Library...

Don't forget to install the dependencies listed below the same way via library manager or Add .ZIP Library

Dependencies

Sensor wiring

Custom sensor connection

For custom setups please check out the detailed sensor pinout.

<details> <summary> Detailed sensor pinout </summary> <p> The M8 connector of your SFX6XXX has the following pinout: <img src="images/product-pinout-sfx6xxx.png" width="300px">
PinCable ColorNameDescriptionComments
1brownVDDSupply Voltage+24V
2whiteD+
3blackD-
4blueGNDGround
</p> </details> </br>

Connecting the Sensor over RS485 converter

To connect the sensor to your Arduino board's serial interface you need a RS485 to TTL converter. For example, you can use the following material:

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

Sensor PinCable ColorNameConverter connectionComments
1brownVDD-Connect to external power supply (+24V).
2whiteD+A
3blackD-B
4blueGNDGroundConnect the Ground of the external power supply to the adapter ground as well
<img src="images/SFC6xxxRS485ConverterPinout.png" width="500px">

Wire the RS485 converter to your Arduino board using the Grove to pin header cable:

ConverterCable ColorArduino PinComments
TXDyellowRXcross over
RXDwhiteTXcross over
5Vred5VPower supply for the RS485 converter
GNDblackGND

Board-specific wiring

We recommend using Arduino Boards or an ESP supporting two or more hardware serial connections to run the example code. One serial port is needed to connect the SFX6XXX sensor and the other one (over USB) for logging to the Serial Monitor of the Arduino IDE.

Arduino Uno, Micro and Nano have only one hardware serial connection and are therefore not recommended to use. There is the option to use the SoftwareSerial library to emulate a serial connection, but it does not work reliably to communicate with the sensor at the required baudrate of 115200 baud. However, you can connect your sensor over the hardware serial connection and use the SoftwareSerial library to set up a connection for logging to the host.

You will find pinout schematics for recommended board models below:

<details><summary>Arduino Mega 2560 Rev3 Pinout</summary> <p>
ConverterCable ColorArduino PinComments
TXDyellowD19 (RX1)cross over
RXDwhiteD18 (TX1)cross over
5Vred5VPower supply for the RS485 converter
GNDblackGND

Note: Make sure to connect serial pins as cross-over (RXD pin of converter -> TX pin on Arduino; TXD pin of converter -> RX pin on Ardunio)

<img src="images/Arduino-uart-Mega-2560-Rev3-pinout-5V.png" width="600px"> </p> </details> <details><summary>Espressif ESP32-DevKitC Pinout</summary> <p>
ConverterCable ColorESP PinComments
TXDyellowGPIO16 (RXD 2)cross over
RXDwhiteGPIO17 (TXD 2)cross over
5Vred5VPower supply for the RS485 converter
GNDblackGND

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

<img src="images/esp32-serial2-devkitc-pinout-5V.png" width="600px"> </p> </details>

Quick start example

  1. Install the libraries and dependencies according to Installation of the library

  2. Connect the SFX6XXX sensor as explained in Sensor wiring

  3. Load the exampleUsage sample project within the Arduino IDE:

    FileExamplesSensirion UART SFX6XXXexampleUsage

  4. Depending on your Arduino board you may need to adapt the code sample. See the board specific instruction section for more information.

  5. Make sure to select the correct board model under ToolsBoards and the connected USB port under ToolsPort.

  6. Click the Upload button in the Arduino IDE or SketchUpload

  7. When the upload process has finished, open the Serial Monitor or Serial Plotter via the Tools menu to observe the measurement values. Note that the Baud Rate in the used tool has to be set to 115200 baud.

Board-specific instructions

<details><summary>Arduino Mega 2560</summary> <p>

Serial Interface

The provided wiring instructed you to connect the SFX6XXX to Serial Port 1. Therefore, the following line needs to be used in the usage example code:

#define SENSOR_SERIAL_INTERFACE Serial1

</p> </details> <details><summary>Espressif ESP32-DevKitC</summary> <p>

ESP32 Library

The ESP32 board is not supported by default with Arduino IDE. If it is your first time using an ESP32 board, you should follow this guide from Esspressif itself.

Serial Interface

The provided wiring instructed you to connect the sensor to Serial Port 2.

Since ESP boards require HardwareSerial implementation, you need to replace the define for the SENSOR_SERIAL_INTERFACE with the following lines in the usage example code:

#include <HardwareSerial.h>
HardwareSerial HwSerial(2);
#define SENSOR_SERIAL_INTERFACE HwSerial
</p> </details> <details><summary>Emulated serial connection for logging (Arduino Uno, Arduino Nano, Arduino Micro)</summary> <p> Use following instructions if your board has only one hardware serial port and you want to emulated a serial connection for logging to the host using the SoftwareSerial library. </p> </details>

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 .cpp 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 src/*.cpp src/*.h

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

License

See LICENSE.