This instructable will show you how to build a Raspberry Pi-based tracker for the shared coffee machine in your office space. Using the tracker's OLED display and mechanical switches, the users can log their coffee consumption, see their balance and register their payments.
Your system will be able to
After getting all of the components listed in the previous section, you are ready to assemble your hardware. In this step, you are going to do some soldering.
And, you are done with the hardware!
In this step, you will set up your Raspberry Pi. We will follow a headless setup, meaning you will not need a monitor/keyboard/mouse setup for the Rasberry Pi.
At this point, you should be able to SSH into your Raspberry Pi. However, you will need to figure out the IP address of your Raspberry Pi, which you can find using your router's web interface.
If you are done with the SSH connection, you are ready to set up the software for the tracker!
Before installing the software, you need to create your Google Spreadsheet and get your API key. You can use this spreadsheet as an example to form yours. If you follow this tutorial, you can generate your API key in less than 5 minutes. After the last tutorial, you should have downloaded a JSON file. You need to rename that JSON file to 'secret.json' in order for it to work with the provided software.
You will need to transfer the folder to your Raspberry Pi. You can do that using Cyberduck with SSH File Transfer Protocol (SFTP). Transfer the folder to your Raspberry Pi's home directory.
The tracking software uses Python 3. You don't need to install it manually since the Raspberry Pi image comes with a pre-installed Python 3, but please remember to use python3 command instead of python.
Before running the software you need to install the dependencies using the commands below.
pip3 install gspread oauth2client
The tracking software also requires Adafruit OLED Libraries. You can install them by following this tutorial.
As the last step of your setup procedure, you need to edit the the gdrive_controller.py in the code_tracker folder. Open the file and go to the line 13, as the comment on line 12 states, you need to change the spreadsheet name to the one you created for your application.
Now, you are all set to give it a try!
Navigate to the coffee_tracker folder and run the command below to start the tracker.
cd ~/cofee_tracker
python3 main.py
If you want to start you main.py each time your Raspberry Pi boots up, please follow these instructions.
Congrats! You survived the previous step! Now, you can try and use your tracker.
The tracker starts with a screen displaying "Init..." followed by your IP address for debugging purposes. The tracker constantly checks its WiFi connection and if it loses connection, displays a "No Wi-Fi" message.
If your WiFi connection is stable, the tracker displays an animated screen as shown in the beginning of this instructable until the center button is pressed.
Pressing the center button gathers the user information from Google Sheets and makes the display show the user names. You can navigate between users using the left and right buttons. If you press the center button, you will be navigated for a user specific menu. If you don't take any action in 10 seconds the display will start to show the animation again.
In the user specific menu you can log your coffee, register your payment, see your balance. You can navigate through those options using left and right buttons. If you want to go back to the user list navigate to the go back icon and press the center button.
If you read this far, thanks for doing that! So far the functionality is limited but you can improve the tracker with a leaderboard! If you want to do a hardware improvement a laser cut case would be a good one.
Feel free to message me if you have any issues, questions or suggestions!