Asked — Edited
Resolved by Rich!
I2CRead is no recognise in the scrip, it's on the list at the left but the only command for I2C functionning is I2CWrite.
Upgrade to ARC Pro
Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
I'm literally just about to look in to I2CRead.
Can you post the code you have been trying?
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
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).
# Set the adress to read an angle
$i2cAddress = 0x31
# show the adress in decimal
# 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
# just keeping for reference
$Red = GetByte($Raw)
$Green = GetByte($Raw)
$Blue = GetByte($Raw)
$dir = i2cRead(0, Auto, $i2cAddress, 8)
Result manually copie:
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 ?
I now anderstand a lot more about it because of you. I still have a big amount of work to do to anderstand the data I receive and principally to format the received data but I am progressing bit by bit. The I2C is easier than expected, probably because of the EZ two instructions. I know now I had to make a write and just after a read, now i have to look in the EZ instruction set to determine how to format the data. In the cloud I had posted a very little example of my progress. Thank you again Rich, you have opened my eyes.
In that case, let's have a look at the code that's needed (Note: I do not have a GY-26 to test any of this with but basing it on the datasheets available, please post if anything is confusing or doesn't work and I'll do my best to help).
First I assume it would be good practice to calibrate the compass module, you may skip this if you don't think it needs calibrating. It is assumed the robot is mobile and you use a Movement Panel to control it. It is also assumed it takes 1000ms for one single rotation of the robot - adjust the variable $rotationtime to suit your robot design. It is also assumed you have not changed the default I2C address.
Add a new EZ-Script control or new script to the script manager and call it Calibrate Compass. Copy and paste the code below into the script and run to calibrate (or add as part of an init script with a ControlCommand)
Now it's calibrated you want to know the robot's direction so again, the same assumptions as above and add a new EZ-Script control or script to the script manager called Compass Read. Copy and paste the code below.
The current angle should be stored in the variable $currentangle for use anywhere else in the project.
You can have this on a loop with a slight delay to avoid saturation of the comms, if that's what you need just add in a label at the top
and a sleep and goto at the end
Hopefully that will work but without the device I can't test it and it is based upon my interpretation of the datasheet. However there should be enough there for you to get cracking with and again, if not just ask and I'll delve in deeper.
Byte0 is ASCII enter
Byte1 is ASCII new line
Byte2 is ASCII angle hundreths
Byte3 is ASCII angle tens
Byte4 is ASCII angle bits
Byte5 is ASCII decimal
Byte6 is ASCII angle decimals
Byte7 is ASCII Calibration Sum
I kinda missed the explanation above however did show the script stripping the bytes individually and then putting them back together (which is something I've never done before so please say if it works or not).
It also can read the temperature from the looks of it, have a look at the datasheet and (if the above works for the angle) have a look to see if you can figure out how to read that If you can't and you need help feel free to ask.
# Read From GY-26 I2C Compass
# Default address 0xE0
# Read the current angle
I2CWrite(0, 0xE0, 0x00, 0x31)
$Raw = I2CRead(0, auto, 0xE0, 8)
# Split the array of bytes and assign to each variable
$anglehundreths = GetByte($Raw)
$angletens = GetByte($Raw)
$anglebits = GetByte($Raw)
$angledecimalpoint = GetByte($Raw)
$angledecimal = GetByte($Raw)
# Combine results to make up angle
$currentangle = $anglehundreths$angletens$anglebits$angledecimalpoint$angledecimal
With this I have a result but it look like I need to make a better installation, too much interference to have a constant reading.
Thank you very much Rich, i now anderstand much more the formating of the data for this unit and in script.
DJ Sure has make a very good scriting tool and you anderstand it very well. I keep looking at all your post because you give hints and very usefull advice,