Exemplo n.º 1
0
    def __init__(self, gpio=None):

        # If no gpio is given, create resource now
        if gpio == None:
            gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)

        # Create resource to control HD44780 16x2 LCD
        self.lcd = HD44780_595()

        # Create resources to control leds
        self.sLed = Led(3, 0, gpio)
        self.mLed = Led(0, 0, gpio)

        # Disply Helper
        self.helper = DisplayHelper()

        # Volume
        self.vol = VolumeDisplay()

        # Tone
        self.tone = ToneDisplay()

        # Mp3
        self.mp3 = Mp3Display()

        # Radio
        self.radio = RadioDisplay()

        # Selected Input
        self.selectedInput = True  # media = True, mp3 = False
Exemplo n.º 2
0
 def __init__(self, pin):
     self.pin = pin
     self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
     self.gpio.pinMode(self.pin, self.gpio.OUTPUT)
     self.maxCycles = 100
     self.repeats = 2
     self.threshold = 40
Exemplo n.º 3
0
    def __init__(self):
        if gaugette.platform.isRaspberryPi:
            import wiringpi
            self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
            self.setup = self.wiringpi_setup
            self.output = self.gpio.digitalWrite
            self.input = self.gpio.digitalRead
            self.OUT = self.gpio.OUTPUT
            self.IN = self.gpio.INPUT
            self.HIGH = self.gpio.HIGH
            self.LOW = self.gpio.LOW
            self.PUD_UP = self.gpio.PUD_UP
            self.PUD_DOWN = self.gpio.PUD_DOWN
            self.PUD_OFF = self.gpio.PUD_OFF
            
        elif gaugette.platform.isBeagleBoneBlack:
            import Adafruit_BBIO.GPIO
            self.gpio = Adafruit_BBIO.GPIO
            self.setup = self.gpio.setup
            self.output = self.gpio.output
            self.input = self.gpio.input
            self.OUT = self.gpio.OUT
            self.IN  = self.gpio.IN
            self.HIGH = self.gpio.HIGH
            self.LOW = self.gpio.LOW
            self.PUD_UP = self.gpio.PUD_UP
            self.PUD_DOWN = self.gpio.PUD_DOWN
            self.PUD_OFF = self.gpio.PUD_OFF

        else:
            raise NotImplementedError("Platform is not supported.")
Exemplo n.º 4
0
    def __init__(self, pins, callback=None):
        a_pin = pins[0]
        b_pin = pins[1]
        self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        self.a_pin = wiringport[a_pin]
        self.b_pin = wiringport[b_pin]
        self.wiringpi_setup(self.a_pin, self.gpio.INPUT, self.gpio.PUD_UP)
        self.wiringpi_setup(self.b_pin, self.gpio.INPUT, self.gpio.PUD_UP)

        self.steps = 0
        self.last_delta = 0
        self.r_seq = self.rotation_sequence()
        self.speed = 0

        # Callback function gets called when a rotation is detected
        # Function format should be:
        # FuncName(x) where x is 1 or -1 depending on the detected rotation
        # direction
        self.callback = callback

        # steps_per_cycle and self.remainder are only used in get_cycles which
        # returns a coarse-granularity step count.  By default
        # steps_per_cycle is 4 as there are 4 steps per
        # detent on my encoder, and get_cycles() will return a signed
        # count of full detent steps.
        self.steps_per_cycle = 4
        self.remainder = 0
Exemplo n.º 5
0
 def __init__(self, bus=0, device=0, reset_pin=None, buffer_rows=64, buffer_cols=128):
     self.reset_pin = reset_pin
     if self.reset_pin is not None:
         self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
         self.gpio.pinMode(self.reset_pin, self.gpio.OUTPUT)
         self.gpio.digitalWrite(self.reset_pin, self.gpio.HIGH)
     super(SSD1306Physical, self).__init__(buffer_rows, buffer_cols)
Exemplo n.º 6
0
 def __init__(self, pin, longpress=0.3):
     self.pin = pin
     self.longpress = longpress
     self.state = Button.OFF
     self.io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
     self.io.pinMode(self.pin, self.io.INPUT)
     self.io.pullUpDnControl(self.pin, self.io.PUD_UP)
Exemplo n.º 7
0
 def __init__(self, motorpins, pwm_range=255):
     self.pi = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
     self.pins = motorpins
     self.speed = 0
     self.pwm_range = pwm_range
     for pin in motorpins:
         print(wiringport[pin])
         self.pi.softPwmCreate(wiringport[pin], 0, pwm_range)
Exemplo n.º 8
0
 def __init__(self, a_pin, b_pin):
     self.a_pin = a_pin
     self.b_pin = b_pin
     self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
     self.gpio.pinMode(self.a_pin, self.gpio.INPUT)
     self.gpio.pullUpDnControl(self.a_pin, self.gpio.PUD_UP)
     self.gpio.pinMode(self.b_pin, self.gpio.INPUT)
     self.gpio.pullUpDnControl(self.b_pin, self.gpio.PUD_UP)
     self.last_delta = 0
     self.r_seq = self.rotation_sequence()
Exemplo n.º 9
0
def is_enabled(button):
	if not WIRING_PI:
		return False

	pin = button_pin[button]

	io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
	state = io.digitalRead(pin)

	return state == 1
Exemplo n.º 10
0
def callback(req):
  io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
  # establecemos el modo de operacion del pin, en este caso es de salida
  # hay que utilizar la nomenclatura de Wiring pi, es MUY IMPORTANTE
  io.pinMode(0, io.OUTPUT)
  if req.data:
    io.digitalWrite(0, io.HIGH)
  else:
    io.digitalWrite(0, io.LOW)

  return SetBoolResponse()
Exemplo n.º 11
0
def disable(button):
	if not WIRING_PI:
		return False

	pin = button_pin[button]

	io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
	io.pinMode(pin, io.OUTPUT)
	io.digitalWrite(pin, io.LOW)

	return True
Exemplo n.º 12
0
 def initGpio(self, gpio, rs=11, e=10, d4=6, d5=5, d6=4, d7=1):
   if gpio == None:
     self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
   else:
     self.gpio = gpio      
   # LCD Pins
   self.E  = self.gpio.pinMode(self.pin_e,  self.gpio.OUTPUT)
   self.RS = self.gpio.pinMode(self.pin_rs, self.gpio.OUTPUT)
   self.D4 = self.gpio.pinMode(self.pin_d4, self.gpio.OUTPUT)
   self.D5 = self.gpio.pinMode(self.pin_d5, self.gpio.OUTPUT)
   self.D6 = self.gpio.pinMode(self.pin_d6, self.gpio.OUTPUT)
   self.D7 = self.gpio.pinMode(self.pin_d7, self.gpio.OUTPUT)
Exemplo n.º 13
0
 def __init__(self, gpio, pin, pull_up=True):
     self.gpio = gpio
     self.pin = pin
     self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
     self.gpio.pinMode(self.pin, self.gpio.INPUT)
     if self.pullUp:
         self.gpio.pullUpDnControl(self.pin, self.gpio.PUD_UP)
     else:
         self.gpio.pullUpDnControl(self.pin, self.gpio.PUD_DOWN)
     self.pull_up = pull_up
     pull_up_mode = gpio.PUD_UP if pull_up else gpio.PUD_DOWN
     self.gpio.setup(self.pin, self.gpio.IN, pull_up_mode)
Exemplo n.º 14
0
    def __init__(self, port, gpio_pinmap={}):
        self.port = port
        self.gpio_pinmap = gpio_pinmap

        if HAVE_GPIO:
            self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO)

            for pin in self.gpio_pinmap.values():
                self.gpio.pinMode(pin, self.gpio.OUTPUT)

        self.device = serial.serial_for_url(self.port,
                                            baudrate=1200,
                                            bytesize=serial.SEVENBITS,
                                            parity=serial.PARITY_EVEN,
                                            stopbits=serial.STOPBITS_TWO)
Exemplo n.º 15
0
	def __init__(self,cePin=2,csnPin=3,channel=1,payload=8):
		# we use wiringPi pin numbering!
		self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) 
		self.cePin = cePin      # pin number for CE
		self.csnPin = csnPin    # pin number for CSN
		self.channel = channel  # RF channel to be used
		self.payload = payload	# size of payload in bytes
		
		self.gpio.pinMode(self.cePin,self.gpio.OUTPUT); #set ce as output
		self.gpio.pinMode(self.csnPin,self.gpio.OUTPUT); #set csn as output

		self.ceLow()
		self.csnHi()

		self.spi = spidev.SpiDev()
		self.spi.open(0,0)
Exemplo n.º 16
0
    def __init__(self, display, pinmap):
        self.display = display
        try:
            import wiringpi
            self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO)
        except:
            raise IOError(
                "Could not export the GPIO pins. Make sure that you have the wiringpi library installed, run as root and are on a Raspberry Pi."
            )

        self.reverse_pinmap = dict([(value, key)
                                    for key, value in pinmap.items()])
        for pin, output in pinmap.items():
            setattr(self, 'PIN_%s' % pin, output)
            if pin == 'LED':
                self.led_pwm = output == 18
            self.gpio.pinMode(
                output, self.gpio.PWM_OUTPUT
                if pin == 'LED' and self.led_pwm else self.gpio.OUTPUT)
Exemplo n.º 17
0
 def __init__(self, bus=0, device=0, dc_pin=1, reset_pin=2, buffer_rows=64, buffer_cols=128, rows=32, cols=128):
     self.cols = cols
     self.rows = rows
     self.buffer_rows = buffer_rows
     self.mem_bytes = self.buffer_rows * self.cols / 8 # total bytes in SSD1306 display ram
     self.dc_pin = dc_pin
     self.reset_pin = reset_pin
     self.spi = spidev.SpiDev()
     self.spi.open(bus, device)
     self.spi.max_speed_hz = 500000
     self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
     self.gpio.pinMode(self.reset_pin, self.gpio.OUTPUT)
     self.gpio.digitalWrite(self.reset_pin, self.gpio.HIGH)
     self.gpio.pinMode(self.dc_pin, self.gpio.OUTPUT)
     self.gpio.digitalWrite(self.dc_pin, self.gpio.LOW)
     self.font = font5x8.Font5x8
     self.col_offset = 0
     self.bitmap = self.Bitmap(buffer_cols, buffer_rows)
     self.flipped = False
Exemplo n.º 18
0
    def __init__(self, gsclk, blank, vprg, xlat, dcprg, sin, sclk):
        self.gsclk = gsclk
        self.blank = blank
        self.vprg = vprg
        self.xlat = xlat
        self.dcprg = dcprg
        self.sin = sin
        self.sclk = sclk

        # setup GPIO pins
        self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        self.gpio.pinMode(self.blank, self.gpio.OUTPUT)
        self.gpio.pinMode(self.vprg, self.gpio.OUTPUT)
        self.gpio.pinMode(self.xlat, self.gpio.OUTPUT)
        self.gpio.pinMode(self.dcprg, self.gpio.OUTPUT)

        self.gpio.pinMode(self.gsclk, self.gpio.OUTPUT)
        self.gpio.pinMode(self.sin, self.gpio.OUTPUT)
        self.gpio.pinMode(self.sclk, self.gpio.OUTPUT)
Exemplo n.º 19
0
 def __init__(self,
              board=None,
              pinmap=PINMAP,
              charmap=None,
              lines=2,
              columns=16,
              characters=40,
              skip_init=False,
              debug=False):
     self.board = board
     self.brightness = 0
     self.debug = debug
     self.line_count = lines
     self.column_count = columns
     self.character_count = characters
     self.max_chars_per_line = self.character_count / self.line_count
     self.lines = ("", "")
     self.cursor_pos = [0, 0]
     self.reverse_pinmap = dict([(value, key)
                                 for key, value in pinmap.iteritems()])
     if not self.board:
         self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO)
     for pin, output in pinmap.iteritems():
         setattr(self, 'PIN_%s' % pin, output)
         if not self.board:
             self.gpio.pinMode(
                 output,
                 self.gpio.PWM_OUTPUT if pin == 'LED' else self.gpio.OUTPUT)
     self.all_low()
     self.set_brightness(1023)
     if not skip_init:
         self.initialize()
         if charmap:
             if 'dir' in charmap:
                 files = os.listdir(charmap['dir'])
                 for filename in files:
                     charmap[int(filename.split(".")[0], 16)] = open(
                         os.path.join(charmap['dir'], filename), 'rb')
                 del charmap['dir']
             for pos, char in charmap.iteritems():
                 self.load_custom_character(pos, char)
             self.set_cursor_position()
Exemplo n.º 20
0
    def __init__(self, pin, defaultState=False, gpio=None):

        self.state = self._setState(defaultState)
        self.pin = pin

        # If no gpio is given, create resource now
        if gpio == None:
            gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        self.gpio = gpio

        # attempt to gain resource to GPIO pin
        try:
            self.sLed = self.gpio.pinMode(self.pin, self.gpio.OUTPUT)
        except:
            print "Error! Couldn't assign pin " + str(
                pin) + " of the GPIO in WPI MODE."
            print "Unexpected error:", sys.exc_info()[0]
            raise

        # Set default state
        self.out(self.state)
Exemplo n.º 21
0
def write(cmd):
    io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)

    MISO = 13
    MOSI = 12
    TxEnable = 2

    io.pinMode(TxEnable, io.OUTPUT)
    io.pinMode(MOSI, io.OUTPUT)
    io.pinMode(MISO, io.INPUT)

    while cmd != 0:
        if (cmd & 0x01):
            #	    io.digitalWrite(MOSI,io.HIGH)
            print(1)
            cmd = cmd >> 1
            sleep(0.000833333)
        else:
            #	    io.digitalWrite(MOSI,io.LOW)
            print(0)
            cmd = cmd >> 1
            sleep(0.000833333)
Exemplo n.º 22
0
    def __init__(self,
                 tlcs,
                 blank,
                 vprg,
                 xlat,
                 dcprg,
                 spibus=0,
                 spidevice=0,
                 spispeed=500000,
                 inverted=True):
        self.n_tlcs = tlcs
        self.n_outputs = self.n_tlcs * 16  # 16 outputs per TLC
        self.blank = blank
        self.vprg = vprg
        self.xlat = xlat
        self.dcprg = dcprg

        # setup SPI
        self.spi = spidev.SpiDev()
        self.spi.open(spibus, spidevice)
        self.spi_fd = self.spi.fileno()
        self.spi.max_speed_hz = spispeed
        if inverted:
            self.spi.mode = 0b10  # invert clock signal

        # setup GPIO pins
        self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        self.gpio.pinMode(self.blank, self.gpio.OUTPUT)
        self.gpio.pinMode(self.vprg, self.gpio.OUTPUT)
        self.gpio.pinMode(self.xlat, self.gpio.OUTPUT)
        self.gpio.pinMode(self.dcprg, self.gpio.OUTPUT)

        if inverted:
            self.HIGH = self.gpio.LOW
            self.LOW = self.gpio.HIGH
        else:
            self.HIGH = self.gpio.HIGH
            self.LOW = self.gpio.LOW
Exemplo n.º 23
0
    def __init__(self, pinmap):
        try:
            import wiringpi
            self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO)
        except:
            raise IOError(
                "Could not export the GPIO pins. Make sure that you have the wiringpi library installed, run as root and are on a Raspberry Pi."
            )

        self.pinmap = dict([(key, value if type(value) in [list, tuple] else
                             (value, False, 1))
                            for key, value in pinmap.iteritems()])
        self.reverse_pinmap = dict([(value[0], key)
                                    for key, value in self.pinmap.iteritems()])
        for name, pin_data in self.pinmap.iteritems():
            pin, output, pullup = pin_data

            setattr(self, 'PIN_%s' % name, pin)
            self.gpio.pinMode(pin,
                              self.gpio.OUTPUT if output else self.gpio.INPUT)
            if pullup != 0:
                wiringpi.pullUpDnControl(
                    pin, wiringpi.PUD_UP if pullup > 0 else wiringpi.PUD_DOWN)
Exemplo n.º 24
0
#FLASH_IO=12
#DIAS_IO=13
def reset_pins(io, pin):
    io.pinMode(pin,io.OUTPUT)
    io.digitalWrite(pin, io.LOW)


def pwm_dim(io, pin, val):
    val = val*1024 #maps percent to 1024 range
    io.pinMode(pin,io.PWM_OUTPUT)
    io.pwmWrite(pin, int(val))
    if(val == 0):
        io.digitalWrite(pin, io.LOW)


io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)

reset_pins(io, FLASH_IO)
reset_pins(io, DIAS_IO)

def flash_led(val):
    print("Flash", val)
    #led = PWMLED(FLASH_IO)
    if val:
        pwm_dim(io,FLASH_IO,0.95)
    else:
        pwm_dim(io,FLASH_IO,0.0)
    return

def dias_led(val):
    print("Dias", val)
Exemplo n.º 25
0
import time

import wiringpi as wp
from constants import *
from utils import angle_to_time, cm_to_time

gpio = wp.GPIO(wp.GPIO.WPI_MODE_PINS)


class Car:
    def __init__(self):
        self.setup()

    def setup(self):
        wp.wiringPiSetup()
        for pin in OUTPUTS:
            wp.pinMode(pin, 1)
        for pin in INPUTS:
            wp.pinMode(pin, gpio.INPUT)

        wp.softPwmCreate(MOTOR_1, MIN_SPEED, MAX_SPEED)
        wp.softPwmCreate(MOTOR_2, MIN_SPEED, MAX_SPEED)
        wp.softPwmCreate(MOTOR_3, MIN_SPEED, MAX_SPEED)
        wp.softPwmCreate(MOTOR_4, MIN_SPEED, MAX_SPEED)

    def forward(self, speed=100):
        wp.softPwmWrite(MOTOR_1, int(MAX_SPEED / (100 / speed)))
        wp.softPwmWrite(MOTOR_2, MIN_SPEED)
        wp.softPwmWrite(MOTOR_3, int(MAX_SPEED / (100 / speed)))
        wp.softPwmWrite(MOTOR_4, MIN_SPEED)
Exemplo n.º 26
0
    def run(self, fullscreen):
        print "Running..."
        pygame.init()
        mocpid = os.path.expanduser("~/.moc/pid")
        if os.path.exists(mocpid):
            proc = os.path.join('/proc', open(mocpid).read().strip())
            if not os.path.exists(proc):
                print "Removing stale moc pid file..."
                os.remove(mocpid)
        if not os.path.exists(mocpid):
            subprocess.call(['mocp', '--server'])
        if fullscreen:
            self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        else:
            self.screen = pygame.display.set_mode(SCREEN_SIZE)
        pygame.mouse.set_visible(False)
        self.set_album(0)
        poll_thread = threading.Thread(target=self.poll)
        poll_thread.daemon = True
        poll_thread.start()
        shell_thread = threading.Thread(target=self.shell)
        shell_thread.daemon = True
        shell_thread.start()
        if wiringpi is not None:
            init_gpio()
            io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
            pygame.time.set_timer(POLL_GPIO, 5)
            knob = Knob(io)
            button = Button(io)
            self.tv = TV(io)
            self.amp = Amp(io)
        pygame.time.set_timer(POLL_JOG, 100)
        while True:
            event = pygame.event.wait()
            if event.type == pygame.KEYDOWN:
                if event.unicode == u'q':
                    sys.exit(0)
                elif event.key == 275:
                    self.jog(1)
                elif event.key == 276:
                    self.jog(-1)
                elif event.unicode == u' ':
                    self.button()

            elif event.type == POLL_GPIO:
                if self.state == self.ASLEEP:
                    if knob.read() or button.pressed():
                        self.wake_up()
                else:
                    jog = knob.read()
                    if jog:
                        self.jog(jog)
                    elif button.pressed():
                        self.button()
                    elif self.state == self.IDLE:
                        if time.time() - self.idle_since > IDLE_TIMEOUT:
                            self.fall_asleep()

            elif event.type == POLL_JOG:
                if self.state == self.PLAYING and self.jog_state:
                    self.jog_track(self.jog_state.amount)
                    self.jog_state.clear()
                self.jog_state.tick()
Exemplo n.º 27
0
import roslib
import rospy
import time
import wiringpi
import subprocess
from std_msgs.msg import String

#main
if __name__ == '__main__':
    ### init io port ###
    subprocess.check_call('gpio export 14 out', shell=True)
    subprocess.check_call('gpio export 17 out', shell=True)
    ###
    rospy.init_node('led_pub')

    io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO_SYS)
    io.pinMode(14, io.OUTPUT)  # ピンのセットアップ
    io.pinMode(17, io.OUTPUT)

    while not rospy.is_shutdown():
        i = raw_input()
        pub = rospy.Publisher('led_flash_str', String, queue_size=1)
        pub.publish(i)

        if i == '0':
            io.digitalWrite(14, 0)
            io.digitalWrite(17, 0)
            time.sleep(1)
        elif i == '1':
            io.digitalWrite(14, 1)
            io.digitalWrite(17, 1)
 def init_gpio_out_pin(self, pin):
     os.system("gpio export %s out" % pin)
     pin_obj = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
     pin_obj.pinMode(pin, pin_obj.OUTPUT)
     wiringpi.pinMode(pin, pin_obj.OUTPUT)
     return pin_obj
Exemplo n.º 29
0
# -*- coding: utf-8 -*-

import string
import wiringpi as wp
import time
import struct
import signal
import sys
import subprocess

L6470_SPI_SPEED = 1000000
STEPPING_TICK = 200

BUSY_PIN_0 = 21
BUSY_PIN_1 = 20
io = wp.GPIO(wp.GPIO.WPI_MODE_GPIO)
io.pinMode(BUSY_PIN_0, io.INPUT)
io.pinMode(BUSY_PIN_1, io.INPUT)


def exit_handler(signal, frame):
    print("\nExit")
    L6470_softstop(0)
    L6470_softstop(1)
    L6470_softhiz(0)
    L6470_softhiz(1)
    quit()


signal.signal(signal.SIGINT, exit_handler)
Exemplo n.º 30
0
    def __init__(self, pin):
        self.pin = pin

        self.gpio = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        self.gpio.pinMode(self.pin, self.gpio.INPUT)
        self.gpio.pullUpDnControl(self.pin, self.gpio.PUD_UP)