The LEGO MINDSTORMS system does something called bit shifting: you need to add a 0 at the end of the address when you call on it. In this example, we set the slave address to 0x0A, which is hexadecimal. In both of our Arduino examples, we have to setup a few things to get going. Setting the Arduino up for I2C: Assigning an Address
#ROBOTC FOR ARDUINO SOFTWARE#
We will show the NXT software in Labview for LEGO MINDSTORMS, and RobotC.Īll of the code can be downloaded from this package. The software for the Arduino does not change: it is the same software for each programming language. We’ll divide this into two parts: the Arduino software, and the NXT software. This should provide the necessary power to power the Arduino, but be sure not to overload the NXT (recomended 50 mA current consumption as a maximum by LEGO). In this example, we power the Arduino with the USB line (which we keep hooked up to our computer) however, you could easily power your Arduino with the NXT: simply connect the 4.7V line (VCC) to the “VIN” connection on the Arduino. In this example, we’re going to connect only the SDA, SCL lines (for communications) and the ground (GND) line to equalize the communication voltages. You can see an overarching view of everything below. The setup we’ll wire together will look like this: NXT –> Breadboard Adapter –> Arduino. Notice the pullup resistors connected from SDA and SCL to the 4.3V line. We will need ground to be connected, and if you’re going to power your Arduino off the LEGO Mindstorms system, you will need the 4.3V connected to the VIN pin on the Arduino. The schematic shows the NXT plug on the left hand side of the drawing, and the Arduino on the right hand side. Setting up the Hardware.įirst, a schematic of what we’re aiming for. If you use the Dexter Industries Breadboard Adapter for the LEGO MINDSTORMS NXT the pullup resistors are already built into the board. Resistor values are important to ensuring you can communicate at a fast speed with the NXT. If the device you are communicating with is operating at 3.3V (rather than 4.7V) you can use 43k resistors. Typically resistor values of 82k are used. These resistors go between the SDA and 4.7 V line, and the SCL and 4.7V line. I2C on the NXT requires a pullup resistor. When the master demands information, the slave provides that information.ĭiagram of the Pullup Resistors used to connect an I2C line to the NXT. When the master sends a command, the slave drops everything and listens. The device being controlled is referred to as the slave. The master ( always the NXT) always controls the communications, and always sets the communications clock for both devices. The other wire is for sending data (data is sent and received by both devices at the same time), and is usually referred to as “ SDA“. The clock line is usually referred to as “ SCL“. One wire provides a clock: this makes sure that both devices are sending information at the same speed. I2C is called a “two wire interface”, because it uses two wires to communicate. Both are very similar, but different.Ī little background on I2C and the NXT.
#ROBOTC FOR ARDUINO HOW TO#
In this example, we show you how to send commands to the Arduino from the NXT and how to write a program that requests data from the Arduino. Although it’s beyond this tutorial, with clever coding and polling, the Arduino can be setup to control the NXT. The NXT must always be a master and can never be a slave. In this tutorial, we setup the Arduino as an I2C slave, and the NXT as an I2C master. The NXT and the Arduino can be made to talk over I2C.
#ROBOTC FOR ARDUINO FREE#
This is probably the fastest way to free your NXT and add your own sensors and devices: when you connect the NXT and the Arduino and the world is yours! This example can be extended to use the Arduino as a sensor for the NXT, and to develop your own sensors for the LEGO MINDSTORMS NXT system. In the demonstration, we use an Arduino Uno, but the example we’ve written can be used for just about any of the versions of Arduino. In this HowTo, we’ll show you how to get your LEGO MINDSTORMS NXT and your Arduino to talk.