Introduction: Raspberry Pi Slack Scroll Bot!
This project combines a Raspberry Pi with a Pimoroni Scroll Bot kit (modified with buttons), Slack, and IFTT for visual and audible notifications when youtube videos are posted to a subscription!
The button modifications to the kit are optional, as well as the speaker to announce the arrival of a new video.
You can also use this to send any message to the bot through slack by prepending "bot" the front of the message, such as "bot hello world". "bot clear" will clear the screen.
Step 1: Scroll Bot Assembly
Complete the instructions for assembling the Pimoroni Scroll Bot:
Step 2: Install Packages and Codebase
Install Audio Packages:
sudo apt-get update & sudo apt-get upgrade -y sudo apt-get install mpg123
Install python packages:
pip install flask pip install psutil pip install slackclient
Follow the tutorial at Pimoroni's for Getting Started with Scroll Hat:
https://learn.pimoroni.com/tutorial/sandyj/getting...
which includes downloading the sample source code and resources:
curl https://get.pimoroni.com/scrollphathd | bash
Since the screen is mounted upside down in the robot kit, you need to uncomment code to rotate the screen 180:
$ sed -i 's/#scrollphathd.rotate(degrees=180)/scrollphathd.rotate(degrees=180)/g' /home/pi/Pimoroni/scrollphathd/examples/web-api.py
Step 3: Configuring Slack Instance
For the script to communicate with Slack, you'll need a bot API Key.
Start by logging into your Slack team webpage (https://my.slack.com/services/new/bot) and chose a username for your bot, then copy the API token provided.
Step 4: Create a Slack Channel, and Invite Your Robot to the Channel.
You can use the general slack channel, or if you prefer you can create a separate slack channel.
In my case I used #robot-claire-control
You must invite your robot into the channel, or it won't see the messages that are sent.
Step 5: Download SlackPiBot Source Code & Configure
Download the slackPiBot sourcecode from git:
<p>git clone https://github.com/mhajda/slackPiBot.git</p>
Update line 29 with your API Key:
<p>slack_client = SlackClient("xoxb-YOUR-API-KEY-HERE")</p>
Update line 34 with your robot name:
<p>if user.get('name') == "robot-claire":</p>
Step 6: Configure Crontabs to Start Automatically on Boot:
Setting up crontabs to start automatically on boot:
<p>crontab -e</p>
Add the following to the bottom of your crontab:
<p>@reboot python /home/pi/Pimoroni/scrollphathd/examples/web-api.py<br>@reboot python /home/pi/slackPiBot/check_button.py @reboot python /home/pi/slackPiBot/forever.py /home/pi/slackPiBot/slackPiBot.py >> /home/pi/slackPiBot/outputLog.txt 2>&1</p>
Step 7: Optional: Add a USB Speaker Output
For this project, I am using a USB speakerphone from US Robotics - available on amazon or ebay.
If using something similar, you will need to change the default system sound device by editing the alsa config (/usr/share/alsa/alsa.conf). Change the following lines:
<p>defaults.ctl.card 1<br>defaults.pcm.card 1</p>
1 being the index of your device. To find the device ID of your USB device, run aplay -l and look for the card ID.
Step 8: Optional: Add Wired Buttons to Robot to Clear Messages
This step is optional but highly recommended to clear messages on the screen.
I have added two push buttons to my robot, but in this project I'm only using GPIO17.
The script check_button.py that runs on boot polls the GPIO17 every few milliseconds and if depressed sends an HTTP POST to the sample screen script to clear the screen.
Step 9: Pulling It All Together and Sending Output to the Pi
There are 4 scripts that work together for this project:
<p>/home/pi/Pimoroni/scrollphathd/examples/web-api.py<br>/home/pi/slackPiBot/check_button.py<br>/home/pi/slackPiBot/forever.py /home/pi/slackPiBot/slackPiBot.py</p>
The web-api script is provided by Pimoroni and is a simple web application to control the screen with POST commands.
The check_button python script polls the GPIO pins and when the button is depressed sends an HTTP POST to the web-api.py script.
The forever.py script kicks off the slackPiBot.py script to ensure that if there are any uncaught errors or disconnects from slack, the script is restarted to avoid missing any messages.
The slackPiBot.py script connects to slack and monitors the channel for messages starting with "bot" or posts from IFTT. If there's a match, it will send an HTTP POST to the web-api.py script and display on the screen.
Step 10: Optional: IFTT Integration
This project was designed to alert my kids of videos posted by people they follow on youtube, since they are too young to have their own iPhone or iPads. I accomplished this by creating IFTT recipes that send a notification to the slack control channel once a video has been posted.
The instructables wiki makes this complicated to see in one step, but the screenshots above show the end result.