In this tutorial we learn how to set up a Raspberry Pi to connect to a PIR sensor using the Gravio Platform and then trigger various animated GIFs via CATT on to broadcast them to a laser projector using a Chromecast dongle. In step 2, you will also learn how to order your sensors. Please note that it will take a couple of days for the sensors to reach you, depending on where you are.
You will need the following hardware:
First, download and install the Raspberry Pi Imager software. This software will help you to easily download and write the operating system to the respective SD card. Insert your SD card with at least 16 GB space in your SD card slot and pick the Ubuntu 20.04 LTS 64 Bit onto the SD card.
In the next step, make sure you select the right SD card you wish to install the software on and hit the “Write” button.
Wait until the SD card is written and verified.
Once verified, remove the SD Card from your computer and insert it into your Raspberry Pi 4 and connect it to a keyboard, screen and power.
You will need the screen and keyboard only in the beginning to connect your Raspberry Pi to the wireless network:
Open the file
sudo vim /etc/netplan/50-cloud-init.yaml
And change it to:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: true
optional: true
version: 2
wifis:
wlan0:
dhcp4: true
dhcp6: true
access-points:
"<yourwifiname>":
password: "<yourpassword>"
Save it and test it:
sudo netplan try
If all is ok, you can reboot your Raspberry and it should be connected to wifi.
Once rebooted, log into your RPI using
Username: ubuntu
Password: ubuntu
And change your password.
Now you need Gravio to receive the USB dongle and the sensors. You can send me a message if it's not available in your country, and I can have a look what we can do.
Step 2: Installing Gravio Studio on your PC/Mac and Creating a Gravio AccountGravio Studio (Mac OS app,Windows app) is the desktop app that is needed to configure the platform and put your IoT applications together. To receive the sensors, you also need to subscribe to the sensor rental plan inside those apps.
Please note, the following screenshots are based on macOS but the Windows process is very similar.
Sign up with your details and you will receive an e-mail with a code:
After you have downloaded the application and started it, you will see a registration screen:
Now click on the + sign on the top right to add your Raspberry Edge node:
Now you can start configuring your node and build your applications.
Ordering SensorsIf you like to order sensors, you need a subscription. Please check availability in your country before you order sensors.
The sensors are rented on a monthly basis. You can stop the subscription at any time, in which case you will have to send the sensors back.
Choose your subscription and follow your Operating System’s instructions on how to subscribe:
Once you are subscribed, you can visit https://www.gravio.com and use the login button at the top right to log in and visit the ordering page:
Once ordered, Asteria will ship the sensors and the USB dongle to you, ready to connect.
For more information, have a look at https://doc.gravio.com or join the Gravio Slack Channel
A few days later you will receive the sensors of your choice and the USB dongle. Which allows you to proceed to the next step below.
Step 3: Installing Gravio on your Raspberry Pi 4 and Connecting the SensorsGravio consists of the server (installed on the RPI), called “Gravio HubKit” and the Client (installed on your Mac or Windows machine), called Gravio Studio, which you already have, if you have followed the above instructions. You use Gravio Studio to set up your IoT applications. But one step at a time.
In order to install Gravio on your Raspberry Pi, please log into your device and make sure it’s all up to date:
sudo apt-get install update
sudo apt-get install upgrade
Then download Gravio:
wget https://download.gravio.com/release/raspberry/gravio_arm64.deb
In accordance with this website: https://www.gravio.com/product#Gravio-Server
Once downloaded, you can run the command
sudo apt install./gravio_arm64.deb
To run the installation.
Once Gravio Hubkit is installed, you can connect to it from your Gravio Studio by adding it to the Hub overview:
Once added, double click to enter it and create an area and add the respective layers. Following this example, please create 2 layers:
- A motion detection layer
- A door sensor (magnet) layer
Your Gravio Studio could look similar to this:
Then you can pair the respective sensors, which looks like this: https://www.youtube.com/watch?v=7CDZY77773s&t=99 (Note, this is on Windows, but Mac is very similar.)
On macOS, you can use the button at the top left ot add areas and layers, and the button on the top right to initiate the pairing process:
During the pairing process, press the sensor buttons, or if you have the double button, press both buttons at the same time.
More details about the pairing process can be found on https://www.gravio.com/sensor-setup-guide
Place the motion sensor in a good place, where it can capture motion when somebody is entering the entrance area, and stick the magnet/door sensor to the hand sanitizer so it closes the contact when the hand sanitizer is operated.
You can see in Gravio’s Data Viewer if the data is coming through ok (don’t forget to press the “LIVE” button on the top right to see the data coming in in real-time:
Once you have paired the sensors, we can start working on the actual program to trigger the various actions (i.e. image/animation plays).
We two images:
- An image saying “Welcome, please use the Hand Sanitizer”
- An animated GIF that counts downwards and then tanks the user
We need to ensure that the Google Chromecast device is already connected to the same wireless network as the Raspberry Pi. I assume you have followed your Chromecast’s instruction on how to do that.
Now we need to prepare the Images. For this, we need to know the distortion of the picture, because we are not projecting perpendicularly. At this point it becomes important that the projector is a laser projector, because a laser projector does not go out of focus depending on the distance of the screen. For this demo, we have used this AnyBeam device which can be powered from USB.
Preparing the Perspective ImagesFirst and foremost, we need to understand the degree of the perspective distortion, so we know how we have to skew the image For this, we need to take a picture from the laser’s “viewpoint”. In order to identify the position of the various pixels, I suggest projecting a grid that contains something recognizable inside, such as for example a world map:
This world map can then be compared back on the same picture in distortion including the desired result:
And based on the grid, we can determine the amount of distortion required:
You can distort a photoshop layer in whatever shape or form you like if you hold the “Command” button while dragging the corners.
Then you export the image on a fully black background. The great thing about laser projectors is that for the black colour they will simply omit the light:
This picture projected will look something like this:
Note, depending on the strength of the projector you may need to install the projector closer or further away from the surface.
Because it is a laser projector, the "H" close to the projector as well as the emoji of the hand are in focus. If this were a projector using lenses, it wouldn’t be able to project a focused image across this distance difference.
For the animated GIF image, I suggest you use Adobe Photoshop’s Smart Objects as layers, then you can just change an undistorted image (i.e. the Smart Object) for each frame, and Photoshop will automatically distort it in-place:
You can then use Adobe Photoshop’s Animation feature to export the animation as Animated Gif that does not loop. More details you can find here: https://helpx.adobe.com/hk_en/photoshop/how-to/make-animated-gif.html
Lastly, you will need an all-black image that you can send to the projector to “switch it off”.
Put the images in a folder of your choice on the Raspberry Pi. In this example, we put it in the folder ~/projections/
Installing CATTNext, you need the software that can send the pictures to your Chromecast device. We assume the Raspberry Pi and the Chromecast device are connected to the same network. You can use the open source software called CATT (Cast All The Things) to achieve that. The software is based on Python and quite easy to install:
1. Add ~/.local/bin to your PATH (if it's not already added). Also export the PYTHONPATH as /usr/lib/python3/dist-packages:$PYTHONPATH to avoid having other apps picking up Python modules from ~/.local/lib.
You can do this manually (and source.bashrc /.zshrc) or run the following commands to do all of this:
for Bash:
echo "export PATH=\"\$PATH:\$HOME/.local/bin\"" >> ~/.bashrc
echo "export PYTHONPATH=\"/usr/lib/python3/dist-packages:\$PYTHONPATH\"" >> ~/.bashrc
. ~/.bashrc
for Zsh:
echo "export PATH=\"\$PATH:\$HOME/.local/bin\"" >> ~/.zshrc
echo "export PYTHONPATH=\"/usr/lib/python3/dist-packages:\$PYTHONPATH\"" >> ~/.zshrc
. ~/.zshrc
2. Install Python3 PIP and Python3 Setuptools
In Debian / Ubuntu / Linux Mint, use:
sudo apt install python3-pip python3-setuptools
3. Install CATT using Python3 PIP:
pip3 install --user catt
If you get a permission error when trying to install CATT using this command, you may have previously used PIP to install packages as root. This is not recommended but in such a case, you can force the CATT installation by running the install command above with sudo.
Once installed, you can easily test it by entering the command:
catt cast <filename>
Or
catt cast “<url to youtube video>”
If you have multiple chromecast devices, you may want to consider specifying the output, which you can do as:
catt -d <yourdevicename> cast …
Creating the Shell ScriptIn the next step we create the shell script that we will trigger within Gravio. As you may know with Gravio you can execute any shell script upon trigger (of sensors or other inputs).
The shell script is very simple. It simply contains the command:
catt -d $1 cast $2
$1 is the variable for the device name
$2 is the variable for the content
Create this script on your computer where you run your Gravio Studio and call it
send-to-chromecast.sh
This is all we need in terms of preparations.
Configuring GravioNow that you have your files and the Raspberry prepared, you can create the IoT app in Gravio.
- Open Gravio Studio and log in with your account details
- Log into your Gravio Hub ( = the Raspberry Pi)
- Then add the Actions. You need two actions in total: one to show the “Welcome” slide, and another one for the “Counting Animation”. To add the first action, click on the Actions icon in the top bar:
- Click on the + sign to create a new action. We will start with the “Welcome” screen, that will show if a person walks into the motion detection zone.
- Double-click on the Action, and double click on the Title in the top left to rename it “Show Welcome Slide”.
- Click on the big + sign and pick the RunScript component and click “Add”:
- You will see a screen similar to this:
- Upload your shell script by clicking on the “Upload” button:
- Now, we need to make the shellscript executable on the Raspberry Pi. Therefore log into your Raspberry and execute the command
chmod +x /var/opt/gravio/action/scripts/send-to-chromecast.sh
- Add the necessary arguments to the Arguments field in Gravio Studio. Note, the parameters in the shell script are -d $1 and cast $2. Therefore the first parameter is the device name and the second is the source. Accordingly, the parameter field needs to be:
<mydevice> </path/to/filename/file.gif>
- So if your device is called Chromecast and your file is called welcome.png in the folder /home/ubuntu/projections/, this would be:
Chromecast /home/ubuntu/projections/welcome.png
- At this point, you can test if the action works. Connect the Chromecast and projector to power, wait for a few seconds for it to boot up and press the play button on the top right to see if the image gets sent to the projector. If everything is set up correctly, you should see the picture being projected. If nothing happens, please check the network connection, the Chromecast name and the source location.
- Once that’s done, you create one more Actions so you have two in total:
- Show Welcome Slide - which uses the welcome screen we just created above
- Start Animation - which uses the animated gif and then the black screen a few seconds after the animation stopped
- As a next step, we create the Triggers. For this, open the Triggers tab in Gravio Studio:
- One trigger is to start the Welcome Slide
- One trigger is to start the Welcome Slide
- One trigger is to start the animation
- For more details about the trigger parameters, please consult the documentation under https://doc.gravio.com
- Now we need to edit the “Start Animation” action. We need to add a timer to the length of the actual animation, then add another shell script to replace the end of the animation with the blank “off” screen:
- Press the play button to check if the animation plays and gets replaced by the blank off screen after 15 seconds.
This is it! Ensure that the triggers are switched on in the triggers view, but basically you have now created the automatic projector welcome and hand sanitizer IoT application! Congratulations!
If you have any questions, or if you like more ideas, inspiration or just speak to other Gravio developers, please feel free to join our Slack channel. You can also find Gravio Tutorial Videos on YouTube.
Comments