Jameco.com has an interesting article on how to build your own Arduino microcontroller circuit.
The circuit relies on an ATMega328 microcontroller, and since it requires only component parts it is cheaper and has a potentially smaller footprint than the popular Arduino Boards.
NOTE: WE ARE NOT RESPONSIBLE FOR ANY DAMAGE YOU MAY DO TO YOUR NXT BRICK.
THIS EXERCISE PRESUMES SOME WORKING KNOWLEDGE OF ELECTRONICS.
In this exercise, I will walk you through interfacing a potentiometer (variable resistor) to the NXT brick.
You will need:
- A stripped NXT cable
- A potentiometer with a maximum resistance no more than
- A small piece of wire
- An NXT Brick
This exercise is derived and expanded from a chapter in Extreme NXT by Gasperi, Hurbain and Hurbain.
THEORY
The NXT monitors the potential difference between the black and white wires with an Analog-to-Digital (A/D) converter. The A/D converter converts this potential difference to a RAW value between 0 and 1023 (10 bits accuracy). This RAW value is given by the ratio
(1)
where is the maximum RAW value of 1023, is the voltage used by the NXT A/D Converter, and is the voltage drop between the black and white wires.
The circuit diagram looks like this:
I have a little potentiometer that can turn over a range of about to . Below is a diagram. The resistance between the leftmost and rightmost pins is the maximum resistance of . We will focus on the resistance between the leftmost and center pins, which varies based on the angle through which the potentiometer has been rotated. To keep things safe, we wire the center pin and rightmost pin together. This doesn’t affect the potential difference between the leftmost and center pins.
I will assume that it is a linear potentiometer (a pretty good assumption), which means that the resistance at any given angle is given by
(2)
where is the maximum angle of the potentiometer and is the maximum resistance.
Equation (2) says that if the angle then the resistance of the potentiometer , and if the angle then the resistance of the potentiometer is maximum .
Looking at the circuit diagram for the A/D converter, the potential drop across our potentiometer (represented by resistor ) is given by the typical voltage divider relation
(3)
We can now substitute (2) into (3) so that the voltage between the black and white wires is determined by the angle of the potentiometer rather than its resistance. Then we can substitute the result into (1) to get an equation for the RAW value
(4)
with my particular values, this is
This formula will let us predict the NXT RAW value based on the angle of the potentiometer.
For my potentiometer, I find that a maximum angle of gives me a maximum value of 93. This is less than 7 bits of information, and each RAW value corresponds to . If you want a nice angle detector, you will probably need a potentiometer!
TRY IT
1. Before beginning, you need to cut and strip one of the NXT cables so that you can interface with the wires directly. I have placed a layer of solder on mine, so they can be inserted into a breadboard for easy connecting.
2. Next connect the center and right pins of the potentiometer together with a wire
3. Plug the other end of the NXT cable into the NXT brick.
I wrote a simple NXT-G program to read the sensor and display the RAW value. Notice that the Touch Sensor actually reads the resistance between the wires. So we are just replacing the Touch Sensor with a potentiometer. We will use the raw number output of the Touch Sensor Block, which is represented by the 1010 0101 symbol. We then need to convert it to text so it can be displayed on the NXT LCD panel.
You may download it here, Potentio-01.rbt
or write your own.
When I try my potentiometer, I find that the RAW value goes from 0 to 95, pretty close to my predicted range of 0 to 93. So it works! Not bad considering I guessed that the potentiometer sweeps through and angle of .
Determining the Angle of the Potentiometer
Now, let’s convert this RAW value to an angle.
In Extreme NXT, the authors worry about the fact that the resulting relationship is nonlinear with respect to the RAW value. As far as I can see, this isn’t a problem. We simply solve (4) above for the angle in terms of RAW. We can output the angle if we wish, but here I’ll take it a step further and demonstrate the resulting equation by controlling a motor so that it maintains an angle equal to the angle through which I have rotated the potentiometer.
I will leave out the algebra. Try it yourself. Solve (4) for angle A:
(5)
for my potentiometer, this is simply
which is easy to code in NXT-G.
You can download my code here: Potentio-03.rbt
The motor control is a bit crude, but it works well enough for the demonstration.
Check out the YouTube video to see it in action!
Daniele Benedettelli introduces a MATLAB-based NXC Bluetooth Router. This router relies on connecting a master NXT Brick to a computer via USB. This master NXT Brick then can communicate messages to up to three additional slave NXT Bricks up to a distance of 10 meters from the master. This software would allow one to create small swarms of up to three LEGO robots, which is a nice starting point for investigating distributed robotic systems.
An article at NXTasy.org highlights a three-wheeled robot that moves in one dimension and detects signals from an external beacon that emits ultrasonic bursts. The robot relies on a microcontroller that runs a Kalman filter to perform and maintain spatial localization. The NXT software is implemented using the LabVIEW NXT toolkit
There are now several MATLAB packages for robotics, and specifically for the NXT. One paradigm is to run the code on a PC and have it communicate direct commands to the NXT Brick via Bluetooth or USB. I have found this paradigm to be a bit dangerous since in the event of a MATLAB crash or a miscommunication, the NXT Brick will continue with its last command until ordered to stop. This has the potential to destroy your robot. The paradigm that I prefer to use is to write several programs that run on the brick. These programs take commands from files on the brick that can be uploaded rapidly from the PC. The MATLAB code then is in charge of sending the command files and starting and stopping programs. In the event of a MATLAB crash or communication failure, the software running on the NXT Brick can be designed to terminate gracefully.
Here are the MATLAB packages that I know of. The first two are specifically geared toward the NXT; whereas the last is a general robotics package.
I have finally compiled building instructions for my Little Rover, which can be seen above in a 3D Rendering courtesy of POVRay. An earlier version of this rover can be seen in this YouTube video:
The complete detailed building instructions can be found here in this 94-page pdf file.
Warning: it is about 9MB in size. The design is not entirely compatible with the standard NXT Mindstorms Kit. This design relies on two touch sensors, several 1×9 bent liftarms, and as far as I can tell from Peeron, the NXT Kit has only two. This may require a little redesign. Other compatibility issues and their solutions can be found in the Parts List in the instructions.
The main file is called DriveSmart.rbt. Drive Smart runs four threads:
Drive Thread
The Drive Thread (lowest one of the four) drives until a warning flag is set by one of the other
threads. It then waits until it gets an all clear message via the Wait Until Free block, and then
it starts driving again.
Bumper Threads
There are two threads that monitor the bumpers.
The reaction is only activated if nothing else is currently commanding the robot. In this case the
bumper has been pressed and the robot will veer away from the hazard.
Ultrasound Thread
This thread monitors the ultrasound rangefinder.
The reaction is only activated if nothing else is currently commanding the robot. When the robot
comes too close to a hazard, the robot is commanded to stop. It then looks both ways and then turns
in the direction with more room. If the robot is within 10 cm of a hazard on both sides, it then
backs up.
The robot can roam about a wide variety of rooms and not get stuck.
He does not detect stairs though! So be careful.