User Tools

Site Tools


steppernxt

This is an old revision of the document!


In many instances in engineering, precise rotary movement is necessary to produce accurate results. The stepper motor, a motor that rotates a certain amount of degree per step; therefore, allow the user to track the total amount rotated. In addition, the rotation speed can be controlled through programming. 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 ability to track the amount of rotation that the stepper motor has made allow for more accurate determination of the state (position, velocity, acceleration) of any mechanism that is attached to the stepper motor. Circuit Schematics The circuit is based on http://www.extremenxt.com/stepper.html 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 to the stepper motor in a correct sequence in order to turn the stepper motor, say in clockwise direction. This means, to drive the stepper motor in the opposite direction, we reverse the sequence. FILE: testingStepper.nxc

#define I2Cport S1 // Port number
#define I2CAddr8574 0x70 // I2C address when PCF8574A A2-A1-A0 are set to 0-0-0
task main() {
 // array variables (since NXC's I2C functions take array variables
 byte WriteBuf[2]; // data written to PCF8574A.  Declares a two one-byte variables
 byte ReadBuf[]; // data received from PCF8574A.  We won't be reading any data but we need this for I2CBytes
 int RdCnt = 1;
 bool rightArrowButtonPushed;
 SetSensorLowspeed (I2Cport); 
 WriteBuf[1] = 0x00; 
 WriteBuf[0] = I2CAddr8574;
 I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
 TextOut (0, LCD_LINE1, "Right Btn starts");
 do {
    rightArrowButtonPushed = ButtonPressed(BTNRIGHT, FALSE);
 } while(!rightArrowButtonPushed);
 ClearScreen();
 TextOut (0, LCD_LINE1, "Looping");
 for (int i=0; i<=300; i++) {
  WriteBuf[1] = 12;  //1100
  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
  Wait(10);
  WriteBuf[1] = 9;  //1001
  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
  Wait(10);
  WriteBuf[1] = 3;   //0011
  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
  Wait(10);
  WriteBuf[1] = 6;   //0110
  I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
  Wait(10); 
 } //end for loop
TextOut(0, LCD_LINE5, "Finished!");
PlaySound(SOUND_DOUBLE_BEEP);
} // end main

Sample Video

Here is the demo of the motor turning with the following schematics and coding.

steppernxt.1501894755.txt.gz · Last modified: 2017/08/04 17:59 by rebeccacao