, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here
Is there new information about I2C? The last reference I can find is:
I am trying to write a script that will have the EZ-B v4 respond as an I2C slave to a master I2C device. To do this, the master device sends the EZ-B data, the EZ-b is then able to respond by sending data to the master.
The script fails and the WiFi connection is broken.
I have to power down, then reconnect the EZ-B.
Here is a script snippet:
(The address of the master is 0x4)
>> The master is in a loop I2C writing a '1', then I2C reading <<
$V1 = I2CRead(0,0x4,1)
Print ("V1 = "+$V1)
I2CWrite(0,0x4,40) #decimal 40 is the value I want written
I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.
Also, consider reviewing the Learn section for informative lessons and activities.
Check it out!
You are unable to "read" unless there is a request sent.
Attempting to read i2c will pause forever (as you are experiencing) without knowing there is data. Do something like this...
1) Send a request for data
2) Read the known data size that has been requested
For more information, look at the i2c BlinkM 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
# Split the array of bytes and assign to each variable
$Red = GetByte($Raw)
$Green = GetByte($Raw)
$Blue = GetByte($Raw)
Thanks for the quick reply.
Your script is setting the EZ-b as the master and the BlinkM as the slave.
I need the EZ-b to be the slave.
The EZ-B is unable to be a slave - it's configured as a master by factory.
You could essentially run your robot with 2 masters. The ez-bv4 can communicate serially to the Arduino. You could write a program on the Arduino that could translate your serial data from the ez-b and create I2C commands to send to the EV3 controller, probably wouldn't be that efficient but it's an idea.
Otherwise, I would suggest to try interfacing the motors and sensors from the EV3 directly to the ez-b. I believe LEGO peripherals also communicate as I2C slaves, but I don't have enough info on these new LEGO kits to confirm that.
From what I read, it looks like the EV3 can only be a Master (no slave option) and the EZB as DJ said likewise is designed to only be a Master.
My thoughts are you would either need to use an Arduino in between the two. Or it might be possible to communicate with the LEGO EV3 over wifi using TCP/IP.
This might work.
Jeremie and JustinRatliff,
Good ideas and I will look into both suggestions.
Thanks to you both.
Now - how does the 'resolved by' credit get assigned?