You are on page 1of 6

YouTube Subscriber counter using a Waveshare 7.

5” E-Ink 3 colour display and a


Raspberry Pi Zero W. www.youtube.com/mikemakesit

This sub-counter is based on the first E-ink counter I ever saw (which I was amazed
by) which was created by Michael Klements. I have altered the code and hopefully
simplified the software install and build as I was new to Pi when I saw the
original project and was a little confused. Hopefully the way I have presented this
project should be straight forward even for builders with little or no knowledge of
Pi. Like I was when I started! A link to Michaels original project is on my youTube
video for this E-ink counter.

I created an LED YouTube subscriber counter based on an AZDelivery ESP8266 Node CPU
board and an Adafruit 0.56" white seven segment I2C display in the past but this
time we will be using a Waveshare 7.5” 3 colour E-ink display and a Raspberry Pi
Zero W.

All this information is based on a Windows 10 machine and I have used Note++ (On
Windows and the Text editor on Pi) throughout. Using anything else, I have found,
can alter the formatting of the document and cause issues. As already stated, I
have assumed you are familiar with Windows and "Pi". I was not and it was a steep
learning curve! But I worked it out. So can you.
Please have a go yourself as I have spent many, many hours getting to where I am
now with this setup, and it works!
Software updates and changes may stop this counter from working however this
information worked fine in October 2021. Hopefully it still does! Let me know if
you have any issues and I'll try and help.

Let's get started!!!

Go to https://www.raspberrypi.org/software/operating-systems/#raspberry-pi-os-32-
bit

This is where you can download the Raspberry Pi software.

Choose "Raspberry Pi OS with desktop" and download the file.

Then go to https://www.raspberrypi.org/software/ and download the imager program to


install operating system to your microSD card. Read and follow the install
instructions.

Fit a USB drive adaptor with your microSD card in it that you want to put your Pi
system on into your Windows machine.

Run the imager program you just installed above. Click “YES” to start the program.
It should pick up on the file you downloaded in the first line of this instruction
sheet.

Click “Choose OS”


Pick the top option (Raspberry Pi OS 32bit)
Then click Second box, “Choose Storage”
Pick your microSD card
Now click “Write”
Click “Yes” to confirm

Now wait until the operation completes and remove the microSD card from the
machine. Ignore Windows prompt to format the card.

Fit the microSD card to your Pi and boot.


Follow instructions on screen to connect the Pi to your Wi-Fi and setup the Pi
normally. Complete any updates you are prompted to do on screen and reboot when
complete.

Now we need to install the necessary libraries etc onto the MicroSD card to get the
counter to run.
Do everything in the order stated and don’t miss out anything or else it will end
badly and you may have to start again.
I did many times until I got it right!

You may like to try and connect the Pi to your Windows system and transfer this
whole text document. It is certainly a more fool-proof way of doing it rather than
typing my hand as you can copy and paste.

This is the software I used for transfer and it really is straight forward, it’s
called Win SCP. You will need to turn on SSH on the Pi but in the link below it is
all explained. You'll also need to turn on "SPI" for the sub counter to work so
when you are doing that you might as well turn on "SSH" at the same time.

As you will enable SSH when you use Win SCP just remember to turn it off when you
have the Sub Counter working. All the information on how to connect you Pi to the
Windows PC is within the link below. That’s how I figured it out!

It was scary for me to start as I knew very little about the Raspberry Pi. After
this project I knew considerably more.

https://behind-the-scenes.net/using-winscp-to-connect-to-a-raspberry-pi/

When you have installed Win SCP hop over to the Pi and open a terminal window and
type:

sudo raspi-config (press enter)

Move to "interface" Hit "Enter" and to "SPI” Enter. Select "Yes" Click "Enter"
Confirm. Click "OK".
Again move to "interface" Hit "Enter" and to "SSH” Enter. Select "Yes" Click
"Enter" Confirm. Click "OK".
Click "Finish". Reboot and then continue with the following in a terminal window as
before.

You should be able to log into the Pi (you may have to set a password and find the
IP address of the Pi, it’s all in the doc's in Win SCP) and transfer this text
document that you are reading!

Now would be a good time to go to my Google drive and copy the whole of the
subCount folder over to the Pi. I would unzip it before you move it to the Pi
though.

Copy it into the /home/pi/ directory so it looks like /home/pi/SubCount

Open the text document (This document) and follow it!

On the Pi:

Open a terminal window and type the following to install the libraries:
**(SEE END OF THIS DOC FOR A FASTER WAY OF INPUTTING THE SOFTWARE)**

Install the BCM2835 libraries:


wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz
tar zxvf bcm2835-1.60.tar.gz
cd bcm2835-1.60/
sudo ./configure
sudo make
sudo make check
sudo make install

Install the WiringPi libraries:

sudo apt-get install wiringpi


wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v

Install the Python2 libraries:

sudo apt-get update


sudo apt-get install python-pip
sudo apt-get install python-pil
sudo apt-get install python-numpy
sudo pip install RPi.GPIO
sudo pip install spidev

Install the Python3 libraries:

sudo apt-get update


sudo apt-get install python3-pip
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo pip3 install RPi.GPIO
sudo pip3 install spidev

**********

API KEYS. Now you need to get Your YouTube API Keys:

In order for the Python script to retrieve your current subscriber count and number
of views, you’ll need to add your Channel ID and your YouTube API key.
Here’s how to generate your API key:

Go to the Google API web page while signed in to your google account associated
with your YouTube channel – https://console.developers.google.com

Go to your Dashboard and the click on “Create Project”, choose a name for your
project and click “Create”.

Next, click on “Enable APIs and Services” and type – YouTube Data API v3 – into the
search box. Enable it and click “Create Credentials”.

On the next page, you should see a link to create an API key in small letters,
click on this link.

Next click “API Restrictions” and select “YouTube Data API v3”.

Click “Create” and you should then be given your API key which you’ll need to copy
into the main Python script below.
You’ll also need to get your Channel ID. You can find this under “Advanced
Settings” for your channel account. Click on your profile picture in the top right,
then go to “Settings”, wait for the page to load and then click on “Advanced
Settings” from the menu on the left.

You can test your API Key and Channel ID by going to the following address in your
browser, replacing YourChannelID and YourAPIKey with the ones you’ve just got:

https://www.googleapis.com/youtube/v3/channels?
part=statistics&id=YourChannelID&key=YourAPIKey

The link above helped considerably as I didn't get my keys first time as it was a
tad confusing. DO NOT go past this point until you have working API and Channel Id
keys as the program will fail!

***********

OK, so far so good. You should have copied my SubCount folder over to the Pi by
now.

In the folder are the files below.

"clear.py" used to clear the display. This is important if you are going to
disconnect the power. Run it before you do so as you end up with a white display.
Waveshare say this is important.

"subCount.py" Starts the counter

"Launcher.sh" Used to get the program running on boot.

I'd suggest (You need to or it won’t work!) you change the "Permissions" on
"Launcher.sh", "subCount.py" and "Clear.py" which are in the
/home/pi/SubCount/SubCount folder. Right click on each of these in turn, select
"Properties" and change all "Permissions" to "Anybody". If you don't crontab might
not work, see later in the text about this!

You will also need to edit the "subCount.py" script where you see @@@@@@@ with your
own channel name and ID with your own. You will also need to replace "Mike Makes
It" with you own channel name otherwise that would be weird!. Use a text editor to
do this. Right click on "subCount.py" and then click on "Text editor" In this
"subCount.py" you can tweak with the settings for exactly where your name is
displayed. For example, if you have a short YouTube name it may be off set to the
left. Tweak the value in the brackets. For example, the 312 and 360 will move my
channel name up/down/left/right depending on the number input ***
(draw_blackImage.text((312, 360), 'Mike Makes It', font = font32, fill = 0) ***

Now if you type "sudo python3 /home/pi/SubCount/SubCount/subCount.py" (in a


terminal window) and press "Enter" the display should flicker a few times before
you are presented with a nice youTube logo and your channel information.
Occasionally the YouTube logo appears black. I just restart the program. This has
only happened when I'm tweaking the software and never when the program is stand
alone and running.

If this works try the "clear" program below. This will put the display into a safe
storage state.

Type "sudo python3 /home/pi/SubCount/SubCount/clear.py" (in a terminal window) and


press "Enter". This should blank your display after a few flickers and a few
seconds.It's now safe to remove power and this is the state the display should be
left in unless you are actively refreshing the display, for example you are running
the counter!!

If the screen clears, well done, you've copied the information correctly.

Please note, the faster the Pi, the faster the display will respond. With a zero it
is a tad slow but when running for real this is not important, at least not to me!

To get the program to run automatically and stand-alone follow the instructions
below.

I edited crontab (A program that runs on boot) so as when the Pi is turned on the
program will run automatically. My Pi Zero is a stand-alone unit only used for the
Sub Counter.

It is also very important that the E-ink display is refreshed at least once a day
according to Waveshare. I set the unit to boot into the Sub Counter program on
power-up/power-restore (after a power interruption) and to reboot 3 times in a
24hour period which is more than the minimum recommendation. As I'm a bit paranoid
I've also added a time and date display in the lower right-hand corner of the
display so you can check to make sure the display hasn't frozen! This will display
the time and date the system restarted. It should show less than 6 hours from the
actual time you are looking at it! If it’s more than this then the Pi has frozen
and you need to sort it out ASAP.

Copy and paste these lines one by one into a terminal window.

crontab -e

If this is the first time you have edited crontab you will be presented with 3
options, I always choose 1, the nano editor. Press 1 and press "enter" and scroll
to the bottom of the text displayed and type the following:

@reboot sleep 30 && /home/pi/SubCount/SubCount/launcher.sh


0 01 * * * /home/pi/SubCount/SubCount/launcher.sh
0 09 * * * /home/pi/SubCount/SubCount/launcher.sh
0 17 * * * /home/pi/SubCount/SubCount/launcher.sh

press ctrl + x
press "y" key
Press "Enter" key
close terminal window

If all is well, on reboot the E-ink display should, after a couple of minutes
display your youTube statistics. Try it! Reboot!!!

********

Below are the files that you may have typed in above, I’ve just condensed it down
here. You don’t need to do it again!

If you want to speed up the install of the software above just copy and paste this
block into the terminal window at the point above. Make sure you click enter so as
the last line is installed. When you have done this go back up the page and
continue with the API creation.

sudo apt-get install wiringpi


wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install python-pil
sudo apt-get install python-numpy
sudo pip install RPi.GPIO
sudo pip install spidev
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo pip3 install RPi.GPIO
sudo pip3 install spidev. (Click the “enter” key when it gets to this point to
finish)

Now go back up the page to where you need to get your API keys!

You might also like