Python controlling motors
Posted: Tue Nov 13, 2012 7:32 pm
Hi, I have question about Python. I´m building my first robot and I tried to write program in Bash and it looks like this
and it is working quite good. But i wanted to try software pwm so i tried to write python program like this
I tried to call this python script from the bash script when i press w. and it is working. But i wanted to press w and drive forward until i press s and and the same with every key.
Could anyone help me please?
Thank you for any answer and sorry for my bad english.
Code: Select all
#!/bin/bash
gpio mode 1 out
gpio mode 2 out
gpio write 1 0
gpio write 2 0
while true
do
read -n 1 -s x
case $x in
[w]*)
gpio write 1 1
gpio write 2 1
echo "forward"
;;
[s]*)
gpio write 1 0
gpio write 2 0
echo "stop"
;;
[a]*)
gpio write 1 0
gpio write 2 1
echo "right"
;;
[d]*)
gpio write 1 1
gpio write 2 0
echo "left"
;;
esac
echo "You have pressed $key"
done
Code: Select all
import RPi.GPIO as GPIO
import time
import signal
import Tkinter as tk
from pizypwm import *
first_f = PiZyPwm(0.01, 100, 12, GPIO.BOARD)
second_f = PiZyPwm(0.01, 100, 13, GPIO.BOARD)
first_f.start(50)
second_f.start(50)
time.sleep(1)
first_f.stop()
second_f.stop()
Could anyone help me please?
Thank you for any answer and sorry for my bad english.