Lego Mindstorms EV3
4 stars based on
Owing to its very technical nature, this article is primarily aimed at those having some skills in electronics. It is therefore not surprising that Lego chose to use it in its NXT intelligent brick. A good understanding of I2C is therefore essential for robotics engineers versed in electronics who would like to design their own sensors, or connect their own circuits robot lego nxt brick the Lego Mindstorms NXT robot. I2C is a half-duplex, bi-directional, synchronous, serial data bus.
It makes simple and efficient communication possible between a microcontroller and one or more actuators or sensors. Without going into too much detail, but without omitting any important points either to ensure you can all build your own sensors, we will be looking here at the basics of I2C communication during a dialogue between our brick and these actuators.
An I2C conversation works on the master-slave principle. In an I2C transaction robot lego nxt brick the NXT brick and its sensors, the NXT brick is robot lego nxt brick the master and the sensors are necessarily slaves even if technologically speaking they are able to act as mastersi.
As the diagram above shows, four wires are needed for communication between the sensor and NXT brick the NXT connection cables you use contain these four wires:. How does the I2C protocol work? The basic element is called a transaction. Robot lego nxt brick these two bits is the actual communication itself. In master-slave mode, it is always the master that initiates a transaction.
Robot lego nxt brick first transaction will be for the master to write the I2C address of the sensor it is addressing to its connection bus. When you plug the NXT ultrasonic sensor directly into port 1 for examplethere is just one sensor and therefore no risk of contention.
The image below shows just such an initial transaction, using the software supplied with the Saleae MHz, channel, USB logic analyzer. As the image above shows, a transaction begins with a START bit characterized by a falling edge in the data signal while the clock is in its high state.
Then come 8 data bits. The first 6 bits are 0 low SDA potentialthe 7th is 1, and lastly the 8th is 0. All of which means that 0x02 has been written, i. As we said earlier, the first thing the master does is write the I2C address of the sensor with which it wants to communicate to the data bus. Lastly, the 8th bit is 0, indicating it is a write message. The 9th bit is 0, this being the ACK acknowledgementi.
Once the circuit has been built, the software supplied with the Saleae logic analyzer has to be downloaded and installed. This software is available at http: Once that has been done, all that remains is to configure the software to run in I2C mode so it takes care of everything. To do that, go into Analyzers and select I2C mode. Now, we need to select the data acquisition time. As the image below robot lego nxt brick, we are selecting M samples at 16 MHz, which equates to 6.
For I2C communications, a minimum of 2 MHz is advisable, but not necessarily needed. However, the faster we set it, the less likely we are to miss any data. Well, more or less, since while we are ready to run a data acquisition exercise, what do we want to acquire?
How do we ask the sensor to send us its version number? The following NXC code does this task. The language used is unimportant here because the logic analyzer makes no assumptions about the type of program generating a communication, it just intercepts the message and analyses it. We could consequently have offered a program written in any language. A pop-up window with a cursor then appears in the centre of your Saleae logic analyzer capture software screen.
This means that robot lego nxt brick I2C transactions are being analyzed. Once the analysis has finished, roll your mouse scroll wheel downwards to get robot lego nxt brick widest view of the full frame the mouse scroll wheel zooms out, which is very useful.
You should see a different area on your screen. Position the mouse cursor on the area bordered in red and zoom in roll the mouse wheel forwards. Your screen then looks like the image below:. Robot lego nxt brick then waits to receive in robot lego nxt brick a number of data items equal to the content of the size variable 4 in this case.
It can be seen here that once the last data item has been received, the brick does not transmit robot lego nxt brick ACK, but a NAK, meaning the brick is no longer expecting anything from its slave. Transmission is ended by sending a STOP signal, i. With this relatively straightforward example, we can clearly see the usefulness of a frame analyzer such as the Saleae logic analyzer, because even if some of you are not yet sure of its robot lego nxt brick, this small technological wonder will enable you to debug plenty of programs, since it performs a quick and easy check on the integrity of transactions between one or more of your controllers or actuators.
Today, it is the companion robot lego nxt brick choice when learning the basics of electronic communications, partly because of its simple user interface, but mainly because of the service it provides, dissecting most electronic communication standards such as I2C, SPI, 1-Wire and many others for you, leaving you with a clear, readable, recordable and easily interpreted timeline.
First of all, what is I2C? How the I2C protocol works in master-slave mode An I2C conversation works on the master-slave principle.