Blog 16
Working with 2 7FETs Stepper motors
Hardware I used on my Raspberry Pi:
- One RPi_UI board | (User Interface)
- Two 7FETs | (7FETs)
- Two Jumper cables M-F
- Two IDC cable 6 pin
- Two 28BYJ-48 Stepper Motor
Programmed in:
- Bash
Talking to the second 7FETs ( stepper motor )
How to find the second 7FETs( on spi1 ). The other 7FETS also of course has 88 as address. ( On the 2 dots there has to be a hexadecimal number. ) But when you also send
bw_tool -s 50000 -a 88 -W 42:..:i
nothing will happen, only the other stepper motor will rotate.
The second spi (spi1) is named spidec0.1.
bw_tool -S -D /dev/spidev0.1
( If you are sending commands on I2C you have to use -I instead of -S (SPI) )
Result:
88: spi_7fets 1.1
To try it out:
bw_tool -S -D /dev/spidev0.1 -a 88 -W 42:0x200:i
This should make the stepper motor rotate 90 degrees.
2 7FETs rotating plateaus
Now I want to show how you can make it possible to let with the previous script let 2 7FETs rotate and stop a special amount of seconds.
#!/bin/bash Address="bw_tool -s 50000 -a 88" Address2="bw_tool -S -D /dev/spidev0.1 -a 88" Rot=-400 Target=`$Address -R 41:i` #Speed=200 #$Address -W 43:$Speed:b` #$Address2 -W 43:$Speed:b` Current="" while true; do $Address -W 42:$Rot:i $Address2 -W 42:$Rot:i Target=`$Address -R 41:i` while [ "$Current" != "$Target" ] ; do sleep 0.2 Current=`$Address -R 40:i` done sleep 10 done
What I did with the code from blog 15 is: I added a second address that leads to the second 7FETs. I made is possible to also change the speed from the second stepper motor. You of course have to make them both as fast as each other otherwise one of them will keep spinning around. I also made it that they both run the command of rotating 90 degrees after the while do loop had ended.
2 7FETs stepper motors controlled by pushbuttons
Now lets control the 2 7FETs with the pushbuttons.
#!/bin/bash Address="bw_tool -s 50000 -a 88" Address2="bw_tool -S -D /dev/spidev0.1 -a 88" AddressI="bw_tool -I -D /dev/i2c-1 -a 94" #SpeedX=0x25 #$Address -W 43:$SpeedX:b #SpeedY=0x25 #$Address2 -W 43:$SpeedY:b $AddressI -W 10:00:b $AddressI -W 11:00:b $AddressI -t "1=1+ 2=1- 3=12+" $AddressI -W 11:20:b $AddressI -t "4=12- 5=2+ 6=2-" Rot=0x200 #Rot2=0x400 #Rot3=0x100 while true; do Button=`$AddressI -R 30:b` if [ $Button = "20" ]; then $Address -W 42:$Rot:i fi if [ $Button = "10" ]; then $Address -W 42:-$Rot:i fi if [ $Button = "08" ]; then $Address -W 42:$Rot:i $Address2 -W 42:$Rot:i fi if [ $Button = "04" ]; then $Address -W 42:-$Rot:i $Address2 -W 42:-$Rot:i fi if [ $Button = "02" ]; then $Address2 -W 42:$Rot:i fi if [ $Button = "01" ]; then $Address2 -W 42:-$Rot:i fi sleep 1 done
The most part of the script is just the same as the one explained at blog 15. The text:
$AddressI -W 11:00:b $AddressI -t "1=1+ 2=1- 3=12+" $AddressI -W 11:20:b $AddressI -t "4=12- 5=2+ 6=2-"
I made to make clear for which button does what. So, button 1 makes it rotate it 0x200 ( 90 degrees ). And button 2 makes it rotate -0x200 ( 90 degrees the other way ). It should be that with -0x200 should be rotating to the right. But if that isn't so you maybe have to change a cable. With 12+ and 12- I want to make clear that both button 1 and 2 are going the same way. ( I didn't know an other short way to do make clear that they are both rotating )
For now I just let the script rotate 90 degrees, but you can of course change the rot names in the command to make another button let the stepper motor rotate an other value)
Rot=0x200 #Rot2=0x400 #Rot3=0x100
Useful links
- Working with the 7FETs BigRelay Board Blog 14
- Working with a 7FETs Stepper motors Blog 15
- Example script for working with arduino from BitWizard: ardemo_lcd.pde