fbpx

Raspberry PI + PowerShell Social Media Like Counter

A few months back I was looking at social media follower and like counters to display on my desk. There are a few options out there but I had a Raspberry PI and and old display module handy so thought id try making my own!

A while back I found out how to run PowerShell on a standard PI image and experimented with the PowerShell IoT module. I’m loving this combination because I’m doing a lot in PowerShell at the moment so I didnt have to mix languages between projects.

Below is a copy of my GitHub entry so feel free to download the code from there and build one yourself! If you do please send me a picture of it 😀

https://github.com/slashadminsource/SocialCounter

Use the following guide to setup Visual Code and install PowerShell to the Raspberry PI: https://www.slashadmin.co.uk/how-to-develop-powershell-scripts-for-the-raspberry-pi/

alt text
alt text
alt text

PARTS

SETUP STEPS

  • Hookup five buttons and the display module.
  • Install PowerShell to the Raspberry PI following the guide above.
  • Place the socialcounter.ps1 and settings.cfg files to a location in your scripts folder.
  • Setup the script to run automatically.

HOOKUP PARTS

Buttons

  • Button 1 = Back = Connect to pin 37
  • Button 2 = Up = Connect to pin 35
  • Button 3 = Down = Connect to pin 33
  • Button 4 = Select = Connect to pin 38
  • Button 5 = Exit = Connect to pin 36

Display Module

  • VCC = Connect to pin 17
  • GND = Connect to pin 25
  • DOUT = Connect to pin 19
  • LOAD = Connect to pin 24
  • CLK = Connect to pin 23

SETUP THE SCRIPT TO AUTORUN

Open up the rc.local file under the /etc folder.
Add the following line before the exit 0 command and update it to point to your script location:

sudo /usr/bin/pwsh -File /home/pi/scripts/SocialCounter.ps1

Here is what mine looks like:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

sudo /usr/bin/pwsh -File /home/pi/scripts/DisplayDemo4.ps1

exit 0

Once you save the file and reboot the Raspberry PI should boot up and run the script automatically.

Author: Ian@SlashAdmin

Share This Post On
468 ad

Submit a Comment

Your email address will not be published. Required fields are marked *