Friday, February 19, 2010

Arduino and Pololu Motor Controller

Arduino and the Pololu Motor Controller - A tutorial for the beginner.

Let's say you wanna work with robots using the arduino but don't where to start and need some help.

Well you found the right blog to do that.

Here's what you need:
  1. Arduino
  2. Pololu Motor Controller preferably Pololu Low Voltage Dual Serial Motor Controller
  3. Gearbox and Motor- Preferably Tamiya Gearbox which can be obtained from
  4. A bread Board
  5. A Power Supply for the motor controller or a battery pack - Voltage rating between 5-7 volts
  6. Wires to connect everything together.

After you got everything now let's go...

Step 1 Assembly

Assemble the gearbox and solder cables to the motor controller to avoid shorting of the controller. (This stuff is expensive and shorting stuff sucks)
Connect everything together and make sure to tie the ground of the Arduino with the Motor Controller ground to eliminate noise and to complete the circuit. Very Important!

Step 2 Programming the Arduino

Program the Arduino and make sure you do it well. Fortunately, with all of the previous posts submitted, a sample code is always provided for convenience below.

Note: Programming the Pololu motor controller isn't tricky but you have to know what you are doing.

  • First you set the reset pin of motor controller to HIGH so you can talk to it.
  • Then you have to send a command that tells the motor controller you are commanding it (0x80);
  • then a parameter command or instructions of what to do (0x00 = move);
  • then a motor selection command (see code)
  • then the speed for the motors (see code)
If you are using more than one motor controller, then I suggest programming one controller at a time. You also need to refer to the manual for the motor controller configuration. If you need help you can contact me as well on this post.

*** start of program
int resetPin = 7; //need to have a reset pin so you can control motors

void setup()
delay(1000); //delay for 1 second
Serial.begin(9600); //Serial set to 9600 baud
pinMode(resetPin,OUTPUT); //set the reset pin to HIGH to program
delay(1000); //delay for 1 second

//move motor(s)


void loop()
digitalWrite(resetPin,LOW); //reset the motorcontroller
delay(100); //delay for 1 msec
digitalWrite(resetPin,HIGH); //intitiate motorcontroller
delay(1000); //delay 1 second

//Serial.print(0x80,BYTE); //command motorcontroller
//Serial.print(0x00,BYTE); //move parameter

//**motors are configured as motors 2 and 3 by default 2 is right side and 3 is left side
//Serial.print(0x05,BYTE); //right side motor move forward
//Serial.print(0x04,BYTE); //right side motor move backward

//Serial.print(0x07,BYTE); //left side motor move forward
//Serial.print(0x06,BYTE); //left side motor move backward

//Serial.print(0x3F,BYTE); //speed setting command 0x7F = full speed; 0x3F half speed; 0x00 speed off

//both motors in sequence allowing both motors to move
Serial.print(0x80,BYTE); //command motorcontroller
Serial.print(0x00,BYTE); //move parameter
Serial.print(0x05,BYTE); //right side motor move forward
Serial.print(0x3F,BYTE); //speed setting command 0x7F = full speed; 0x3F half speed; 0x00 speed off

Serial.print(0x80,BYTE); //command motorcontroller
Serial.print(0x00,BYTE); //move parameter
Serial.print(0x07,BYTE); //left side motor move forward
Serial.print(0x3F,BYTE); //speed setting command 0x7F = full speed; 0x3F half speed; 0x00 speed off

delay(3000); //let it run for 3 seconds


***end of program

Step 4 Run it

When uploading the program do not attach the motor controller because it will screw up the motor controller.

After uploading the program, attach the motor controller and power supply and watch it go.

Final Result

Here is everything put together

These two photos show the motor controller and its respective LEDs. The LEDs on the photo on the right shows both LEDs lighted meaning both motors are moving). When green it is moving forward, red is moving in reverse. One of the LED will glow if you command for one of the motors to move.

Have fun and post your comments if you are having problems.

Monday, February 15, 2010

Arduino and the thermal printers

I've been browsing through the web and noticed that there isn't much support for thermal printer especially for Epson branded or the ESC POS printer types using Arduino boards. Therefore, I will provide some useful insights on how to get a thermal receipt printer working using ESC POS codes with the Arduino...

Here's what you need:
Step 1
Get hardware

-RS232 level converter (Maxim 232 chip or equivalent and assembled with preferrably an RS232 male connector)
-Epson printer or ESC POS compatible printer (Citizen, etc.)
- cable to connect your printer to the RS232 converter.

To make an RS232 converter all you need is:
- a Maxim232 or alternative equivalent,
- 4 .1uF Capacitors
- a breadboard or pcb board to solder with wire connectors.

Go find datasheets for the converter chip of you choice and follow the pin numbers for connecting the capacitors and for voltage input and ground and viola, you got one.

Step 2
Write some program. Fortunately I have developed a sample program for you.(below) :)

void setup ()
Serial.begin(19200) //Epson default printer settings for baud rate for parallel type printer

void loop() //looping sequence
Serial.print(0x1B,BYTE); //ESC POS command
Serial.print('@'); //ESC POS initialize followed after command
Serial.print("Hola Epson"); //Print "Hola Epson" to buffer
Serial.print(0xA,BYTE); //Print and Line Feed from Buffer

//*** Upload you program

Step 3
Put it all together.

Make or purchase an RS232 level converter. Connect the Arduino 5V and Ground to the RS232 level converter so that it can communicate with the printer. Then pray it all works.

Final Result (Pics)

The Printer here is a parallel printer and I am using a parallel to serial cable to communicate with Arduino directly.