Bluetooth communication between Arduino and Lego NXT using leJOS

The Lego NXT is a robotics platform that makes it easy to start creating robots with standard Lego pieces, an “intelligent brick” and a wide variety of sensors and actuators. One of the problems of the NXT is that it only has 3 motor ports and 4 sensor ports. If you want to extend the amount of sensors and actuators that the NXT can have access to, a solution is to use an Arduino with a Bluetooth module. In our case, we used the leJOS firmware for the NXT, which allows us to write the code for the robot in Java.

The first step is to pair both devices, which you can do by going to the Bluetooth menu  on the NXT. Afterwards, you can access the Arduino through its Bluetooth ID via the Java code:

It is VERY important that you use the RAW mode (NXTConnection.RAW) when connecting to a Bluetooth device other than another NXT brick. By default leJOS sends some extra bytes with every communication, which can mess up your data transmission. After the connection is established, you can open the input and/or output streams and start sending data:

Make sure that you read data from the stream on a different thread if you don’t want your robot to block while waiting for data. In our case, the NXT brick was communicating with an Arduino. Here’s an example of how that looks like:

Something that gave us some headaches was the difference between Serial.print() and Serial.write(). The value that you pass to Serial.print(), even if it’s an int, gets converted to its corresponding character. For instance, Serial.print(5) will send the character ‘5’, which corresponds to the ASCII value of 53. If you want to send the integer 5, use Serial.write(5).

A quick analysis of the e-puck’s infrared proximity and light sensors

Recently I have begun developing for the e-puck robot as part of my thesis. The e-puck is a small (75 mm in diameter) differential drive robot that has several sensors and actuators, such as 8 infrared proximity sensors, a VGA camera, a 3D accelerometer, 3 microphones, a speaker and two wheels. For my research, I needed to model the way the infrared proximity sensors reacted to close objects and to light.

Proximity sensors

The e-puck can sense obstacles around itself via the use of 8 infrared proximity sensors, which are positioned around its perimeter. The measurements were taken with the wheels of the e-puck moving, but the robot itself was fixed in place. They were taken for 10 seconds with a sampling rate of 10 samples per second (for a total of 100 samples) and repeated at increments of 0.5 cm from 0 cm to 2 cm and at increments of 1 cm from 2 cm to 12 cm. The measured sensor was perpendicular to the wooden wall. The following data is the average values for 4 of the 8 sensors (sensors number 0, 2, 5 and 7) in two different e-pucks:

You can download the data as a CSV file. Included in the file is also the standard deviation: epuck_proximity_sensors.csv

Light sensors

The proximity sensors also can be used as light sensors. Following the same method as above, the e-puck was placed next to an LED lamp and measurements were taken for 2 of the 8 sensors (sensor 2 and sensor 5). The following data was gathered:

You can download the data as a CSV file. Included in the file is also the standard deviation and the reference value for the ambient light: epuck_light_sensors.csv