the other gpio pins

I have two picoborg reverse connected with the pi ( and working !)
What can i do with the others pins on the pi board:
Example 1
I want a led on pin 7 setting high when a motor is working and when the motor is off, the pin is low. Is that possible ? Or is there an other solution

piborg's picture

You can write some Python code to do that, there would be two ways to do this.

Method 1

Make your own functions which set the GPIO pin and the motor.
For example:

# Import library functions we need
import PicoBorgRev
import time
import wiringpi2 as wiringpi
wiringpi.wiringPiSetup()

# Setup the PicoBorg Reverse
PBR = PicoBorgRev.PicoBorgRev()
PBR.Init()
PBR.ResetEpo()

# Setup the GPIO pins
PIN_MOTOR1 = 6
PIN_MOTOR2 = 7
wiringpi.pinMode(PIN_MOTOR1, wiringpi.GPIO.OUTPUT)
wiringpi.pinMode(PIN_MOTOR2, wiringpi.GPIO.OUTPUT)
wiringpi.digitalWrite(PIN_MOTOR1, 0)
wiringpi.digitalWrite(PIN_MOTOR2, 0)

# Make some functions for the
def SetMotor1(power):
    PBR.SetMotor1(power)
    if power == 0:
        wiringpi.digitalWrite(PIN_MOTOR1, 1)
    else:
        wiringpi.digitalWrite(PIN_MOTOR1, 0)

def SetMotor2(power):
    PBR.SetMotor2(power)
    if power == 0:
        wiringpi.digitalWrite(PIN_MOTOR2, 1)
    else:
        wiringpi.digitalWrite(PIN_MOTOR2, 0)

def MotorsOff():
    PBR.MotorsOff()
    wiringpi.digitalWrite(PIN_MOTOR1, 0)
    wiringpi.digitalWrite(PIN_MOTOR2, 0)

# Use like this
SetMotor1(0.5)
time.sleep(1.0)
SetMotor2(0.5)
time.sleep(1.0)
MotorsOff()

Method 2

Make a script which looks at the motor speeds and sets the GPIO pins as needed
For example:

# Import library functions we need
import PicoBorgRev
import time
import wiringpi2 as wiringpi
wiringpi.wiringPiSetup()

# Setup the PicoBorg Reverse
PBR = PicoBorgRev.PicoBorgRev()
PBR.Init()
PBR.ResetEpo()

# Setup the GPIO pins
PIN_MOTOR1 = 6
PIN_MOTOR2 = 7
wiringpi.pinMode(PIN_MOTOR1, wiringpi.GPIO.OUTPUT)
wiringpi.pinMode(PIN_MOTOR2, wiringpi.GPIO.OUTPUT)
wiringpi.digitalWrite(PIN_MOTOR1, 0)
wiringpi.digitalWrite(PIN_MOTOR2, 0)

# Read the motor statuses and set the GPIO pins
while True:
    if PBR.GetMotor1() == 0:
        wiringpi.digitalWrite(PIN_MOTOR1, 0)
    else:
        wiringpi.digitalWrite(PIN_MOTOR1, 1)
    if PBR.GetMotor2() == 0:
        wiringpi.digitalWrite(PIN_MOTOR2, 0)
    else:
        wiringpi.digitalWrite(PIN_MOTOR2, 1)
    time.sleep(0.5)
Subscribe to Comments for "the other gpio pins"