Skip to content

Latest commit

 

History

History

QtEducationalProp

Qt Educational prop

Educational example of pure Python prop using PyQt5.

An educational example which makes a LED blinking and making a sound when an RFID tag is detected. And unlock a door when an object (magnetic) is detected by a reed switch.

This prop uses PyQt5 and extends QtPropApp.

We use a MIFARE RFID-RC522 module:

http://wiki.sunfounder.cc/index.php?title=Mifare_RC522_Module_RFID_Reader

RC522 pin Raspberry Pi 3 pin name
SDA GPIO8
SCK GPIO11
MOSI GPIO10
MISO GPIO9
IRQ Not connected
GND GND
RST GPIO25
3.3V 3V3

We tested with a NFC Pi Hat as well: https://www.waveshare.com/wiki/PN532_NFC_HAT

If you need two NFC reader you wil find help at https://github.com/pat-odoo/TwoRC522_RPi2-3

Installation

This prop was created before PyProps library was released so there is no dependencies with PyProps.

You will have to install following Python packages:

    $ pip3 install paho-mqtt
    $ pip3 install PyYAML
    $ sudo apt-get update
    $ sudo apt-get install qt5-default pyqt5-dev pyqt5-dev-tools
    $ sudo apt-get install python3-pyqt5 python3-pyqt5-dbg

PyQt5.QtMultimedia must be installed:

    $ sudo apt-get update
    $ sudo apt-get install python3-pyqt5.qtmultimedia

May have to install pulseaudio:

    $ sudo apt-get upgrade
    $ sudo apt-get install libasound2-dev pulseaudio libpulse-dev
    $ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev \
        libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-base \
        gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad \
        libgstreamer-plugins-bad1.0-dev gstreamer1.0-pulseaudio gstreamer1.0-tools \
        gstreamer1.0-alsa
    $ sudo modprobe snd-bcm2835
    $ echo "snd-bcm2835" | sudo tee -a /etc/modules

Test pulseaudio (output on HDMI TV monitor):

pi@raspberrypi:~/Room/Props/PyProps/QtProp/QtEducationalProp $ aplay audio/ringtone.wav 
Playing WAVE 'audio/ringtone.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

RFID-RC522 module configuration

  1. enable SPI in raspi-config
  2. check:
    $ lsmod | grep spi
    spidev                 16384  0
    spi_bcm2835            16384  0
  1. install python library
    $ sudo apt-get update
    $ sudo apt-get upgrade
  1. download and install SPI-Py
    $ cd ~
    $ git clone https://github.com/lthiery/SPI-Py.git
    $ cd ~/SPI-Py
    $ sudo python3 setup.py install
  1. test reading a tag
    $ sudo python Read.py

Usage

Start main.py script in /home/pi/Room/Props/PyProps/QtProp/QtEducationalProp/:

pi@raspberrypi:~ $ python3 ~/Room/Props/PyProps/QtProp/QtEducationalProp/main.py -s 192.168.1.42 -d

Config: {'host': '192.168.1.42'}
INFO - New periodic action added 'send all data' every 10.0 seconds
INFO - New boolean Publishable 'led' (1/0) with initial=0
INFO - New boolean Publishable 'blinking' (yes/no) with initial=0
INFO - New boolean Publishable 'sounding' (yes/no) with initial=0
INFO - New periodic action added 'blink' every 1.0 seconds
INFO - New boolean Publishable 'nfc' (yes/no) with initial=0
INFO - No NFC module configured'
INFO - Periodic task created 'send all data' every 10.0 seconds
INFO - Periodic task created 'blink' every 1.0 seconds
INFO - Program connected to MQTT server
INFO - Program sending message 'CONNECTED' (mid=1) on Room/My room/Props/Raspberry QtEducational/outbox
INFO - Program subscribing to topic (mid=2) : Room/My room/Props/Raspberry QtEducational/inbox
INFO - Program sending message 'DATA led=0 blinking=no sounding=yes nfc=no' (mid=3) on Room/My room/Props/Raspberry QtEducational/outbox
DEBUG - MQTT message is published : mid=1 userdata={'host': '192.168.1.42', 'port': 1883}
INFO - Message published (mid=1)
DEBUG - MQTT topic is subscribed : mid=2 granted_qos=(1,)
INFO - Program susbcribed to topic (mid=2) with QoS (1,)
DEBUG - MQTT message is published : mid=3 userdata={'host': '192.168.1.42', 'port': 1883}
INFO - Message published (mid=3)
INFO - Message received : '@PING' in Room/My room/Props/Raspberry QtEducational/inbox
INFO - Program sending message 'PONG' (mid=4) on Room/My room/Props/Raspberry QtEducational/outbox
DEBUG - MQTT message is published : mid=4 userdata={'host': '192.168.1.42', 'port': 1883}
INFO - Message published (mid=4)

SSH relaunch command

The command to relaunch the prop is :

$ ps aux | grep python | grep -v "grep python" | grep QtEducationalProp/main.py | awk '{print $2}' | xargs kill -9 && screen -d -m python3 /home/pi/Room/Props/PyProps/QtProp/QtEducationalProp/main.py -s %BROKER%

Qt Educational Prop as a prop for xcape.io Room

To use QtEducationalProp as a prop for xcape.io Room software, here are prop commands and messages as well as a suggested control panel.

Prop commands

  • blink:0 : deactivate blinking
  • blink:1 : activate blinking
  • sound:0 : mute blinking sound
  • sound:1 : unmute blinking sound

Prop configuration

Add and configure Raspberry PygameBlink connected props.

Prop configuration

Prop data messages

Outbox messages

Prop control panel

Room control panel

Author

Faure Systems (Apr 10th, 2020)

  • company: FAURE SYSTEMS SAS
  • mail: dev at faure dot systems
  • github: xcape-io
  • web: xcape.io