So I’ve been playing with this a while and have gotten no where…
Hope you can help. I want to read the measurements of the nunchuck basically. I’m surprised noone has done this for the imp =(. I tried to base it on the example in the wiki (I’m sure you can tell )
`// Ambient Light Sensor Firmware
// A great example of how to communicate with a peripheral via I2C
server.log(“Imp Light Sensor Started”);
// I2C Interface to TSL2561FN Light Sensor
// Pin 8 is SCL
// Pin 9 is SDA
// set the I2C clock speed. We can do 10 kHz, 50 kHz, 100 kHz, or 400 kHz
hardware.i2c89.configure(CLOCK_SPEED_400_KHZ);
// the slave address for this device is set in hardware. Saving it here is helpful.
local alsAddr = 0x52;
// function to tell the sensor to start taking a reading
// we send this command, then wait a bit, then collect the reading
function initialize() {
// i2c.write takes two arguments: address and string.
// here, we send 16 bits of data: the first byte is a register, the second is a command
// your needs will vary with the device you are trying to communicate with
hardware.i2c89.write(alsAddr, “\x40”);
hardware.i2c89.write(alsAddr, “\x00”);
// 400 ms required to integrate and complete conversion
}
function startAls() {
// i2c.write takes two arguments: address and string.
// here, we send 16 bits of data: the first byte is a register, the second is a command
// your needs will vary with the device you are trying to communicate with
hardware.i2c89.write(alsAddr, “\x00”);
// 400 ms required to integrate and complete conversion
// schedule the imp to go read the sensor in half a second, after it's done taking a reading
imp.wakeup(1, readAls);
}
// function to collect the reading from the sensor.
// this function is long mostly because the sensor wants us to do funny math with the values
function readAls() {
// i2c.read takes three arguments: address, subaddress, and number of bytes to read
// subaddress is often used for a command or a register to read from
// if you don’t need a subaddress, use “” for none
local reg0 = hardware.i2c89.read(0x52, “\x7E”,2);
// local reg1 = hardware.i2c89.read(alsAddr, “1”,6);
server.log((reg0));
// schedule the imp to take another reading in 5 minutes
imp.wakeup(2, startAls);
}
imp.configure(“Imp Light Sensor”, [], []);
initialize()
startAls();
//EOF`