Seminar Topics & Project Ideas On Computer Science Electronics Electrical Mechanical Engineering Civil MBA Medicine Nursing Science Physics Mathematics Chemistry ppt pdf doc presentation downloads and Abstract

Full Version: An Optical Mouse Sensor as an extension for LEGO NXT
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
An Optical Mouse Sensor as an extension for LEGO NXT
[attachment=21183]
1. Introduction
Assignment Description
This project is part of the Technology Masterclass of Industrial Design at the Technical University
Eindhoven. During this class, Master students get the opportunity to dive into some very diverse
elements of technology like electronics, mechanics, programming intelligent robots and creating a
new innovative sensor for LEGO NXT. This report describes the elaboration of the latter assignment.
Deliverables
• working model of the extension pack
• report in MS Word describing the extension pack
• technical documentation of the extension pack, such as technical drawings and UML models
• photos of the extension pack
• movie of the extension pack in action uploaded in high quality to SurfMedia and available for
download from there.
2. Sensor Choice
For a robot that is able to move itself, it is essential to know in what environment it is and where in
that environment it is located. Location, distance and speed are variables that can help a robot
determine it’s current state. A GPS‐sensor is able to give these variables, but are quite expensive and
not as accurate as you might need. A computer mouse is more accurate and can detect movement
smaller than a millimeter. For this reason I decided to look at computer mice as a new sensor for
LEGO NXT.
An ‘old’ computer mouse (fig. 1) detects movement mechanically through a ball inside that can rotate
in any direction. There are three wheels inside that are positioned against the ball, so that the wheels
are turning when the ball rolls. These wheels chop light beams in front of light sensors so a
movement, speed of movement and direction can be detected. This kind of mouse is also called a ball
mouse.
Fig. 1: A ball mouse1
A different kind of computer mouse is the optical mouse (fig. 2). The optical mouse has a
sensor inside that is actually a very small camera. It detects changes in pictures of the surface
underneath it. This is then converted to an amount of movement into the X‐ or Y‐direction. A red LED
illuminates the surface to increase the contrast of the pictures.
fig. 2: My optical mouse (before this project)
I chose to go further with the optical mouse sensor for the following reasons:
‐ it has no mechanical parts that can break or wear off;
‐ it can be used on more surfaces than the ball mouse;
‐ a ball mouse collects debris inside the casing
‐ it’s quite small (smaller than the ball mouse);
‐ it’s cheap;
‐ I see a lot of learning opportunities here.
The following chapters will describe how to create an optical mouse sensor for the NXT from a cheap
optical mouse.
3. Hacking the optical mouse
I have used some tutorials I found on internet2,3. My approach was quite similar, but eventually I need
to read the data with the LEGO NXT. My first step is to hack the mouse read the data from the sensor
with Arduino4.
Tutorial for hacking the optical mouse
This tutorial will explain what steps you need to take to hack the optical mouse and read the data
with Arduino. First take an old optical mouse or buy a cheap one. Fig. 2 shows how my mouse looked
like.
1. Open up the mouse
Underneath the mouse there’s a screw you need to unbolt. This will open up the mouse. Here you
find the circuit board with the sensor (the chip in the middle), a LED, buttons and the scroll wheel (fig.
3). Underneath the circuit board is the lens clip (fig. 4), that is used to amplify the light and functions
as a lens for the sensor.
fig. 3: Mouse opened up
fig. 4: lens clip
2. Look up the datasheet
The sensor is located in the middle of the circuit board. Search for the datasheet of the sensor on the
internet and look up the pin connections. You need the following pins:
• +5V (input voltage)
• GND (ground)
• SCK (serial port clock)
• SDIO (serial port data)
In the case of my sensor I need pin 3, 4, 6 and 7 (fig.5)
fig. 5 mechanical drawing + pinout table of the datasheet5
Make sure that your sensor doesn’t have the USB‐controller embedded inside the chip. The first
mouse I tried to open had this kind of chip (see fig. 6), which means that you can’t capture the data
without a USB‐protocol. Using a 2‐wire serial port communication is much more preferable.
fig. 6: a mouse with the USB controller embedded in the chip of the sensor
3. Solder wires
Solder wires to the 4 needed pins. It’s useful to choose different colors, so you’re able to distinguish
the clock and data lines easily (fig.7).
fig. 7 ‐ Wires soldered to pins 3, 4, 6 and 7
4. Remove the USB‐controller
This step is not necessary, but if you’re not going to use the mouse anymore it might be better to
remove the USB‐controller to prevent the controller of taking over the data connection. Removing
the controller can be done by removing the soldered tin and scrape the controller of the circuit board.
5. Connect it to Arduino
Choose two digital pins on the Arduino for the clock line and the data line and connect the +5V and
GND of the mouse to the 5V and Gnd of Arduino. Upload the sketches (programs for Arduino)
provided by Martijn Thé based on sketches of Benoît Rousseau. Make sure that the right registers If
you open the Serial monitor in the Arduino software you’ll see the x‐ and y‐values. In the next
paragraph I’ll explain how this works.
Get the data from the optical mouse to Arduino
In the datasheet of the sensor there is a whole section about the synchronous serial port. This port is
used to set and read parameters from the sensor. The port uses two wires and is a half duplex port,
which means that it can talk both ways, but not at the same time. The microcontroller, in my case the
Arduino, always initiates communication and is called the master (the sensor is the slave). The two
wires are the serial port clock (SCK) and the data line (SDIO). The serial port clock is generated by the
microcontroller.
The microcontroller can try to read parameters like the X‐ and Y‐movement, but can also write to the
sensor to change parameters like for example the configuration of the sensor. For thiswe need a read
and a write operation. The clock line is generated by the microcontroller and is preferably pulsing at a
length of 250 ns per pulse. The function of the clock is to synchronize data transfers.
Write operation
A write operation is initiated by the microcontroller and consists of two bytes. The first byte contains
a 7‐bit address and has a “1” as its most significant bit (MSB). This 1 means that the microcontroller
wants to write data and the address is a register where you want to write to. The second byte
contains the data you want to write. The clock synchronizes the data transfer, because the
microcontroller changes SDIO on falling edges of the clock and the sensor reads SDIO on rising edges
of the clock.
fig. 8: Write operation
Read Operation
A write operation works kind of the same; it also consists of two bytes. The first byte has a “0” as MSB
(to indicate a read operation) and a seven bit address to request the data from a certain register. The
second byte is the data send from the sensor to the microcontroller. After the last bit of the address
there is a delay of 100 us for the sensor to prepare the data.
fig. 9: Read Operation
Registers
In the datasheet there is a list of addresses (fig. 10). From address 0x42 and 0x43 you can get the
Delta_Y and Delta_X (X‐ and Y‐movement). Let me give an example: If I want to read the Y movement
I have to perform a read operation. The first byte the microcontroller sends is 0x42, but with a “0” as
MSB bit. In bit‐form this looks like this: ”01000010”. Then there is a delay of 100 microseconds and
after that the sensor will give a byte containing the movement of the sensor in the Y direction.
fig. 10: Addresses of the registers of the ADNS‐2083
In the next chapter I’ll explain how to get this data to the LEGO NXT.
4. Hacking LEGO NXT
The NXT is actually a microcontroller like Arduino. For this assignment we need to program the NXT
with leJOS, a JAVA‐based language for the NXT. I couldn’t figure out how to read the sensor directly
with the NXT using leJOS. Therefore I chose to to read data from the sensor with Arduino and let the
NXT communicate with the Arduino.
LEGO NXT cables:
The cables of the NXT are actually slightly modified JR12 cables (telephone cables). The modification
lies in the connector. Inside the cable are 6 wires that connect to an input port of the NXT (fig. 12).
fig.12: Input port of the NXT6
Communication between Lego NXT and Arduino through I2C:
I2C is a protocol developed by Philips. The protocol of reading the optical mouse sensor is quite similar
to this, but not entirely. In the case of the optical mouse sensor, there is no device address. You need
this to start up the whole communication. For this reason I couldn’t read the sensor directly from the
NXT.
In my project, the Arduino is the slave and the NXT is the master. In Arduino there’s a library called
“Wire.h” that can be used for I2C. With this library you can set the device address, I used the number
127. Whenever the NXT requests data, I use this library to send an array of two bytes; the x‐ and yvalue.
In leJOS I request data by using the I2CSensor class. I created a class for the optical mouse sensor that
extends the I2CSensor class. Now I can make several objects of this class, which can be useful when I
want to use more than one of these sensors at the same time.
After the NXT has initialized communication with device address 127, it can request data. After this
request I get a response of two bytes, which I store in an array with two indexes . The first index of
the array is the x‐value and the second is the y‐value.