Giter Club home page Giter Club logo

arduino-core's Introduction

Sensirion Arduino Core Library

This library provides SHDLC and I2C protocol implementations for Sensirion sensors. There shouldn't be a reason to use it directly, but is required by the sensor driver libraries provided here:

More Drivers

Not looking for Arduino drivers? Check out our other drivers here:

Usage

SHDLC

SHDLC (Sensirion High-Level Data Link Control) is a byte-oriented master-slave communication protocol based on ISO HDLC. It is used to control some of Sensirion’s devices (for example mass flow controllers). The detailed protocol documentation is not publicly available (yet). If you need it, please contact our customer support.

This library provides the following classes for communication with Sensirion Sensors using the SHDLC protocol.

  • SensirionShdlcTxFrame
  • SensirionShdlcRxFrame
  • SensirionShdlcCommunication

Example Usage

First initialize an instance of SensirionShdlcTxFrame and SensirionShdlcRxFrame with a properly sized buffer. A good worst case estimation for the buffer size is 2 * (n+6) where n is the number of bytes you want to send. After that you can build your frame by first calling begin(). Information about the correct COMMAND and ADDRESS can be found on the data sheet of your sensor. Then you can add data to the frame by using different add member functions. See the code below for examples. After adding your data finish the frame by calling finish().

To send this frame to the sensor you first need to initialize the correct Stream object (Serial,UART,...) to talk to your sensor. Don't forget to also call the .begin() function with the right configuration. Then call the static function sendAndReceiveFrame() from SensirionShdlcCommunication as shown below. You need to replace STREAMOBJECT with the initialized Stream object of your choice. Additionally you need to provide a timeout for to receive data back, consult the data sheet of your sensor for information on the best timeout value.

You can decode the frame by using the different get members to convert the received data to desired data types.

All functions return a error code if an error occurs during execution and zero otherwise.

uint8_t txBuffer[256];
uint8_t rxBuffer[256];

SensirionShdlcTxFrame txFrame(txBuffer, 256);
SensirionShdlcRxFrame rxFrame(rxBuffer, 256);

txFrame.begin(COMMAND, ADDRESS, DATALENGTH);

txFrame.addUInt8(UINT8);
txFrame.addUInt32(UINT32);

txFrame.finish();

SensirionShdlcCommunication::sendAndReceiveFrame(STREAMOBJECT, txFrame, rxFrame, TIMEOUT);

rxFrame.getUInt16(UINT16);
rxFrame.getFloat(FLOAT);

I2C

This library provides the following classes for communication with Sensirion Sensors using the I2C protocol.

  • SensirionI2cTxFrame
  • SensirionI2cRxFrame
  • SensirionI2cCommunication

Example Usage

First initialize an instance of SensirionI2CTxFrame and SensirionI2CRxFrame with a buffer sized the amount of data to read times 1.5. This is needed to account for the CRC which is added after every second byte. After that you can build your frame by first calling addCommand() to add the command at the beginning of the frame. Information about the different COMMANDs can be found on the data sheet of your sensor. Then you can add data to the frame by using different add member functions. See the code below for examples.

To send this frame to the sensor you first need to initialize a Wire object. Don't forget to also call the .begin() function with the right configuration. Then call the static function sendFrame() form SensirionI2CCommunication as shown below. You can find the ADDRESS on the data sheet of the sensor. You also need to replace WIREOBJECT with the initialized Wire object. Then wait the in the data sheet documented READ_DELAY before receiving the reply from the sensor by calling receiveFrame() with the same Wire object.

You then can decode the frame by using the different get members to convert the received data to desired data types.

All functions return a error code if an error occurs during execution and zero otherwise.

uint8_t txBuffer[256];
uint8_t rxBuffer[256];

SensirionShdlcTxFrame txFrame(txBuffer, 256);
SensirionShdlcRxFrame rxFrame(rxBuffer, 256);

txFrame.addCommand(COMMAND);

txFrame.addUInt8(UINT8);
txFrame.addUInt32(UINT32);

SensirionShdlcCommunication::sendFrame(ADDRESS, txFrame, WIREOBJECT);

delay(READ_DELAY);

SensirionShdlcCommunication::receiveFrame(ADDRESS, rxFrame, WIREOBJECT);

rxFrame.getUInt16(UINT16);
rxFrame.getFloat(FLOAT);

arduino-core's People

Contributors

zifzaf avatar rnestler avatar psachs avatar mbjoern avatar rol-la avatar abrauchli avatar sensirion-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.