Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Sensors

Cai Biesinger edited this page Jul 10, 2018 · 8 revisions

Tip: Quickly find and jump to sensors from the Supported Devices page.

ISensor Interface

All sensors use the ISensor interface. This requires some functionality common to all sensors.

Here are the methods provided:

  • bool Test()
    • Checks if the sensor is working correctly. The implementation depends on the specific sensor. If there is no way to test the sensor accurately, or it is not implemented, this must return true. This method should never throw an exception.
  • void UpdateState()
    • Updates the sensor. Specific actions depend on the sensor, but getting readings is very common. Make sure to call this every time you want to get a new reading from your sensor.
  • DataUnit GetData()
    • Gets sensor information in a DataLog-compatible format.
  • string System (Property)
    • This is to be used by the user to associate a task to a sensor, to make it easier to tell multiple sensors apart. For example, "Ground Temperature", or "Front-Right Wheel".
  • bool TraceLogging (Property)

BME280

Implementation | Datasheet | Adafruit Breakout

The BME280 is a high-accuracy air temperature, humidity, and pressure sensor. It uses the I2C or SPI protocols, and is fully supported in Scarlet.

Create an instance using either of the two constructors:

new BME280(II2CBus I2CBus, byte DeviceAddress)
new BME280(ISPIBus SPIBus, IDigitalOut ChipSelect)

Now, you'll need to apply a configuration:

MyBME.Configure();

You can also create a custom configuration, and apply that instead:

BME280.Config MyConfig = BME280.DefaultConfig;
MyConfig.MeasureHumidity = false;
MyBME.Configure(MyConfig);

Then, as with any other sensor, call UpdateState(), and then get the readings from the Temperature, Humidity, and Pressure properties as needed.

Here are the options that you can configure:

Option Default Values Description
HumidityOversampling OS_1x BME280.Oversampling enum values Sets oversampling on temperature measurements, determining capture time. This is used to reduce noise.
MeasureHumidity true true/false Determines whether humidity measurements are carried out. Turning off unwanted measurements reduces power usage and increases measurement speed.
PressureOversampling OS_1x BME280.Oversampling enum values Sets oversampling on temperature measurements, determining capture time. This is used to reduce noise.
MeasurePressure true true/false Determines whether pressure measurements are carried out. Turning off unwanted measurements reduces power usage and increases measurement speed.
TemperatureOversampling OS_1x BME280.Oversampling enum values Sets oversampling on temperature measurements, determining capture time. This is used to reduce noise.
Mode NORMAL BME280.Mode enum values Chooses if the device takes measurements, and in what manner.
StandbyTime TIME_500us BME280.Oversampling enum values The amount of time to wait between measurements in NORMAL mode.
IIRFilterTimeConstant FILTER_OFF BME280.Oversampling enum values How many samples should be averaged for temperature and pressure readings. Used to smooth readings.
Use3WireSPI false true/false Whether to use 3-wire SPI mode (usually false).

Note that temperature measurement cannot be disabled, as it is required for the other two measurements to work.

DataUnit

Like any sensor, the BME280 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"Temperature" double The air temperature, in 0.01 °C increments.
"Pressure" double The air pressure, in 1/256 Pa increments. double.NaN if pressure measurements are not taken.
"Humidity" double The air humidity, in 1/1024 %RH increments, from 0.0 to 100.0. double.NaN if humidity measurements are not taken.

BNO055

Implementation | Datasheet | Adafruit Breakout

Documentation to be added.

DataUnit

Like any sensor, the BNO055 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"X" float Depends on vector mode
"Y" float Depends on vector mode
"Z" float Depends on vector mode

INA226

Implementation | Datasheet

The INA226 is a high- or low-side current shunt monitor. It uses the I2C protocol, and is fully supported in Scarlet.

Usage is very easy, start by constructing an instance:

new INA226(II2CBus Bus, byte DeviceAddress, float MaxCurrent, double Resistor, INA226.AveragingMode Avg = AveragingMode.Last1, INA226.ConversionTime VBusTime = ConversionTime.Time1100us, INA226.ConversionTime VShuntTime = ConversionTime.Time1100us)

The advanced parameters all have default values that are reasonable. If you have specific requirements, you can tweak them.

Once you have your instance, you're ready to go. Simply call UpdateState() to get new readings from the device, then use the GetBusVoltage(), GetShuntVoltage(), GetCurrent(), or GetPower() methods to get the data you need.

DataUnit

Like any sensor, the INA226 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"BusVoltage" double The voltage at the bus line (the supply voltage for high-side sensing)
"ShuntVoltage" double The voltage across the shunt resistor
"Current" double The calculated current going through the shunt resistor
"Power" double The calculated power being drawn by the load

LS7366R

Implementation | Datasheet

The LS7366R is a high-speed dedicated encoder counter. It uses the SPI protocol, and is fully supported in Scarlet.

To start using it, construct an instance:

new LS7366R(ISPIBus SPIBus, IDigitalOut SPI_CS)

Then, create and apply a configuration:

LS7366R.Configuration Config = LS7366R.DefaultConfig;
Config.QuadMode = LS7366R.QuadMode.X1_QUAD;
MyEncoder.Configure(Config);

You are now ready to get data. Simply call UpdateState() to get the newest data from the device, then access the count by getting the Count property.

Optionally, you can register for Overflow/Underflow events. To do this, implement a method with the required signature, or expand an existing event handler, then register it:

public void EncoderOverflowTriggered(object sender, LS7366R.OverflowEvent eventData)
{
    bool WasOver = eventData.Overflow;
    bool WasUnder = eventData.Underflow;
    ...
}

MyEncoder.OverflowOccured += this.EncoderOverflowTriggered;

If you want to enable/disable counting without re-sending the entire configuration, you can do so by using EnableCount(bool Enable).

Here are the configuration options:

Option Default Values Description
QuadMode NON_QUAD LS7366R.QuadMode enum values Determines the type of encoder that the device is expecting. If this is not set correctly, you will get no or incorrect readings. Check the specifications of the connected encoder for this information. If you are not sure, X1_QUAD is a good guess.
CountMode FREE_RUNNING LS7366R.CountMode enum values This is a bit complex, so you'll want to look in the LS7366R datasheet (page 4, MDR0 section) to understand the modes.
IndexConfig DISABLE LS7366R.IndexConfig enum values This is a bit complex, so you'll want to look in the LS7366R datasheet (page 4, MDR0 section) to understand the modes.
CounterMode BYTE_4 LS7366R.CounterMode enum values The number of bytes to use for the counter data
CountEnable true true/false Whether to count incoming encoder pulses. If false, Count will not change.
DivideClkBy2 false true/false ?
SynchronousIndex false true/false ?
FlagOnIDX false true/false Whether to put Index state into STR register
FlagOnCMP false true/false Whether to put Compare (Counter = DTR) state into STR register
FlagOnBW false true/false Whether to put Borrow (Counter underflow) state into STR register
FlagOnCY false true/false Whether to put Carry (Counter overflow) state into STR register

DataUnit

Like any sensor, the LS7366R outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"Count" int The current differential encoder step count since the sensor began reading

MAX31855

Implementation | Datasheet | Adafruit Breakout
Documentation to be added.

DataUnit

Like any sensor, the MAX31855 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"IntTemp" float The internal temperature of the sensor itself
"ExtTemp" float The thermocouple's temperature
"Fault" string Any faults that are detected

MPU6050

Implementation | Datasheet | Sparkfun Breakout
Documentation to be added.

DataUnit

Like any sensor, the MPU6050 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"AccelX" double X-direction accelerometer reading
"AccelY" double Y-direction accelerometer reading
"AccelZ" double Z-direction accelerometer reading
"GyroX" double X-direction gyroscope reading
"GyroY" double Y-direction gyroscope reading
"GyroZ" double Z-direction gyroscope reading

MQ135

Implementation | Datasheet
Documentation to be added.

DataUnit

Like any sensor, the MQ135 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"PPMReadingCal" float The air pollutant PPM, using the given calibration parameters

MTK3339

Implementation | Datasheet
Documentation to be added.

DataUnit

Like any sensor, the MTK3339 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"HasFix" bool Currently always true
"Lat" float Latitude
"Lon" float Longitude

VEML6070

Implementation | Datasheet | Adafruit Breakout
Documentation to be added.

DataUnit

Like any sensor, the VEML6070 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"UV" int UV light reading in μW/cm^2

VH400

Implementation | Info Page
Documentation to be added.

DataUnit

Like any sensor, the VH400 outputs DataUnit objects using GetData(). Here is the format:

Name Type Meaning
"RawReading" double The voltage that the sensor is outputting
"Multiplier" double The currently set voltage multiplier
"VWC%" float The soil moisture, in %VWC from 0.0-1.0, or -1 if the input is not valid

Logo

Quick Links:
NuGet
Pin Diagrams: RPi | BBB
Developers: CaiB, Baldstrom

General Info:
Home
Common Issues
Getting Started
Supported Devices

Sections:
Logging
DataLog
Filters
Hardware I/O:
- BeagleBone Black
- Raspberry Pi
- Pin Diagrams: RPi | BBB
- GPIO: Using | For Beginners
- PWM: Using | For Beginners
- ADC: Using | For Beginners
- I2C: Using | For Beginners
- SPI: Using | For Beginners
- UART: Using | For Beginners
- CAN: Using | For Beginners
Networking
Sensors
StateStore

Other: Interesting Case Studies

Clone this wiki locally