Author: Xinke (Rebecca) Cao
Date: Last modified on 08/04/2017
Keywords: unipolar stepper motor, LEGO NXT, transistors, IRF510
This is a continuation of the first option, but this tutorial is specifically for the audiences who doesn't have the access to ULN2003A Darlington transistor array.
In this tutorial, the focus will be on using the IRF510 N-channel MOSFET to control the stepper motor, where the IRF510 acts as a switch to sending the signal into the stepper motor for the motor to turn.
Insert a PCF8574A.
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, which will also be the ground to the NXT Brick.
Insert four IRF510 resistors.
Gather an NXT adaptor.
Insert the NXT adaptor.
Gather four 100k Ohms resistors.
Connect the resistors to the “Gate” pins of all of the transistors.
Connect the source of all transistors to the ground.
Insert data lines from the correct output pins from the PCF8574A to the corresponding transistor's “drain” pin.
Connect the center line (red) of the stepper motor to a 9V source and the other four lines to the corresponding “drain” pin of the transistors.
Connect the battery.
First, I defined where the input port and the address for the PCF8574 will be.
#define I2Cport S1 // Port number #define I2CAddr8574 0x70 // I2C address
Then, in the main task, the variables for the function I2CBytes() will be initialized.
byte WriteBuf; byte ReadBuf; int RdCnt = 1;
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); // PCF8574A connect to NXT on S1 WriteBuf = 0x00; // i.e. write zeros to port sets up PCF8574A for writing WriteBuf = I2CAddr8574; // i.e. address is 0x70 I2CBytes(S1, WriteBuf, RdCnt, ReadBuf);
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.
The sequence that the PCF8574A will be sending to allow the transistors to open or close is as follows:
WriteBuf = 192; //1100 0000 I2CBytes(S1, WriteBuf, RdCnt, ReadBuf); Wait(10); WriteBuf = 130; //1000 0010 I2CBytes(S1, WriteBuf, RdCnt, ReadBuf); Wait(10); WriteBuf = 3; //0000 0011 I2CBytes(S1, WriteBuf, RdCnt, ReadBuf); Wait(10); WriteBuf = 65; //0100 0001 I2CBytes(S1, WriteBuf, RdCnt, ReadBuf); Wait(10);
Comparing version one and version two of the stepper motor control, the only difference is the circuit diagram, which resulted in different numbers sent out of the PCF8574A from the LEGO Brick.
If you have any questions, please contact me at email@example.com.