def t1(): print("Mode/PUD/read/write tests.") pigpio.set_mode(GPIO, pigpio.INPUT) v = pigpio.get_mode(GPIO) CHECK(1, 1, v, 0, 0, "set mode, get mode") pigpio.set_pull_up_down(GPIO, pigpio.PUD_UP) v = pigpio.read(GPIO) CHECK(1, 2, v, 1, 0, "set pull up down, read") pigpio.set_pull_up_down(GPIO, pigpio.PUD_DOWN) v = pigpio.read(GPIO) CHECK(1, 3, v, 0, 0, "set pull up down, read") pigpio.write(GPIO, pigpio.LOW) v = pigpio.get_mode(GPIO) CHECK(1, 4, v, 1, 0, "write, get mode") v = pigpio.read(GPIO) CHECK(1, 5, v, 0, 0, "read") pigpio.write(GPIO, pigpio.HIGH) v = pigpio.read(GPIO) CHECK(1, 6, v, 1, 0, "write, read")
def __init__(self, gpio_0, gpio_1, callback, bit_timeout=5): """ Instantiate with the gpio for 0 (green wire), the gpio for 1 (white wire), the callback function, and the bit timeout in milliseconds which indicates the end of a code. The callback is passed the code length in bits and the value. """ self.gpio_0 = gpio_0 self.gpio_1 = gpio_1 self.callback = callback self.bit_timeout = bit_timeout self.in_code = False pigpio.set_mode(gpio_0, pigpio.INPUT) pigpio.set_mode(gpio_1, pigpio.INPUT) pigpio.set_pull_up_down(gpio_0, pigpio.PUD_UP) pigpio.set_pull_up_down(gpio_1, pigpio.PUD_UP) self.cb_0 = pigpio.callback(gpio_0, pigpio.FALLING_EDGE, self._cb) self.cb_1 = pigpio.callback(gpio_1, pigpio.FALLING_EDGE, self._cb)
def start(self): pigpio.set_mode(self.GPIO_TRIGGER, pigpio.OUTPUT) pigpio.set_mode(self.GPIO_ECHO, pigpio.INPUT) pigpio.write(self.GPIO_TRIGGER, 0) self.echo_cb = pigpio.callback( self.GPIO_ECHO, pigpio.EITHER_EDGE, self.on_echo) pigpio.set_watchdog(self.GPIO_ECHO, 100)
def trigger(self): """Trigger a new relative humidity and temperature reading.""" self.bit = -3 # header bits self.hH = 0 self.hL = 0 self.tH = 0 self.tL = 0 self.CS = 0 self.accumulating = True pigpio.write(self.gpio, 0) time.sleep(0.0001) pigpio.set_mode(self.gpio, pigpio.INPUT) pigpio.set_watchdog(self.gpio, 50)
def __init__(self, gpio): """ Instantiate with the gpio to which the DHT22 output pin is connected. """ self.gpio = gpio self.bad_CS = 0 # checksum self.bad_TO = 0 # time-out self.accumulating = False self.rhum = -999 self.temp = -999 self.tov = None self.tick = 0 pigpio.set_mode(gpio, pigpio.INPUT) pigpio.set_pull_up_down(gpio, pigpio.PUD_OFF) self.cb = pigpio.callback(gpio, pigpio.EITHER_EDGE, self._cb)
def t5(): global t5_count BAUD = 4800 TEXT = """ Now is the winter of our discontent Made glorious summer by this sun of York; And all the clouds that lour'd upon our house In the deep bosom of the ocean buried. Now are our brows bound with victorious wreaths; Our bruised arms hung up for monuments; Our stern alarums changed to merry meetings, Our dreadful marches to delightful measures. Grim-visaged war hath smooth'd his wrinkled front; And now, instead of mounting barded steeds To fright the souls of fearful adversaries, He capers nimbly in a lady's chamber To the lascivious pleasing of a lute. """ print("Waveforms & serial read/write tests.") t5cb = pigpio.callback(GPIO, pigpio.FALLING_EDGE, t5cbf) pigpio.set_mode(GPIO, pigpio.OUTPUT) e = pigpio.wave_clear() CHECK(5, 1, e, 0, 0, "callback, set mode, wave clear") wf = [] wf.append(pigpio.pulse(1 << GPIO, 0, 10000)) wf.append(pigpio.pulse(0, 1 << GPIO, 30000)) wf.append(pigpio.pulse(1 << GPIO, 0, 60000)) wf.append(pigpio.pulse(0, 1 << GPIO, 100000)) e = pigpio.wave_add_generic(wf) CHECK(5, 2, e, 4, 0, "pulse, wave add generic") e = pigpio.wave_tx_repeat() CHECK(5, 3, e, 9, 0, "wave tx repeat") oc = t5_count time.sleep(5) c = t5_count - oc CHECK(5, 4, c, 50, 1, "callback") e = pigpio.wave_tx_stop() CHECK(5, 5, e, 0, 0, "wave tx stop") e = pigpio.serial_read_open(GPIO, BAUD) CHECK(5, 6, e, 0, 0, "serial read open") pigpio.wave_clear() e = pigpio.wave_add_serial(GPIO, BAUD, 5000000, TEXT) CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial") e = pigpio.wave_tx_start() CHECK(5, 8, e, 6811, 0, "wave tx start") oc = t5_count time.sleep(3) c = t5_count - oc CHECK(5, 9, c, 0, 0, "callback") oc = t5_count while pigpio.wave_tx_busy(): time.sleep(0.1) time.sleep(0.1) c = t5_count - oc CHECK(5, 10, c, 1702, 0, "wave tx busy, callback") c, text = pigpio.serial_read(GPIO) CHECK(5, 11, TEXT == text, True, 0, "wave tx busy, serial read") e = pigpio.serial_read_close(GPIO) CHECK(5, 12, e, 0, 0, "serial read close") c = pigpio.wave_get_micros() CHECK(5, 13, c, 6158704, 0, "wave get micros") CHECK(5, 14, 0, 0, 0, "NOT APPLICABLE") c = pigpio.wave_get_max_micros() CHECK(5, 15, c, 1800000000, 0, "wave get max micros") c = pigpio.wave_get_pulses() CHECK(5, 16, c, 3405, 0, "wave get pulses") CHECK(5, 17, 0, 0, 0, "NOT APPLICABLE") c = pigpio.wave_get_max_pulses() CHECK(5, 18, c, 12000, 0, "wave get max pulses") c = pigpio.wave_get_cbs() CHECK(5, 19, c, 6810, 0, "wave get cbs") CHECK(5, 20, 0, 0, 0, "NOT APPLICABLE") c = pigpio.wave_get_max_cbs() CHECK(5, 21, c, 25016, 0, "wave get max cbs") e = pigpio.wave_clear() CHECK(5, 22, e, 0, 0, "wave clear") e = pigpio.wave_add_generic(wf) CHECK(5, 23, e, 4, 0, "pulse, wave add generic") w1 = pigpio.wave_create() CHECK(5, 24, w1, 0, 0, "wave create") e = pigpio.wave_send_repeat(w1) CHECK(5, 25, e, 9, 0, "wave send repeat") oc = t5_count time.sleep(5) c = t5_count - oc CHECK(5, 26, c, 50, 1, "callback") e = pigpio.wave_tx_stop() CHECK(5, 27, e, 0, 0, "wave tx stop") e = pigpio.wave_add_serial(GPIO, BAUD, 5000000, TEXT) CHECK(5, 28, e, 3405, 0, "wave add serial") w2 = pigpio.wave_create() CHECK(5, 29, w2, 1, 0, "wave create") e = pigpio.wave_send_once(w2) CHECK(5, 30, e, 6811, 0, "wave send once") oc = t5_count time.sleep(3) c = t5_count - oc CHECK(5, 31, c, 0, 0, "callback") oc = t5_count while pigpio.wave_tx_busy(): time.sleep(0.1) time.sleep(0.1) c = t5_count - oc CHECK(5, 32, c, 1702, 0, "wave tx busy, callback") e = pigpio.wave_delete(0) CHECK(5, 33, e, 0, 0, "wave delete")
def pigpio_init_pwm(self): AbstractPWMGenerator.pigpio_init_pwm(self) pigpio.set_mode(self.gpio_direction_pin, pigpio.OUTPUT)
GOPRO_IP = '10.5.5.9' GOPRO_SSID = 'Valtor' GOPRO_PASS = '******' #GOPRO_SSID = 'vulcan' #GOPRO_PASS = '******' GOPRO_MAC = 'd6d919ee4133' network = Wireless(IFACE) ########################################## # # GPIO setup # import pigpio pigpio.start() GPIO_PIN = 11 pigpio.set_mode(GPIO_PIN, pigpio.INPUT) ########################################### camera = None # # The Main loop # def main_loop(): global camera camera = GoProHero(password=GOPRO_PASS) # Record a 5 second test video, just to signal the user that # Raspberry Pi has booted up and that this program is running. This is useful # as feedback, when your Pi is not connected to a monitor or a terminal
self.speed = speed motor1 = motor(pin1, 1210) #front motor speed initialised at 1210 ms pulse width motor2 = motor(pin2, 1230) #back motor speed initialised at 1230 ms pulse width motors = [] #array of motors to be controlled motors.append(motor1) motors.append(motor2) if pigpio.start(''): # must run notification test on localhost print("Connected to pigpio daemon.") #initialisation pigpio.set_mode(pin1, pigpio.OUTPUT) pigpio.set_mode(pin2, pigpio.OUTPUT) pigpio.set_PWM_range(pin1, 255) pigpio.set_PWM_range(pin2, 255) pigpio.set_PWM_frequency(pin1, 50) pigpio.set_PWM_frequency(pin2, 50) pigpio.set_servo_pulsewidth(pin1, 0) pigpio.set_servo_pulsewidth(pin2, 0) #open the serial port rfcomm1 defined in rfcomm.conf file ser = serial.Serial('/dev/rfcomm1', 38400, timeout=.08) print("\nConnected\n") ser.write('Connected') #send message to the smartphone raw = ser.readline()
def init_pin(pin): pigpio.start() pigpio.set_mode(PIN, pigpio.OUTPUT)
def t5(): global t5_count BAUD=4800 TEXT=""" Now is the winter of our discontent Made glorious summer by this sun of York; And all the clouds that lour'd upon our house In the deep bosom of the ocean buried. Now are our brows bound with victorious wreaths; Our bruised arms hung up for monuments; Our stern alarums changed to merry meetings, Our dreadful marches to delightful measures. Grim-visaged war hath smooth'd his wrinkled front; And now, instead of mounting barded steeds To fright the souls of fearful adversaries, He capers nimbly in a lady's chamber To the lascivious pleasing of a lute. """ print("Waveforms & serial read/write tests.") t5cb = pigpio.callback(GPIO, pigpio.FALLING_EDGE, t5cbf) pigpio.set_mode(GPIO, pigpio.OUTPUT) e = pigpio.wave_clear() CHECK(5, 1, e, 0, 0, "callback, set mode, wave clear") wf = [] wf.append(pigpio.pulse(1<<GPIO, 0, 10000)) wf.append(pigpio.pulse(0, 1<<GPIO, 30000)) wf.append(pigpio.pulse(1<<GPIO, 0, 60000)) wf.append(pigpio.pulse(0, 1<<GPIO, 100000)) e = pigpio.wave_add_generic(wf) CHECK(5, 2, e, 4, 0, "pulse, wave add generic") e = pigpio.wave_tx_repeat() CHECK(5, 3, e, 9, 0, "wave tx repeat") oc = t5_count time.sleep(5) c = t5_count - oc CHECK(5, 4, c, 50, 1, "callback") e = pigpio.wave_tx_stop() CHECK(5, 5, e, 0, 0, "wave tx stop") e = pigpio.serial_read_open(GPIO, BAUD) CHECK(5, 6, e, 0, 0, "serial read open") pigpio.wave_clear() e = pigpio.wave_add_serial(GPIO, BAUD, 5000000, TEXT) CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial") e = pigpio.wave_tx_start() CHECK(5, 8, e, 6811, 0, "wave tx start") oc = t5_count time.sleep(3) c = t5_count - oc CHECK(5, 9, c, 0, 0, "callback") oc = t5_count while pigpio.wave_tx_busy(): time.sleep(0.1) time.sleep(0.1) c = t5_count - oc CHECK(5, 10, c, 1702, 0, "wave tx busy, callback") c, text = pigpio.serial_read(GPIO) CHECK(5, 11, TEXT == text, True, 0, "wave tx busy, serial read"); e = pigpio.serial_read_close(GPIO) CHECK(5, 12, e, 0, 0, "serial read close") c = pigpio.wave_get_micros() CHECK(5, 13, c, 6158704, 0, "wave get micros") CHECK(5, 14, 0, 0, 0, "NOT APPLICABLE") c = pigpio.wave_get_max_micros() CHECK(5, 15, c, 1800000000, 0, "wave get max micros") c = pigpio.wave_get_pulses() CHECK(5, 16, c, 3405, 0, "wave get pulses") CHECK(5, 17, 0, 0, 0, "NOT APPLICABLE") c = pigpio.wave_get_max_pulses() CHECK(5, 18, c, 12000, 0, "wave get max pulses") c = pigpio.wave_get_cbs() CHECK(5, 19, c, 6810, 0, "wave get cbs") CHECK(5, 20, 0, 0, 0, "NOT APPLICABLE") c = pigpio.wave_get_max_cbs() CHECK(5, 21, c, 25016, 0, "wave get max cbs")
def __init__(self, pin, speed): self.pin = pin self.speed = speed motor1 = motor(pin1, 1210) # front motor speed initialised at 1210 ms pulse width motor2 = motor(pin2, 1230) # back motor speed initialised at 1230 ms pulse width motors = [] # array of motors to be controlled motors.append(motor1) motors.append(motor2) if pigpio.start(""): # must run notification test on localhost print("Connected to pigpio daemon.") # initialisation pigpio.set_mode(pin1, pigpio.OUTPUT) pigpio.set_mode(pin2, pigpio.OUTPUT) pigpio.set_PWM_range(pin1, 255) pigpio.set_PWM_range(pin2, 255) pigpio.set_PWM_frequency(pin1, 50) pigpio.set_PWM_frequency(pin2, 50) pigpio.set_servo_pulsewidth(pin1, 0) pigpio.set_servo_pulsewidth(pin2, 0) # open the serial port rfcomm1 defined in rfcomm.conf file ser = serial.Serial("/dev/rfcomm1", 38400, timeout=0.08) print("\nConnected\n") ser.write("Connected") # send message to the smartphone raw = ser.readline()