Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Richard Seltrecht
Published © GPL3+

Family Board using AWS IOT

A Family Board is a led matrix that displays a message sent by a mobile phone using AWS IOT and AWS SNS for notification on mobile phones.

IntermediateFull instructions provided2,867
Family Board using AWS IOT

Things used in this project

Hardware components

Raspberry Pi 1 Model B+
Raspberry Pi 1 Model B+
×1
HC-SR04 Ranging Detector Mod Distance Sensor
×1
Adafruit 16mm Panel Mount Momentary Pushbutton - Black
×1
Adafruit RGB Matrix HAT + RTC for Raspberry Pi - Mini Kit
×1
Adafruit 64x32 RGB LED Matrix - 5mm pitch
×1
Switching Power Supplies 110W 5V 22A 85-264VAC
×1

Software apps and online services

AWS IoT
Amazon Web Services AWS IoT
AWS SNS
Amazon Web Services AWS SNS
AWS Cognito
Amazon Web Services AWS Cognito

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Button connected to Raspberry Pi

The button is connected to GPIO 18

Family Board completed

Ultrasonic Sensor

GPIO used are 24 and 25

Code

Family Board on Raspberry Pi

Python
Connect to raspberry pi using SSH
Command :
sudo python familyboard01.py
import json
import ssl
import time
import subprocess
import os
import paho.mqtt.client as mqtt
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

# GPIO 18 is used for arcade button
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

devicecert = "/home/pi/aws/cert.pem"
devicekey = "/home/pi/aws/privateKey.pem"
servercert = "/home/pi/aws/root-CA.pem"
server = "<your aws server url>"
topic="$aws/things/testThing01/shadow/update"
qos=0
retain=False

def on_message(client, userdata, msg):
    # Message received for led matrix, analyse it and send it to led matrix
    # When a message is publish by the mobile phone on topic familyboard/display
    # the message is sent to the led matrix
    print("Message: " + msg.topic + " Payload:" + str(msg.payload))

    # Message contains message to display and color indication 
    strPayload = msg.payload 
    colorPos = strPayload.find("color=")
    colorStr = strPayload[colorPos+6:]
    c = (255, 0, 0)

    if "red" in colorStr : 
        c = (252, 76, 2)
        
    if "blue" in colorStr : 
        c = (0, 122, 255)
        
    if "green" in colorStr :
        c = (109, 196, 79)
    
    #text = (str(msg.payload), (0, 0, 255))
    font = ImageFont.truetype("/usr/share/fonts/truetype/droid/DroidSans.ttf", 32)
    all_text = strPayload[0:colorPos]

    width, ignore = font.getsize(all_text)
    im = Image.new("RGB", (width + 30, 32), "black")
    draw = ImageDraw.Draw(im)

    x = 0
    t = all_text
    draw.text((x, 0), t, c, font=font)

    # The text with font and color is saved on a image in ppm format and sent
    # to the led matrix
    im.save("test.ppm")
    os.system("./led-matrix -D 1 -c 2 -t 20 test.ppm")
    
def on_log(client, userdata, level, msg):
    print("Log: " + msg)

def on_connect(client, userdata, flags, rc):
    print("on_connect: ")
    #client.subscribe("$aws/things/testThing01/#")
    client.subscribe("familyboard/display")

def button_pressed(channel):
    print("button pressed")
    message = "button pressed"
    client.publish("familyboard/button", message, qos, retain)
    
client = mqtt.Client("testThing01")
client.on_connect = on_connect
client.on_message = on_message
client.on_log = on_log
client.tls_set(servercert, devicecert, devicekey, ssl.CERT_REQUIRED, ssl.PROTOCOL_SSLv23)
client.connect(server, 8883, 60)

client.loop_start()

awsmsg = {'state':{ 'reported': {'powerup': 1 }}} #update on power up
payload = json.dumps(awsmsg)
client.publish(topic, payload ,qos, retain)

GPIO.add_event_detect(18, GPIO.FALLING, callback=button_pressed, bouncetime=75)

# set sonar
TRIG = 24 
ECHO = 25

print "Distance Measurement In Progress"

GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)

GPIO.output(TRIG, False)
print "Waiting For Sensor To Settle"
time.sleep(2)

while True:
    GPIO.output(TRIG, True)
    time.sleep(0.00001)
    GPIO.output(TRIG, False)

    while GPIO.input(ECHO)==0:
        pulse_start = time.time()

    while GPIO.input(ECHO)==1:
        pulse_end = time.time()

    pulse_duration = pulse_end - pulse_start
    distance = pulse_duration * 17150
    distance = round(distance, 2)

    if distance < 50 :
        print "Distance:",distance,"cm"
        message = "Sonar detection"
        client.publish("familyboard/sonar", message, qos, retain)
    
    time.sleep(2)

Family Board iPhone application

Sources of the iPhone application used for Family Board You have to change values in Constants.swift

Credits

Richard Seltrecht

Richard Seltrecht

3 projects • 9 followers
20 years of experience in software development. Team leader for iOS and Android development team Maker, love programming IOT devices
Thanks to Adafruit and Amazon.

Comments