Example #1
0
def initialise():
    # Setup
    pz.init()
    pz.setOutputConfig(0, 2)  # set output 0 to Servo
    pz.setOutputConfig(1, 1)  # set output 1 to PWM
    pz.setOutputConfig(2, 1)  # set output 2 to PWM
    pz.setOutputConfig(3, 1)  # set output 3 to PWM
    pz.setInputConfig(0, 0)  # set input 1 to digital

    # Setup Action queues
    global qLED
    qLED = Queue(maxsize=0)
    global qServo
    qServo = Queue(maxsize=0)

    workerLED = Thread(target=processq, args=(qLED, ))
    workerLED.setDaemon(True)
    workerLED.start()

    workerServo = Thread(target=processq, args=(qServo, ))
    workerServo.setDaemon(True)
    workerServo.start()

    # Initialise dropbox
    global dbx
    dbx = dropbox.Dropbox(get_dropboxkey())
Example #2
0
#! /usr/bin/env python
#
# Basic test of HC-SR04 ultrasonic sensor on Picon Zero

import hcsr04, time
import piconzero as pz

pz.setInputConfig(2, 0)
pz.setInputConfig(3, 0)
pz.init()
hcsr04.init()

try:
    while True:
        distance = int(hcsr04.getDistance())
        print("Distance : "), distance
        if (((pz.readInput(2) != 1) or (pz.readInput(3) != 1))
                and distance > 13):
            pz.reverse(60)
        else:
            pz.stop()
            time.sleep(0.2)
            pz.spinRight(50)
            time.sleep(0.2)
            pz.stop()
            break
except KeyboardInterrupt:
    print
finally:
    hcsr04.cleanup()
    pz.cleanup()
Example #3
0
from __future__ import absolute_import
import piconzero as pz, time

pz.setInputConfig(0, 1)     # set input 0 to Analog
pz.setOutputConfig(0, 1)    # set output 0 to PWM
pz.setOutputConfig(2, 2)    # set output 2 to Servo
pz.setOutputConfig(5, 3)    # set output 5 to WS2812

while True:
    ana0 = pz.readInput(0)
    pz.setOutput(0, ana0/10)
    pz.setPixel(0,0,0,ana0/4)
    pz.setOutput(2, int(ana0/7))
    time.sleep(0.1)     # this makes 11 active lines, but can be removed

Example #4
0
#! /usr/bin/env python

# GNU GPL V3
# Test code for 4tronix Picon Zero

import piconzero as pz, time

pz.init()
pz.setInputConfig(0, 2)     # set input 0 to DS18B20
pz.setInputConfig(2, 2)     # set input 2 to DS18B20

try:
    while True:
        ana0 = pz.readInput(0)
        if (ana0>32767):
            ana0 -= 65536
        ana2 = pz.readInput(2)
        if (ana2>32767):
            ana2 -= 65536
        print ana0*0.0625, ana2*0.0625
        time.sleep(1)
except KeyboardInterrupt:
    print
finally:
    pz.cleanup()

Example #5
0
#! /usr/bin/env python

# GNU GPL V3
# Test code for 4tronix Picon Zero

from __future__ import absolute_import
from __future__ import print_function
import piconzero as pz, time

pz.init()
pz.setInputConfig(0, 2)  # set input 0 to DS18B20
pz.setInputConfig(2, 2)  # set input 2 to DS18B20

try:
    while True:
        ana0 = pz.readInput(0)
        if (ana0 > 32767):
            ana0 -= 65536
        ana2 = pz.readInput(2)
        if (ana2 > 32767):
            ana2 -= 65536
        print(ana0 * 0.0625, ana2 * 0.0625)
        time.sleep(1)
except KeyboardInterrupt:
    print()
finally:
    pz.cleanup()
Example #6
0
from gpiozero import Button
import sys
from inputs import get_key
import os
import hcsr04
import I2C_LCD_driver
#I2C LCD driver from http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/

#____________________________________________________________________________________
#hardware setup

mylcd = I2C_LCD_driver.lcd()  #assign LCD to variable for ease of use

pz.init()  #initiate hardware

pz.setInputConfig(0, 0)  #right IR sensor is input 0 and digital
pz.setInputConfig(1, 0)  #left IR sensor is input 1 and digital
pz.setInputConfig(2, 0)  #right line sensor is input 2 and digital
pz.setInputConfig(3, 0)  #left line is input 3 and digital

RIGHTIR = pz.readInput(0)  #assign right IR to a variable
LEFTIR = pz.readInput(1)  #assign left IR to a variable
RIGHTLINE = pz.readInput(2)  #assign right line sensor to a variable
LEFTLINE = pz.readInput(3)  #assign left line sensor to a variable

hcsr04.init()  #initiate hardware
RANGE = hcsr04.getDistance()  #assign HC-SR04 range to variable

button = Button(22)

#end of hardware setup
Example #7
0
#! /usr/bin/env python

# GNU GPL V3
# Test code for 4tronix Picon Zero

from __future__ import absolute_import
from __future__ import print_function
import piconzero as pz, time

pz.init()

pz.setInputConfig(0, 0, True)  # request pullup on input

vsn = pz.getRevision()
if (vsn[1] == 2):
    print("Board Type:", "Picon Zero")
else:
    print("Board Type:", vsn[1])
print("Firmware version:", vsn[0])
print()

try:
    while True:
        switch = pz.readInput(0)
        if (switch == 0):
            print("Switch Pressed", switch)
        else:
            print("Switch Released", switch)
        time.sleep(5)
except KeyboardInterrupt:
    print()
Example #8
0
from triangula.input import SixAxis, SixAxisResource
import time
import smbus
import os
import hcsr04
import piconzero as pz
from gpiozero import Button
import I2C_LCD_driver

#__________________________________________________________________
#initiate piconzero and display

pz.init() #initiate hardware
mylcd = I2C_LCD_driver.lcd() #assign LCD to variable for ease of use

pz.setInputConfig(0,0) #developer switch is input 0 and digital
pz.setInputConfig(1,0) #right IR sensor is input 1 and digital
pz.setInputConfig(2,0) #left IR sensor is input 2 and digital
pz.setInputConfig(3,0) #right line sensor is input 3 and digital
pz.setInputConfig(4,0) #left line is input 4 and digital

DEVELOPER = Button(22) #assign developer switch to variable
DEVELOPER = 0
RIGHTIR = pz.readInput(0) #assign right IR to a variable
LEFTIR = pz.readInput(1) #assign left IR to a variable
RIGHTLINE = pz.readInput(2) #assign right line sensor to a variable
LEFTLINE = pz.readInput(3) #assign left line sensor to a variable

hcsr04.init() #initiate hardware
RANGE = hcsr04.getDistance() #assign HC-SR04 range to variable
Example #9
0
rightState=0

# running total of change of state
leftTotal=0
rightTotal=0

# init all hardware

pz.init()

# Set output mode to Servo
pz.setOutputConfig(pan, 2)
pz.setOutputConfig(tilt, 2)
pz.setOutputConfig(cam, 2)

pz.setInputConfig(irSen, 1)     # set input 0 to Analog

pz.setInputConfig(leftCounter, 0)     # set input 0 to Analog
pz.setInputConfig(rightCounter, 0)     # set input 0 to Analog

# Centre positions for all servos
panVal = 90
tiltVal = 90
camVal = 90

pz.setOutput (pan, panVal)
pz.setOutput (tilt, tiltVal)
pz.setOutput (cam, camVal)

# position for 'head down' while moving forward for collis detection
fwdPan=90
Example #10
0
#! /usr/bin/env python

# Sound controlled McRoboFace by Robin Newman June 4th 2016
# requires picon zero hardware plus software library
# see circuitry in article at rbnrpi.wordpress.com
#version 1.2
import piconzero as pz, time

#setup piconzero card
pz.init()
pz.setInputConfig(
    1, 0, True
)  # used for push button digital input (normally high using internal resistor)
pz.setOutputConfig(5, 3)  # set output 5 to WS2812
pz.setInputConfig(0, 1)  # set to Analogue used to sample audio

#initialise variables used by the program
v = 0  #adc value
offset = 0  #rest adc value read when button pushed
opencount = 0  #count cycles between shutting and next opening of mouth
shutcount = 0  #count cycles between opening and next shutting of mouth
openFlag = 0  #0 closed, 1 open
b = 0  #current brightness
threshold = 65  #trigger brightness level to open mouth
blast = 0  #last brightness
openslot = 8  #number of cycles for which mouth remains open (initial value)
shutslot = 2  #number of cycles for which mouth remains closed (I have had this higher at 4: experiment with it!)


#define function to open or close mouth
def change(t):  #parameter = 1 to open mouth anything else to close it
Example #11
0
servoPort0 = 0
#ch1
servoPort1 = 1
#ch2
servoPort2 = 2

#define input ports
analogPort0 = 0  #input port 0
analogPort1 = 1  #input port 1

# Set output mode
pz.setOutputConfig(servoPort0, 2)  #set to output Servo (0 - 180)
#pz.setOutputConfig(servoPort0, 1)    # set output 0 to PWM (100)

# Set input mode
pz.setInputConfig(analogPort0, 1)  # set input 0 to Analog


def motor(servoPort, speed):  #activate servo hat servo motor
    pz.setOutput(servoPort, speed)


class Encoder(threading.Thread):
    'Class for Analog encoder on continous rotation servo motors'

    def __init__(self, servo_port, analog_port, threshold):
        threading.Thread.__init__(self)
        self.q = queue.Queue()  #q, command queue
        self.event = threading.Event()
        self.encoderLoop = True
        self.servo_port = servo_port
Example #12
0
 def setup():
     print("Init line sensor")
     # read from config file
     LineSensor.channel = int(IniReader.read('pins', 'LINE_SENSOR_CHANNEL'))
     pz.setInputConfig(LineSensor.channel, 0)  # set DIGITAL
     print("Line sensor initialised")
Example #13
0
import piconzero as pz, time

pz.setInputConfig(0, 1)     # set input 0 to Analog
pz.setOutputConfig(0, 1)    # set output 0 to PWM
pz.setOutputConfig(2, 2)    # set output 2 to Servo
pz.setOutputConfig(5, 3)    # set output 5 to WS2812

while True:
    ana0 = pz.readInput(0)
    pz.setOutput(0, ana0/10)
    pz.setPixel(0,0,0,ana0/4)
    pz.setOutput(2, int(ana0/7))
    time.sleep(0.1)     # this makes 11 active lines, but can be removed

Example #14
0
#! /usr/bin/env python

# GNU GPL V3
# Test code for 4tronix Picon Zero

import piconzero as pz, time

pz.init()

pz.setInputConfig(0, 0, True)   # request pullup on input

vsn = pz.getRevision()
if (vsn[1] == 2):
    print "Board Type:", "Picon Zero"
else:
    print "Board Type:", vsn[1]
print "Firmware version:", vsn[0]
print

try:
    while True:
        switch = pz.readInput(0)
        if (switch == 0):
            print "Switch Pressed", switch
        else:
            print "Switch Released", switch
        time.sleep(5)
except KeyboardInterrupt:
    print
finally:
    pz.cleanup()