PDALib.py - Pi Droid Alpha Python Library Discussion

Moderator: Steve

PDALib.py - Pi Droid Alpha Python Library Discussion

Postby alanmcdonley » Tue Aug 25, 2015 9:33 am

Copied from http://forums.mikronauts.com/viewtopic.php?p=155#p155 to start a new thread title.

mikronauts wrote:I've uploaded PDALib.py v0.90 to the Pi Droid Alpha product page :)

http://www.mikronauts.com/raspberry-pi/pi-droid-alpha/

After downloading, rename file as PDALib.py
alanmcdonley
 
Posts: 91
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

PDALib.py - Using Motor 1 and Motor 2

Postby alanmcdonley » Tue Aug 25, 2015 10:12 am

Topic: Driving motor 1 and motor 2 (basic)

Is this correct? (edited: pinMode() was improperly setMode() )

Code: Select all
import PDALib
import time

PDALib.pinMode(6,PDALib.PWM)  # init motor1 speed control pin
PDALib.pinMode(7,PDALib.PWM)  # init motor2 speed control pin

PDALib.pinMode(12,PDALib.OUTPUT)  #init motor1 dirA/Fwd    enable
PDALib.pinMode(13,PDALib.OUTPUT)  #init motor1 dirB/Bkwd  enable
PDALib.pinMode(14,PDALib.OUTPUT)  #init motor2 dirA/Fwd    enable
PDALib.pinMode(15,PDALib.OUTPUT)  #init motor2 dirB/Bkwd  enable

# init all direction pins to off
PDALib.digitalWrite(12,0)  #set to off/coast
PDALib.digitalWrite(13,0)  #set to off/coast
PDALib.digitalWrite(14,0)  #set to off/coast
PDALib.digitalWrite(15,0)  #set to off/coast

# get ready to go forward
PDALib.digitalWrite(12,1)  #set to forward
PDALib.digitalWrite(14,1)  #set to forward

# setting speed will start us going  (zero to fast in one command for this test)
PDALib.analogWrite(6,127)  #set motor1 to half speed
PDALib.analogWrite(7,127)  #set motor2 to half speed

time.sleep(10.0)  # drive while asleep at the wheel for 10 seconds
                           # (bad idea but this is a test)

# two ways to stop - set speed to 0 or set direction to off/coast
PDALib.digitalWrite(12,0)  #set to off/coast to stop
PDALib.digitalWrite(14,0)  #set to off/coast to stop

# turn off the speed pin - not needed when dir pins are off, but good idea
PDALib.analogWrite(6,0)  #set motor1 to zero speed
PDALib.analogWrite(7,0)  #set motor2 to zero speed

Last edited by alanmcdonley on Tue Aug 25, 2015 3:38 pm, edited 1 time in total.
alanmcdonley
 
Posts: 91
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: PDALib.py - Pi Droid Alpha Python Library Discussion

Postby mikronauts » Tue Aug 25, 2015 10:40 am

Yes - that looks correct.

Generally, I set he direction separately, then just use analogWrite() to control the speed - and break by analogWrite(0), as it requires less code :)

FYI, I expect to release the initial manual in a few days.
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm

Set all pins as inputs?

Postby alanmcdonley » Sun Aug 30, 2015 7:11 am

In PDALib.py there is a line:

spi.xfer([0x40,0xff,0xff]) # sets all pins as inputs

should this be?

spi.xfer([0x40,DIO_DIR,0xff,0xff]) # sets all pins as inputs

# 0x40 = write opcode with hardware address zero (0100AAAW W=0 for write)
# DIO_DIR = 0 = IODIRA register
# 0xff = IODIRA value - 1= input, 0xFF =all input direction
# 0xff = IODIRB value (auto register address incrementing on by default)
alanmcdonley
 
Posts: 91
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: PDALib.py - Pi Droid Alpha Python Library Discussion

Postby mikronauts » Mon Aug 31, 2015 7:09 pm

You are correct!

Thank you for the help in debugging the library.

I got my internet back a couple of hours ago!!!
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm


Return to Pi Droid Alpha

Who is online

Users browsing this forum: No registered users and 1 guest

cron