I am usually not a very adventurous person: I liked my electronic products simple and stupid, never opening them up to reveal the wonders inside. That was until I changed schools, where I was introduced into an environment of tweaking with things and where I encountered a whole new range of people. I urged myself to get involved, and having screwed up my first year by accidentally doing the exact opposite, sought to catch-up in my next year, the one I just finished. Just adding, I believe I have accomplished that!
My altered RJ12 socket |
So, lets start on this project. I quickly realised that the annoying NXT cables will not fit into a standard RJ12 socket (telephone cable). Having purchased one and made it breadboard compatible, looked at this guide and decided that my 3 remaining cables, although replaceable, were far too precious to be mutilated like that. So I opted for a more interesting way: cut it!
Yes, you heard me. Instead of using two 30cm cables to make two modified ones, I used one cable and cut it in half, giving me two 15cm modified cables to use with the sensors and motor. I needed to create cables that were breadboard compatible so I could test them with my Arduino. A friend of mine and I worked out the best way to execute this, which I shall describe below.
The Cable
I assume here that you have basic soldering skills, a soldering iron and wire strippers, as every good technician or keen engineer should have.
Firstly, take the NXT cable, attainable at ebay or Lego.com, and cut it in to two equal halves. Then strip the insulating black plastic to reveal the six coloured wires. Strip these as well to expose the copper.
The cut NXT cable |
Then, you will need to buy either some single-core wire or one of these jumper cables. This has to be stripped and soldiered to the exposed end of your modified NXT
Half a jumper cable soldered to NXT cable |
All wires soldered |
To add a professional feel to it, avoid interference and to make your cable sturdier, I would reconnect heat shrinking the connection, in such a way that the colours from the original NXT cable can still be seen.
Testing |
The Motors
I started testing this, thinking it would be somewhat simpler to work out than the sensors, being an output, not an input. This site provided me with the information as to what signal would have to be sent through each pin. I wrote up an initial Arduino sketch to send high and low signals to pins 1 and 2 respectively, hooking the pins directly into the Arduino without a protective diode or Full-H motor driver IC (something I would not recommend!), putting my beloved Arduino at great risk, as I did not have the necessary equipment, like a SN754410 or L293D. They still worked fine though, just not as well.
By pulsing (PWM) the pins, I was able to get the motor to spin at different speeds. The harder part was to get the encoder pins to send data back; more specifically, what type of data they were sending back and how to read it.
Initial testing |
This is a schematic I made depicting how my tests were carried out, adding in the SN754410 for added safety. I am still not quite sure how to use PWM with one of these chips, whether to pulse the enable or input, but I am sure my electronic-savvy friends will pummel me with operational amplifiers when I get back to school for getting it wrong! I have also included the code.
Image developed using Fritzing. For more circuit examples, see the Fritzing project page |
/*
Lego NXT actuator data connection test
Reads the analog value at pins A4 and A5, being pins 6 and 5 on the NXT cable respectively.
The motor enable pins are connected to I/O pins 3 and 5
A push-to-make button voltage divider circuit (10kΩ) is connected to I/O pin 2.
This code was written (badly) by Nicolas Weninger, auther of TheCompBlog.
THIS SOFTWARE COMES WITHOUT ANY WARRANTY, IMPLIED OR EXPLICIT, TO THE MAXIMUM EXTENT PERMITTABLE BY LAW. THIS INCLUDES
WARRANTY AGAINST DAMAGE TO COMPUTER SYSTEMS OR DATA, LOSS OF PROFIT, PERSONAL INJURY OR DEATH.
This code is in the public domain.
*/
const int button = 2; //push button pin
const int pin5 = A4; //pin 5 of the NXT cable
const int pin6 = A5; //pin 6 of the NXT cable
const int mtrEnA = 5; //motor enable pin A
const int mtrEnB = 3; //motor enable pin B
void setup()
{
pinMode(mtrEnA, OUTPUT);
pinMode(mtrEnB, OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(mtrEnA, HIGH);
digitalWrite(mtrEnB, LOW);
if(digitalRead(button) == 1) //only feedback data when the button is pressed
{
int pin5val = analogRead(pin5);
int pin6val = analogRead(pin6);
Serial.print("pin5 = ");
Serial.println(pin6val);
Serial.print("pin6 = ");
Serial.println( pin6val);
Serial.println("_____________________________");
while(digitalRead(button) == 1) //hold until the button is released
{
true;
}
}
}
I was to later find that the encoder pins needed their own, slightly complex, external circuitry, for which I did not have the components or expertise! On my search to find this out, I stumbled across this nifty Arduino shield. It is a shield with all the external circuitry for two NXT motors plus one sensor, with the correct NXT header female ports. I will be purchasing one in the near future, but it was still enjoyable to try without it!
So, I have the stepper motor working without the ‘stepper’ aspect of it until I get my hands on that Arduino shield. In the next post [I am too tired to continue writing!] I shall be moving on to the sensors, so stay tuned!
Update: Part 2 is now up.
Update: Part 2 is now up.