I have the following really small snippet...
require("I2C");
dofile("sd:/htu21d.nut");
// Create an I2C instance
i2c <- I2C(0);
// Set speed to 400 kHz
//i2c.speed(400000);
// Set address
//i2c.address(0x40);
local htu21d = HTU21D(i2c, 0x40);
local temperature;
local humidity;
temperature = htu21d.readTemp();
humidity = htu21d.readHumidity();
print("temp=" + temperature + "\n");
print("humid=" + humidity + "\n");
It runs and produces reasonable results the first time. However subsequent attempts to run it result in:
%%Runtime error [unable to open I2C device]
CALLSTACK
*FUNCTION [main()] sd:/htu21d_demo.nut line [6]
I'm sure I'm just doing something stupid...