steppernxt
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
steppernxt [2017/08/04 17:59] – rebeccacao | steppernxt [2017/08/15 19:29] – [Parts List and Sources] rebeccacao | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== How To Control an Unipolar Stepper Motor with LEGO NXT Using ULN2003A ====== | ||
+ | |||
+ | **Author:** Xinke (Rebecca) Cao | ||
+ | \\ | ||
+ | **Email:** [email protected] | ||
+ | \\ | ||
+ | **Date:** Last modified on 08/04/2017 | ||
+ | \\ | ||
+ | **Keywords: | ||
+ | \\ | ||
+ | |||
+ | ===== Motivation and Audience ===== | ||
In many instances in engineering, | In many instances in engineering, | ||
- | // | + | \\ |
The stepper motors resembles the dynamixels used in Darwin-OP; therefore, learning to operate the stepper motors allows more possibilities on the types of mechanisms can be built that can be controlled by the LEGO NXT Brick. Furthermore, | The stepper motors resembles the dynamixels used in Darwin-OP; therefore, learning to operate the stepper motors allows more possibilities on the types of mechanisms can be built that can be controlled by the LEGO NXT Brick. Furthermore, | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | ==== Parts List and Sources ==== | ||
+ | * (1) 9V battery | ||
+ | * (1) 9V battery snaps | ||
+ | * (1) 28BYJ-48 5V unipolar stepper motor | ||
+ | * (1) ULN2003A | ||
+ | * (4) 3.3k Ohms resistors | ||
+ | * (1) PCF8574A | ||
+ | * (1) NXT to breadboard adaptor | ||
+ | * (1) NXT Brick | ||
+ | * (various quantities) gauge wires | ||
+ | Here is the [[https:// | ||
+ | \\ | ||
+ | All the codes can be found [[https:// | ||
- | + | \\ | |
- | + | \\ | |
- | + | \\ | |
- | **Circuit Schematics** | + | ==== Circuit Schematics |
// | // | ||
- | The circuit is based on http:// | + | The circuit is based on [[http:// |
// | // | ||
+ | Below is a picture of the circuit schematics. | ||
- | **Basic: Coding** | + | {{ : |
- | To simplify what I'm doing, I will put it in layman terms. Basically, in order to drive the unipolar stepper motor that we have, we send currents | + | D0 controls blue. |
- | // FILE: testingStepper.nxc | + | \\ |
+ | D1 controls pink. | ||
+ | \\ | ||
+ | D2 controls yellow. | ||
+ | \\ | ||
+ | D3 controls orange. | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | ==== Construction ==== | ||
+ | **Step 1** | ||
+ | \\ | ||
+ | \\ | ||
+ | Insert a PCF8574A. | ||
+ | \\ | ||
+ | {{:xinke: | ||
+ | \\ | ||
+ | \\ | ||
+ | Insert the clock line from PCF8574A to the NXT adaptor. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | Insert the data line. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | Insert the voltage source to the PCF8574A. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | Insert the ground lines to the NXT Brick. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | Ground the pins on PCF8574A. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | **Step 2** | ||
+ | \\ | ||
+ | \\ | ||
+ | Insert a ULN2003A. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | Add the ground to the ULN2003A and the 9V source to the ULN2003A. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | Add the data lines from the PCF8574A to the ULN2003A's input ports. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | Add resistors | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | **Step 3** | ||
+ | \\ | ||
+ | \\ | ||
+ | Insert the NXT adaptor. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | **Step 4** | ||
+ | \\ | ||
+ | \\ | ||
+ | Insert | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | Connect the red wire from the stepper motor to a 9V voltage source. | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | **Step 6** | ||
+ | \\ | ||
+ | Connect | ||
+ | \\ | ||
+ | {{:xinke: | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | ==== Programming ==== | ||
+ | First, I defined where the input port and the address for the PCF8574 will be. | ||
#define I2Cport S1 // Port number | #define I2Cport S1 // Port number | ||
- | #define I2CAddr8574 0x70 // I2C address | + | #define I2CAddr8574 0x70 // I2C address |
- | task main() { | + | |
- | // array variables (since NXC's I2C functions take array variables | + | Then, in the main task, the variables for the function I2CBytes() will be initialized. |
- | byte WriteBuf[2]; | + | byte WriteBuf[2]; |
- | byte ReadBuf[]; | + | byte ReadBuf[]; |
- | int RdCnt = 1; | + | int RdCnt = 1; |
- | bool rightArrowButtonPushed; | + | Next, since the PCF8574A is connected to the NXT on input port S1; therefore, PCF8574A will be initialized and set up for writing to the PCF8574. |
- | | + | SetSensorLowspeed (I2Cport); |
- | | + | WriteBuf[1] = 0x00; // i.e. write zeros to port sets up PCF8574A for writing |
- | | + | WriteBuf[0] = I2CAddr8574; |
- | | + | I2CBytes(S1, |
- | TextOut (0, LCD_LINE1, "Right Btn starts" | + | |
- | do { | + | To allow the motor to turn, a sequence of data has to be send to the motor in order for the motor to turn in a certain direction. In this case, the motor will be turning in clockwise direction. |
- | | + | \\ |
- | } while(!rightArrowButtonPushed); | + | The sequence that the PCF8574A will be sending to allow the transistors to open or close is as follows: |
- | | + | |
- | | + | |
- | for (int i=0; i<=300; i++) { | + | |
WriteBuf[1] = 12; //1100 | WriteBuf[1] = 12; //1100 | ||
I2CBytes(S1, | I2CBytes(S1, | ||
Line 45: | Line 188: | ||
I2CBytes(S1, | I2CBytes(S1, | ||
Wait(10); | Wait(10); | ||
- | } //end for loop | ||
- | TextOut(0, LCD_LINE5, " | ||
- | PlaySound(SOUND_DOUBLE_BEEP); | ||
- | } // end main | ||
- | // | + | \\ |
+ | To reverse the direction that the stepper motor is turning, the sequence can be reversed. | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | ==== Final Words ==== | ||
+ | The purpose of this tutorial is to allow the users of the NXT Brick learn how to control a stepper motor through an NXT interface. | ||
+ | \\ | ||
+ | Building from this tutorial, one can control the speed of the stepper motor and the direction of the stepper motor by altering the wait time between each signal and the sequence of the signal. | ||
+ | \\ | ||
+ | If you have any questions, please email me at [email protected]. | ||
+ | |||
+ | |||
+ | |||
+ | |||
- | **Sample Video** | ||
- | // | ||
- | // | ||
- | Here is the [[https:// | ||
steppernxt.txt · Last modified: 2017/08/15 20:11 by rebeccacao