Level: Beginner
Hours to Complete: 2.5
Skills Required: Soldering, C Programming, Breadboarding, Familiarity with Xbee Modules
Submitted By: Miguel Rodriguez, Parallax Tech Support
This project introduces the topic of motor control with the help of two H-bridges onboard the Pololu MC33926 motor driver carrier board. You will be controlling them wirelessly through the aid of an XBee module. This application can be used in controlling two-wheeled robots, motorized pulley systems and automatic door control. For the purposes of this demonstration I use a two wheeled robot as my platform of choice, however this set up can be adapted to any application the requires motor control.
Before You Start:
Download the Code files and Schematic Images [1]
The first step is to solder a row of pins onto the motor driver board. The Pololu MC33926 board comes with 25 breakaway male header pins. Breakaway 18 pins from the header and insert them into the pin slots on the driver board and solder them on. You can solder the remaining pins onto the board; however, they are optional for this application. (Make sure you wear your safety goggles.) Now solder the 3 terminal blocks on the opposite side of the board. The terminal block's opening should be facing away from the board. (See image below.)
Now it's time to build the joystick circuit on one of your Activity Boards. Click here to view the wiring diagram from the Propeller C Joystick tutorial [2] and use it to build your "Joystick" circuit. To attach the XBee modules simply align their pins with the Activity Board 's socket located over the SD card slot. The two angled edges of the XBee should be facing away from the Activity Board. (See image below.)
After attaching the XBees you will need to connect two jumper wires. One jumper connects the DO pin (Data Out) to pin 9 and the second jumper connects DI (Data In) to pin 8. Make sure that both Activity Boards have XBees installed, and jumpers connected to DO and DI as shown in the following image.
The next step is to connect the motor driver board to your second Activity Board. In this step it is wise to go slow since it's easy to make a wiring mistake when making this many connections. Always make sure your board is disconnected from its power source before connecting any wiring. Use the legend below and schematic images included in the code download (at the top of the page) to guide you on each connection.
For these connections, use the AB-Pololu-Schematic-05.jpg file in the code download zip.
Take one DC motor and connect M1OUT1 to its red input and M1OUT2 to its black input. Now take the second motor and connect M2OUT1 to its red input and M2OUT2 to the its black input.
Now we're ready to load each board with its corresponding code:
If your motors are spinning in the wrong direction:
Here's how it all works!
Lets start with the Activity Board featuring the joystick. The joystick module houses two potentiometers, one for each axis of motion. When you move the joystick in different directions you're actually changing the the resistance of each potentiometer. When a voltage is placed at the modules input the output voltage will fluctuated anywhere from 0 V to 5 V depending on the position of the joystick/potentiometer. Each axis has its own output that feeds into the Activity Board's analog-to-digital converter (ADC) through pins A2 and A3. This is where the data is digitalized or converter to 1's and 0's.
The Propeller on the second board outputs a PWM signal through P3 and P4, and these two pins are used to control the "forward" motion of the motors – including turning. Pins P2 and P5 are used to control the "reverse" motion of the same two motors. Each pin is associated with each motors direction. For example P3 drives the right motor in a forward direction and P4 drives the left motor in the forward direction. The same goes for P2 and P5 only they drive the right and left motors in reverse. Another way to look at it is P3 drives the right motor forward, P4 drives the left motor forward, P2 drives the right motor in reverse, and P5 drives the left motor in reverse.
Remember when you inserted the jumpers from P9 to DO and P8 to DI? This is where they become really important. The jumpers connect the Propeller's pins to the XBee module, and once the analog data from the joystick is converted to 1's and 0's it is relayed to the XBee module by the Propeller IC chip using the jumpers on P9 and P8. At this point, the XBee module receives the data and wirelessly transmits it to the second XBee module.
The Pololu board has two MC33926 H-bridges built onto its PCB. Each H-bridge controls the forward and backward motion of each motor. In order for a motor to go forward, two MOSFETs on opposite ends must be "turned on" creating a very specific path for current to pass. Current must output from one of the H-bridge's MOSFETs and pass through the motor and into a second MOSFET that leads to ground.(See Hbridge_schematic-06.PNG schematic). When current passes through the motor in one direction, it spins the motor accordingly. When the opposite MOSFETs are "turned on" as show in the schematic, they allow current to pass in the opposite direction which leads to spinning the motor in the opposite direction. The MC33926 IC chip has a logic controller inside that helps determine the speed at which the motors spin, giving the PWM duty cycle.
To learn more on the topics discussed in this project, search: H-bridges, PWM, DC Motors, and XBee modules.
Links
[1] https://learn.parallax.com/sites/default/files/Files/Docs/Projects/DC-Motor-Control/DC-Motor-Control-Code.zip
[2] http://learn.parallax.com/propeller-c-simple-devices/joystick