You are reading a single comment by @pascalo and its replies. Click here to read the full conversation.
  • Neato! Are the relays wired directly to the gpio pins? Did you have to worry about current drain and flyback diodes?

  • Yep, just wired directly to it via jumper cables.
    I didn't worry about any of that, nope.

    This is the relay I used:

    https://www.sainsmart.com/products/2-channel-5v-relay-module

    Python side:

    import boto3
    from time import sleep
    
    import json
    import sys
    import traceback
    import RPi.GPIO as GPIO
    from time import sleep
    
    import datetime as dt
    
    from subprocess import call
    
    
    # Set up SQS
    sqs = boto3.resource('sqs')
    queue = sqs.Queue('QUEUE_URI')
    
    # Set up S3
    s3 = boto3.resource('s3');
    
    # Set up GPIO
    GPIO.setmode(GPIO.BCM)
    
    GPIO.setup(24, GPIO.OUT)
    GPIO.output(24, GPIO.HIGH)
    
    GPIO.setup(25, GPIO.OUT)
    GPIO.output(25, GPIO.HIGH)
    
    
    def takeAndStorePicture(name):
        call(['fswebcam', '-q', '--rotate', '180', '-r', '640x360', '--jpeg', '80', '--timestamp', '%D %T (%Z)', name])
        obj = s3.Object('BUCKET_NAME', name).upload_file(name, ExtraArgs={
            'ACL': 'public-read'
        })
    
    
    def relayOnOff(side):
    
        if side == 'left':
            channel = 24
    
        if side == 'right':
            channel = 25
    
        GPIO.output(channel, GPIO.LOW)
        sleep(1)
        GPIO.output(channel, GPIO.HIGH)
    
    
    def main():
        try:
    
           while(True):
                messages = queue.receive_messages()
    
                for message in messages:
                     print 'Message: ' + message.body
                     j = json.loads(message.body)
                     takeAndStorePicture('before.jpg')
                     relayOnOff(j['Message'])
                     message.delete()
                     sleep(10)
                     takeAndStorePicture('after.jpg')
    
                sleep(1)
    
        except KeyboardInterrupt:
            print "Shutdown requested...exiting"
    
        except Exception:
            traceback.print_exc(file=sys.stdout)
    
        GPIO.cleanup();
        sys.exit(0)
    
    if __name__ == "__main__":
        main()
    
    
About

Avatar for pascalo @pascalo started