JavaScript Sensor API
Overview
In addition to the Core API enabling you to work with sensors via I2C or other means, there is a list of specific sensors made available to you to use with an easy-to-use interface.
This consists of well-known sensors. Feel free to request additional, or changes to existing.
Consider the BMP280 Temperature/Pressure Sensor
You could communicate with it using JavaScript I2C, or, instead, something much easier!
| // Create an instance of the sensor
let sensor = new BMP280(0x77)
// Extract data - no direct I2C required!
sensor.GetPressureMilliBars()
|
Page Structure
For each sensor, in addition to the API description, useful details are made available. They are:
What |
Description |
Description |
What the sensor does. |
Product Page |
A page where you can see product info. |
Technical Page |
A page where you can see technical details. |
Github repo |
A link if the JavaScript interface mirrors a known library. |
Datasheet |
Datasheet of the sensor. |
Power |
Any notable power requirement details. |
Technical Details |
Useful technical details. |
Weather
SI7021 - Temperature, Humidity
SI7021 - Temperature, Humidity
API Description
| // create an instance of the sensor - addr automatically set to 0x40
// (takes 50ms to return)
let sensor = new SI7021()
// get temperature in celsius
// (takes 20ms to return)
sensor.GetTemperatureCelsius()
// get temperature in fahrenheit
// (takes 20ms to return)
sensor.GetTemperatureFahrenheit()
// get humidity as a percent
// (takes 20ms to return)
sensor.GetHumidityPct()
|
API Example
| let sensor = new SI7021()
Log(`sensor.GetTemperatureCelsius() = ${sensor.GetTemperatureCelsius()}`)
Log(`sensor.GetTemperatureFahrenheit() = ${sensor.GetTemperatureFahrenheit()}`)
Log(`sensor.GetHumidityPct() = ${sensor.GetHumidityPct()}`)
|
BME280 - Temperature, Pressure, Humidity, Altitude
BME280 - Temperature, Pressure, Humidity, Altitude estimation
API Description
| // Create an instance of the sensor - addr either 0x76 or 0x77
// (takes 120ms to return)
let sensor = new BME280(addr)
// Get temperature in Celsius
// (takes 1ms to return)
sensor.GetTemperatureCelsius()
// Get temperature in Fahrenheit
// (takes 1ms to return)
sensor.GetTemperatureFahrenheit()
// Get pressure in hPa
// (takes 1ms to return)
sensor.GetPressureHectoPascals()
// Get pressure in millibar
// (takes 1ms to return)
sensor.GetPressureMilliBars()
// Get altitude in Meters (estimated from sea level nominal pressure at 1013.25 hPa)
// (takes 1ms to return)
sensor.GetAltitudeMeters()
// Get altitude in Feet (estimated from sea level nominal pressure at 1013.25 hPa)
// (takes 1ms to return)
sensor.GetAltitudeFeet()
// Get humidity in percent
// (takes 1ms to return)
sensor.GetHumidityPct()
|
API Example
| let sensor = new BME280(0x77)
Log(`sensor.GetTemperatureCelsius() = ${sensor.GetTemperatureCelsius()}`)
Log(`sensor.GetTemperatureFahrenheit() = ${sensor.GetTemperatureFahrenheit()}`)
Log(`sensor.GetPressureHectoPascals() = ${sensor.GetPressureHectoPascals()}`)
Log(`sensor.GetPressureMilliBars() = ${sensor.GetPressureMilliBars()}`)
Log(`sensor.GetAltitudeMeters() = ${sensor.GetAltitudeMeters()}`)
Log(`sensor.GetAltitudeFeet() = ${sensor.GetAltitudeFeet()}`)
Log(`sensor.GetHumidityPct() = ${sensor.GetHumidityPct()}`)
|
BMP280 - Temperature, Pressure, Altitude
BMP280 - Temperature, Pressure, Altitude estimation
API Description
| // Create an instance of the sensor - addr either 0x76 or 0x77
// (takes 105ms to return)
let sensor = new BMP280(addr)
// Get temperature in Celsius
// (takes 1ms to return)
sensor.GetTemperatureCelsius()
// Get temperature in Fahrenheit
// (takes 1ms to return)
sensor.GetTemperatureFahrenheit()
// Get pressure in hPa
// (takes 1ms to return)
sensor.GetPressureHectoPascals()
// Get pressure in millibar
// (takes 1ms to return)
sensor.GetPressureMilliBars()
// Get altitude in Meters (estimated from sea level nominal pressure at 1013.25 hPa)
// (takes 1ms to return)
sensor.GetAltitudeMeters()
// Get altitude in Feet (estimated from sea level nominal pressure at 1013.25 hPa)
// (takes 1ms to return)
sensor.GetAltitudeFeet()
|
API Example
| let sensor = new BMP280(0x77)
Log(`sensor.GetTemperatureCelsius() = ${sensor.GetTemperatureCelsius()}`)
Log(`sensor.GetTemperatureFahrenheit() = ${sensor.GetTemperatureFahrenheit()}`)
Log(`sensor.GetPressureHectoPascals() = ${sensor.GetPressureHectoPascals()}`)
Log(`sensor.GetPressureMilliBars() = ${sensor.GetPressureMilliBars()}`)
Log(`sensor.GetAltitudeMeters() = ${sensor.GetAltitudeMeters()}`)
Log(`sensor.GetAltitudeFeet() = ${sensor.GetAltitudeFeet()}`)
|
Light
BH1750 - Lux
API Description
| // Create an instance of the sensor - addr either 0x23 or 0x5C
// (takes 1ms to return)
let sensor = new BH1750(addr)
// Tell the sensor the current temperature so it can account for the effect on its measurement.
// Default sensor temperature is 20C / 68F.
// (takes 0ms to return)
sensor.SetTemperatureCelsius(temp)
// Tell the sensor the current temperature so it can account for the effect on its measurement.
// Default sensor temperature is 20C / 68F.
// (takes 0ms to return)
sensor.SetTemperatureFahrenheit(temp)
// Take a low-resolution lux measurement (resolution 4 lux)
// (takes 40ms to return)
sensor.GetLuxLowRes()
// Take a high-resolution lux measurement (resolution 1 lux)
// (takes 200ms to return)
sensor.GetLuxHighRes()
// Take a high2-resolution lux measurement (resolution 0.5 lux)
// (takes 200ms to return)
sensor.GetLuxHigh2Res()
|
API Example
| let sensor = new BH1750(0x23)
Log(`sensor.GetLuxLowRes() = ${sensor.GetLuxLowRes()}`)
Log(`sensor.GetLuxHighRes() = ${sensor.GetLuxHighRes()}`)
Log(`sensor.GetLuxHigh2Res() = ${sensor.GetLuxHigh2Res()}`)
|
Magnetic
MMC56x3 - 3-Axis Magnetometer
MMC56x3 - 3-Axis Magnetometer
API Description
| // Create an instance of the sensor - addr automatically set to 0x30
// (takes 25ms to return)
let sensor = new MMC56x3()
// Get field strength along X-Axis in MicroTesla (uT)
// (takes 15ms to return)
sensor.GetMagXMicroTeslas()
// Get field strength along Y-Axis in MicroTesla (uT)
// (takes 15ms to return)
sensor.GetMagYMicroTeslas()
// Get field strength along Z-Axis in MicroTesla (uT)
// (takes 15ms to return)
sensor.GetMagZMicroTeslas()
|
API Example
| let sensor = new MMC56x3()
Log(`sensor.GetMagXMicroTeslas() = ${sensor.GetMagXMicroTeslas()}`)
Log(`sensor.GetMagYMicroTeslas() = ${sensor.GetMagYMicroTeslas()}`)
Log(`sensor.GetMagZMicroTeslas() = ${sensor.GetMagZMicroTeslas()}`)
|