Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Electric Imp Device Code for Si7020 Breakout Board
// Define the Sensor Address
const ADDR = 0x80;
// Define register map
const HUMIDITY = "\xE5";
const TEMP_FROM_RH = "\xE0";
// Specify the update rate in seconds
const update_rate = 60;
// Define the i2c periphrial being used
i2c <- hardware.i2c89;
// Configure said periphrial
// function to read the Si7020 sensor via configured i2c periph
function readSensor() {
// Read the humidity, sensor uses i2c clock stretching to hold the transaction while it is
// taking the measurement, this will block the thread for 16.5ms (typical)
local rh =,HUMIDITY,2);
// Part of taking a humidity reading is getting the temp, so read that out
local t =,TEMP_FROM_RH,2);
// Push this data off to the Agent for processing, avoid dooing much math so that we
// can go back to sleep...
// Schedule the next reading
imp.wakeup(update_rate, readSensor);
// start the loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment