i2c Device
Hi John,
Is there a way to determine the Device# for an i2c device in microBlocks ?
I am looking at an implementation code for MaqueenCar that uses i2c to drive the motors, and I am trying to duplicate that in microBlocks.
I have the following Maqueen code located: https://github.com/jhlucky/maqueen/blob/master/maqueen.ts
//% weight=90
//% blockId=motor_MotorRun block="Motor|%index|dir|%Dir|speed|%speed"
//% speed.min=0 speed.max=255
//% index.fieldEditor="gridpicker" index.fieldOptions.columns=2
//% direction.fieldEditor="gridpicker" direction.fieldOptions.columns=2
export function MotorRun(index: aMotors, direction:Dir, speed: number): void {
let buf = pins.createBuffer(3);
if (index==0){
buf[0]=0x00;
}
if (index==1){
buf[0]=0x02;
}
buf[1]=direction;
buf[2]=speed;
pins.i2cWriteBuffer(0x10, buf);
}
Last line writes to i2c Device 0x10 (I think???) a three byte buffer array/list.
I have duplicated the same in microBlocks using:
Device =16,
a list of 3 entries with corresponding values;
but I do not get any activity.
PS: Is there a way to add a category of “Question” to the KIND* entry below?
Comments (2)
-
repo owner -
repo owner - changed status to resolved
- Log in to comment
I usually check that an I2C device is available by requesting the value of its first register:
If this results in a negative number then no I2C device with the given device ID responded. If you get 0 or some other positive number, then there is device with the given ID. I then check the spec sheet for the device for other registers I can query. Many I2C devices have a “who am I” register that returns a specific value. Getting that value back gives confidence that you’re actually communicated with the expected I2C device.
Re: Is there a way to add a category of “Question” to the KIND* entry below?
I’ll check. But if there isn’t, just submit your question as a “bug” with “Q:” in the title.