I have been attempting to establish I2C communications with a Lego Mindstorms Ultrasonic sensor.
It seems this device has a few quirks, thanks to its I2C protocol being bit-banged by a microcontroller.
After trying everything I could think of to get this device to work, I found some reference on a nxtasy forum that suggested the device doesn't strictly comply with the I2C protocol, and requires a few "extra states" to be implemented for read operations.
I tracked down the source code for the LeJOS firmware, that apparantly has special handling of this type, and found the following statement:
// Note: It appears that the Lego ultrasonic sensor needs a
// stop and an extra clock before the restart.
The state machine (also bit banged) that implements this logic only adds the extra clocking etc during a read command, just before the restart operation. I think this explains why I have been able to write to the sensor, but not read back from it.
SO...I'm thinking perhaps I may be able to directly toggle the SDA and SCL pins by creating a DigitalInOut object using the same pins, then writing to them between I2C write & read operations to simulate the strange sequence that the NXT Ultrasonic sensor apparantly requres.
Any reason why this wouldn't work? Can a DigitalInOut object manipulate pins that are already in use by an I2C object without causing issues?
I have been attempting to establish I2C communications with a Lego Mindstorms Ultrasonic sensor.
It seems this device has a few quirks, thanks to its I2C protocol being bit-banged by a microcontroller.
After trying everything I could think of to get this device to work, I found some reference on a nxtasy forum that suggested the device doesn't strictly comply with the I2C protocol, and requires a few "extra states" to be implemented for read operations.
I tracked down the source code for the LeJOS firmware, that apparantly has special handling of this type, and found the following statement:
// Note: It appears that the Lego ultrasonic sensor needs a
// stop and an extra clock before the restart.
The state machine (also bit banged) that implements this logic only adds the extra clocking etc during a read command, just before the restart operation. I think this explains why I have been able to write to the sensor, but not read back from it.
SO...I'm thinking perhaps I may be able to directly toggle the SDA and SCL pins by creating a DigitalInOut object using the same pins, then writing to them between I2C write & read operations to simulate the strange sequence that the NXT Ultrasonic sensor apparantly requres.
Any reason why this wouldn't work? Can a DigitalInOut object manipulate pins that are already in use by an I2C object without causing issues?