Controlling a Motor Driver using the WiPy

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
craighissett
Posts: 8
Joined: Tue Jul 21, 2015 1:12 pm

Controlling a Motor Driver using the WiPy

Post by craighissett » Wed Jul 22, 2015 4:44 pm

Hello everyone!

So, I'm over my power issues :-) and now I want to get started with writing a script to run on the WiPy!
Here's my plan so far:
I would like to put the WiPy in a project to control a L298N motor driver board; the board requires 4 pins to run, two for each motor.
Any GPIO pins will do - it is a case of turning one pin HIGH and one LOW to to turn a motor; reverse the pins to reverse the direction.
In an ideal world one pin from each pair would be capable of PWM to allow speed control. The WiPy has the option of PWM on GPIOs 9, 10, 11 and 24.
In addition to setting up the defs to enable Forward, Backward, Left, Right and Stop motion I would also like to be able to pass commands to the WiPy to trigger these movements. At first using a Telnet session would be fine, but eventually I would love to incorporate the Blynk library that danicampora is currently working on.
I have started on the code using them examples on this site; it should define the motors pins and set up the wifi soon, ha ha.
Does anyone have any tips on how to make this code run?

Code: Select all

from pyb import Timer
from pyb import Pin
from network import WLAN
from pyb import Sleep

def Setup_Pins()
# initialize GPIO7 and GPIO 8 in gpio mode (af=0) and make output
# These will be the standard pins required for motor control
LMotorB = Pin('GPIO7', af=0, mode=Pin.OUT)
RMotorB = Pin('GPIO8', af=0, mode=Pin.OUT)
LMotorB.low()
RMotorB.low()

# assign GPIO9 and 10 to alternate function 3 (PWM)
# These will be the pins to control speed
LMotorA = Pin('GPIO9', af=3, type=Pin.STD)
RMotorA = Pin('GPIO10', af=3, type=Pin.STD)

# Enable timer channels 3B and 4A for PWM pins
LMTimer = Timer(3, mode=Timer.PWM, width=16)
RMTimer = Timer(4, mode=Timer.PWM, width=16)
# enable channel A @1KHz with a 50% duty cycle
LMT_a = LMTimer.channel(Timer.B, freq=1000, duty_cycle=50)
RMT_a = RMTimer.channel(Timer.A, freq=1000, duty_cycle=50)

def Setup_WIFI()
wifi = WLAN(WLAN.STA)
# go for fixed IP settings
wifi.ifconfig('192.168.0.107', '255.255.255.0', '192.168.0.1', '8.8.8.8')
wifi.scan()     # scan for available netrworks
wifi.connect(ssid='mynetwork', security=2, key='mynetworkkey')
while not wifi.isconnected():
    pass
print(wifi.ifconfig())
# enable wake on WLAN
wifi.callback(wakes=Sleep.SUSPENDED)
# go to sleep
Sleep.suspend()
# now, connect to the FTP or the Telnet server and the WiPy will wake-up
Thanks people!

Craig

photoacoustic
Posts: 24
Joined: Mon Apr 27, 2015 8:25 am

Re: Controlling a Motor Driver using the WiPy

Post by photoacoustic » Fri Jul 24, 2015 6:00 pm

You are very lucky!
I'm waiting my wipy!
So your post are very important.
Please post tutorial and more
best regards

craighissett
Posts: 8
Joined: Tue Jul 21, 2015 1:12 pm

Re: Controlling a Motor Driver using the WiPy

Post by craighissett » Sat Jul 25, 2015 10:49 pm

photoacoustic wrote:You are very lucky!
I'm waiting my wipy!
So your post are very important.
Please post tutorial and more
best regards
Ah, trust me - they are worth the wait!
I have used Python to create a few windows-based programs and functions, plus i also enjoy creating Arduino-based projects. This is the first device I have tried to combine both with, ha ha.
It is great to play with; if you have any issues with it just check the documentation as the guys will have already covered it, or drop a post in the forums as everyone is happy to help!

I am documenting my experiences with the WiPy for a review on the Lets Make Robots site - feel free to check it out!

http://letsmakerobots.com/user/22363/pages

photoacoustic
Posts: 24
Joined: Mon Apr 27, 2015 8:25 am

Re: Controlling a Motor Driver using the WiPy

Post by photoacoustic » Fri Jul 31, 2015 9:51 am

Thanks.
I have bookmarked the link!

Post Reply