Skip to content

Instantly share code, notes, and snippets.

@wamonite
Created February 24, 2017 19:11
Show Gist options
  • Save wamonite/0b7bc3f20d7d756e721b048fc5ff9bcf to your computer and use it in GitHub Desktop.
Save wamonite/0b7bc3f20d7d756e721b048fc5ff9bcf to your computer and use it in GitHub Desktop.
ModMyPi PiOT example code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://www.modmypi.com/raspberry-pi/breakout-boards/modmypi/modmypi-piot-relay-board
from __future__ import print_function, unicode_literals
import sys
import RPi.GPIO as GPIO
import time
RELAY_CONNECT_PIN = 3 # GPIO 2 (not configurable)
RELAY1_PIN = 29 # GPIO 5
RELAY2_PIN = 31 # GPIO 6
RELAY3_PIN = 33 # GPIO 13
RELAY4_PIN = 35 # GPIO 19
RELAY_LIST = [
RELAY1_PIN,
RELAY2_PIN,
RELAY3_PIN,
RELAY4_PIN
]
def handshake():
for idx in range(4):
GPIO.output(RELAY_CONNECT_PIN, 1)
time.sleep(0.05)
GPIO.output(RELAY_CONNECT_PIN, 0)
time.sleep(0.05)
def do_piot_test():
try:
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(RELAY_CONNECT_PIN, GPIO.OUT)
GPIO.output(RELAY_CONNECT_PIN, 0)
for relay_pin in RELAY_LIST:
GPIO.setup(relay_pin, GPIO.OUT)
GPIO.output(relay_pin, 0)
time.sleep(2)
handshake()
for relay_pin in RELAY_LIST:
GPIO.output(relay_pin, 1)
time.sleep(1)
GPIO.output(relay_pin, 0)
time.sleep(1)
time.sleep(2)
handshake()
finally:
GPIO.cleanup()
if __name__ == "__main__":
try:
do_piot_test()
except Exception as e:
print('Error:{}: {}'.format(e.__class__.__name__, e), file = sys.stderr)
sys.exit(1)
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment