Skip to content

How to write Sensor drivers example

Yogesh Hegde edited this page Mar 12, 2020 · 1 revision

Example

For Example : Lets take an sensor example MAX31865

Step 1 : Search for Libraries/code

  1. Datasheet - https://www.mouser.com/datasheet/2/737/adafruit-max31865-rtd-pt100-amplifier-1396508.pdf
  2. Wiring Pi - library - https://github.com/MarkMarine/MAX31865/blob/master/

Since I found the Wiring Pi library I will study the library and gather information from it.

Step 2 : Search for Setup information

  1. Interfaces initialization SPI is setup in function MAX31865::MAX31865(int _channel, int _speed)

  2. Configuration block All the configuration information is given in the function MAX31865::begin(max31865_numwires_t wires)

For configuring the sensor we have 4 parameters

  1. PTD wires - 2 wire or 3 wire or 4 wire.
  2. Enable bias
  3. Start auto convert
  4. Clear Fault

I looked into the data-sheet to find more info on Bias, auto-convert and faults.

Step 3 : Search for Sensor Data information For Reading Raw data from the sensor the library contains function MAX31865::readRTD()

And for calculating the data from the RTD the library has this function MAX31865::temperature(float RTDnominal, float refResistor)

For more info on the calculating equations check this link http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf

Step 4 : Write pseudo code for the blocks

Setup Block

  1. Initialize the SPI interface
  2. Ask the user for number of PTD wires
  3. Set the number of PTD wires
  4. Disable the bias for now
  5. Disable auto convert
  6. Clear all Faults

Data Block

  1. Read RAW Data a. Clear Faults b. Enable bias c. delay for 10 msecs d. Set configuration for oneshot e. delay for 65 msecs f. Read 16 bits of Data from the reg 0x01.
  2. Convert the RAW RTD value to temperature a. Get the RTD Resistance at 0 deg C and the Reference resistor from the user b. Use 2 equations for various temperature ranges. c. Return temperature.