Canada
Asked — Edited
Resolved Resolved by Rich!

I2cread

Good day,

I2CRead is no recognise in the scrip, it's on the list at the left but the only command for I2C functionning is I2CWrite.


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

United Kingdom
#1  

Have you looked at the examples?

I'm literally just about to look in to I2CRead.

Can you post the code you have been trying?

United Kingdom
#2  

Have a look at the I2C examples, the I2CRead command is used (and works) in the I2C example.


# Shift the bits over
# Set the LSB (first bit) to a 1
# When first bit is a 1 on i2c, that means
# it is a Read Address
$i2cAddress = 0x09

Print("BlinkM Address: $i2cAddress ")

# Tell BlinkM we want the RGB Values
i2cWrite(0, $i2cAddress, 0x67)

# Receive the RGB Values
$raw = i2cRead(0, AUTO, $i2cAddress , 3)

# Print the number of bytes
Print("Received: Length($Raw) Bytes")

# Print the hex value of each byte
PrintHex($Raw)

# Split the array of bytes and assign to each variable
$Red = GetByte($Raw[0])
$Green = GetByte($Raw[1])
$Blue = GetByte($Raw[2])

#3  

Thank you @Rich ! I2C is a very important part of the EZ-Board ..if not the most important, as it can piggy back many many sensors etc. .....and curiosity asks , why do you need to read the RGB values of the BlinkM ...I will take a bold leap here and think the reason is to have a base line from which to change the values and hence the color sequence.?

United Kingdom
#4  

The short and quick answer is you don't.

It's the example for I2CRead which was good since the BlinkM is one of two I2C devices I have to play with so I could test it. There could be a use for reading it but to be honest, you will have written the RGB value to it in the first place so you should know what it is.

Basically the above code (taken from the example) demonstrates how to read from an I2C device and use that information within ARC.

As you say, I2C is important. I2C opens up so much. I'm still getting to grips with it myself but I plan to use a fair amount of I2C devices in the future in order to expand my EZ-Bs and give more functions to my robots:)

#5  

Thank you Rich ! Now I anderstand my trouble, I was trying to make a read without a variable... I am too new in programming, I must think much more. Again, you are very helpfull Rich !

#6  

Thanks for the speedy reply and clear answer! .. I too will be using a I2C BlinkM for my project as well .....I am thinking that I2C reads and write scripts can also be uploaded to the cloud . There must be others that are using or will be using I2C cryptic commands:)

United Kingdom
#7  

I2C is simple... if you have a datasheet that's clear like the BlinkM one (ThingM are awesome for that, i've seen some I2C stuff that's got no info and near impossible to work out, ThingM have covered everything nicely and clearly in their datasheet).

I've put some BlinkM stuff on the cloud and there is a topic somewhere too I put up or added to when I got my BlinkM the other week. I only went through some basics like fading to colours and changing to colours, there is more that can be done such as programming sequences into the BlinkM itself which I haven't looked into (I plan to).

I will say I am very impressed with the BlinkM and unlike some other I2C devices the wire length isn't a major issue and it doesn't need any pull up resistors. Just plug it in and away it goes.

The only other I2C device I have at the moment is the LCD in Melvin which was easy to use thanks to the clear datasheet. I plan to get more I2C stuff as and when I can. When I do you can expect to see info and tutorials on them too (like I even need to say that, it should be a given by now).

#8  

Hello Rich, I made a copy of your example and I am playing with it but I do not anderstand correctly the answer I have for the last line.

Set the adress to read an angle

$i2cAddress = 0x31

show the adress in decimal

Print("BlinkM Address:"$i2cAddress)

read the angle

$raw = i2cRead(0, AUTO, $i2cAddress , 8)

Print the number of bytes

Print("Received: Length($Raw) Bytes")

Print the hex value of each byte

PrintHex($Raw)

just keeping for reference

$Red = GetByte($Raw[0]) $Green = GetByte($Raw[1]) $Blue = GetByte($Raw[2]) $dir = i2cRead(0, Auto, $i2cAddress, 8)

Result manually copie: Start BlinkM Address: 49 Received: 8 Bytes 0x3F 0x3F 0x3F 0x3F 0x3F 0x3F 0x3F 0x3F -- look like it's not fine, I am not sure if the device communicate Done (00:00:00.1092012) -- never the same ?