Building a product from scratch can be daunting. The idea of creating something that will enhance the lives of others is both inspirational and terrifying at once, with no clear path to follow. I found this experience refreshing because it was my first time building an app like this in every aspect: design up to the front-end presentation for users! In today's blog post, I'll outline how you too could make your own version of my smart pet bowl project using some resources readily available online!
Project Overview
So, what exactly is the smart bowl?
The smart bowl is a device inspired by my own two dogs, it tracks the dogs eating habits as well as when you fill up the bowl to provide comprehensive data about when your dogs eat and how much your dog eats.
Outline
The general technical outline to the smart bowl includes four primary modules: (1) the physical device, (2) the worker and driver, (3) API/ REST interface, (4) the front-end web interface. See below for a high-level architecture diagram:
The physical device consists of a Raspberry Pi 4, HX711, 5kg load cell, breadboards, jumper wire, two wood planks, nuts, bolts, screws, a thick plastic box, and a steel bracket. The steel bracket, nuts, bolts, screws, wood planks, and plastic boxes were used to create the actual body of the smart bowl.
The HX711 microcontroller converts the analog stress signal (weight) from the load cell into a stream of bytes which the Pi receives on pins 5 and 6. The second portion of this project takes the reading from the HX711 microcontroller and creates something readable to use for the API in the third portion. For this portion, I used HX711 driver code provided by Tatobari to read in data from the load cell into the Pi. With this read-in data I created a worker.py file which calibrates, scales, interprets, and records data to achieve this I used Scipy and MatPlotLib. The now interpretable data is then ready to be sent off to my SQLite database.
The SQLite database along with the Flask app make up the third portion of the project, which creates a simple REST API to serve the web client. For this, I used Flask, SQLAlchemy, Marshmallow, and CORS to create a basic Flask application. The Flask app I wrote then creates classes to share with the SQLAlchemy ORM which is turned into JSON by Marshmellow and is ultimately exposed as an event endpoint API for my frontend web interface to get data from.
The front-end web interface is created using React along with Chakra UI and Plotly to provide the user something friendly and easily interpretable to look at.
Conclusion
In short, this was an exciting project and it certainly allowed me to explore areas that I had not before. Now you have the roadmap on how to build a smart bowl. Try to build your own and make sure to tag me in the results on Instagram (@simkbhamra)! Before you get started, leave a comment and let me know what you think and feel free to reach out with any questions.
Happy building.
Open Source Tools and Libraries Used
HX711 driver code: https://github.com/tatobari/hx711py
Numpy: https://numpy.org/
MatPlotLib:https://matplotlib.org/
Scipy:https://www.scipy.org/
Flask: https://flask.palletsprojects.com/en/2.0.x/
SQLAlchemy: https://www.sqlalchemy.org/
Marshmallow: https://marshmallow.readthedocs.io/en/stable/
React: https://reactjs.org/
Chakra UI: https://chakra-ui.com/
Plotly JS: https://plotly.com/javascript/]]>This project uses Retro Pie, which acts like an Emulationstation and also builds on Raspbian, RetroArch, and other technologies and programs, like KODI (which is how you can stream your favorite shows and songs).
Plus, Retro Pie supports many retro gaming systems for Raspberry Pi, such as favorite like Nintendo 64 (N64), Play Station, Game Boy Advance, and Atari Lynx.
Although you can use older versions of Raspberry Pi to build a retro gaming console, we definitely recommend the Raspberry Pi 4 Model B Basic Starter Kit. Not only does this latest version of Raspberry Pi have higher processing speed and improved performance, the kit comes with multiple components you’ll need to create your new console system:
Here are the additional components you’ll need:
Here’s your step-by-step instructions for getting Retro Pie hooked up with your Raspberry Pi 4:
Raspbian Buster Desktop Image Flashed to Your SD Card
First go here to download a Raspbian Buster Desktop Image to your computer. (if you don’t have it, you’ll also need Etcher so you can flash the Raspbian image to your SD card).
Note: make sure your SD card is inserted in your computer when flashing the image. Once it’s done, you can transfer the card to your Raspberry Pi 4
Connect to the Internet
Next, you’ll need to be online via either ethernet or WiFi so you can setup Raspbian on your Raspberry Pi (just follow the instructions).
Download Retro Pie
Launch a terminal window in the top-left corner of your Raspberry Pi 4 screen. To download the Retro Pie setup files, key in:
git clone –-branch fkms_rpi4 -–depth=1 –-single-branch https://github.com/RetroPie/RetroPie-Setup.git
Set Up Directory
In order to enter the setup directory, use:
cd RetroPie-Setup
FKMS from Github
Next, you’ll need the FKMS version of Retro Pie that goes with Raspberry 4, which you can get from Github. Key in:
git fetch && git checkout fkms_rpi4
Execute Setup Script
For the setup script execution, key in:
cd RetroPie-Setup
Perform Basic Install
With the setup script executed, you should get a screen that allows you to “Perform a Basic Install” as the first option.
Start Emulationstation
With installation complete, you’re ready to exit the setup and start Emulationstation. Just key in:
emulationstation
Play!
Now you’re ready to use Retro Pie with your Raspberry Pi 4.
Here’s a video showing just some of the retro games you can now try!
If you’ve enjoyed this project, come back and check out more projects for Raspberry Pi 4 (and more!) on our Vilros Projects blog.
]]>In this activity, we are going to build a two player Ping Pong like game using Scratch on the Raspberry Pi. There will be two paddles and a ball.
The paddles will be user controlled to try to hit the ball back the other direction to the other player.
To begin, open Scratch and delete the Cat sprite on the right hand side.
To create the backdrop, click the “Stage” section in the bottom right hand portion of the window.
Then, in the main window, click the Backgrounds tab.
Then, click the edit button, and choose your background of choice. I chose the brick wall background.
Next, we're going to create the paddles. In the bottom right hand window, click the "Paint New Sprite" button beside the text "New Sprite."
Choose the line tool and draw a vertical line in the middle of the grid then click OK.
Then, rename the line to Paddle1 at the top of the main window.
Next, under the scripts tab, drop each instruction below into the window. These instructions are found by clicking the buttons in the upper left portion of the window that have the color corresponding to the color of the instruction.
For instance, the “When <FLAG> clicked” button is under the “Control” button because it has an orange bar on the left hand side of it.
Fill in the values as seen and select the buttons to move the paddle up and down. I used “W” and “S” for player 1.
Next, right click on paddle1 in the lower right window and select duplicate. Name the new sprite paddle2.
This will create the paddle for player 2. Change the values in script as seen below. I used the up arrow and down arrow to move the paddle for player 2.
Next, we're going to create our variables for the score. Click the Variables button in the upper left windows.
Then, click the “Make a variable” button and name it Score1. Leave “For all Sprites” selected.
Repeat this and create another variable named Score2.
In the bottom right window, click the "Choose a new sprite from file" button to import a ball sprite. I chose a beach ball, but you can choose any ball you'd like.
Next, insert the script parts seen below. Take your time and make sure you get everything!
]]>
The following hardware is used in this article:
The steps are described below.
The easiest way to install Raspbian is to download the New Out of Box Software (NOOBS) from the Raspberry PI download page.
After downloading NOOBS to your computers hard-drive you must extract or unzip all of the contents from the zipped NOOBS file folder and copy copy and paste ALL of the files and folders on to your SD card. See image below:
Plug the HDMI monitor, keyboard, mouse and SD card into the Raspberry PI board. Switch the monitor power on and connect the power supply to the Raspberry PI last.
The Raspberry PI will boot from the installed SD card and allow you to install the operating system of your choice – Highlight Raspbian and install.
NOOBS allows you to select your language and keyboard after booting from the SD card for the first time and before and during software installation.
After installation, the Raspberry PI will boot up into the Raspbian operating system and automatically run a configuration program that allows you to change some system settings.
If you need to change your language and keyboard settings in the configuration program, you will find them under Internationalization Options.
Change your language under Internationalization Options → Change Locale
Change your keyboard settings under Internationalization Options → Change Keyboard Layout
In the configuration program, select Internationalization Options and then Change Timezone.
Select the geographic area that you are located in and then the city or region in that area that best represents the time zone you will need.
The graphical user desktop environment (similar to a Windows 7 desktop) can be started from the command prompt after logging into Raspbian. Enter the following at the command prompt to start the graphical desktop: startx
You can also automatically boot into the graphical desktop by choosing Enable Boot to Desktop/Scratch in the configuration program (this is the most popular option).
There will usually be a black border around the contents of the screen. The border will most easily be seen when running the graphical desktop. Open up the Terminal window and type sudo rasp-config and adjust the overscan settings.
It is best not to use WiFi for this. Connect the Raspberry PI to the Internet through an Ethernet cable. At the command prompt enter the following command:
sudo apt-get update
Now enter:
sudo apt-get upgrade
You can enter this command from a terminal window when running the graphical desktop.
Now for something fun. The Raspberry PI is capable of playing 1080p HD video which, for this article we will do from the command prompt. A video can be played from the command prompt using the application omxplayer and is run by entering the following at the command prompt:
omxplayer <video name>
Where <video name> is the name of the video to play that must be in the current directory (or folder).
To automatically run a command line application after switching on the Raspberry PI, first configure the PI to login automatically. Modify the .bashrc file in your home directory/folder (default home directory is /home/pi).
The .bashrc file is a hidden file. In the file manager on the graphical desktop, make the hidden files visible by pressing:
Ctrl + H
You will now be able to see the .bashrc file and open and edit it.
Add a line to the bottom of the file that contains the application that you want to run as you would run it from the command line.
The video below shows how to automatically run a video after switching the Raspberry PI on.
After all the time you spent editing and tweaking your Raspberry Pi interface, it is probably a good idea to make a full copy of your SD card to save the settings.
The idea behind copying or cloning an SD card (using Linux or Windows) is to make an image file of the SD card on your computer’s hard drive. The image file of the SD card can then be used to make an exact copy of the original SD card onto as many new SD cards as you want.
]]>