Smart Ball With Storage Box
by ArnaudDeBrabant in Circuits > Raspberry Pi
224 Views, 3 Favorites, 0 Comments
Smart Ball With Storage Box
As a student of Multimedia & Communication technology in Howest Kortrijk, I had to make my own project. This would combine all of the modules followed in the second semester of the first year into one project. I chose to make a smart football with matching storage box because I used to play a lot outside with my football.
When I was playing football at home I would often juggle in the garden and when you are juggling you need to be able to focus well. When you have to keep count yourself after a while it becomes very difficult with the result that you lose count or you drop the ball. The idea is that the ball itself can keep track of how many times it is juggled using a shock sensor. The responsive web app allows you to see how many times you have juggled without having to keep count yourself.
The features of the SmartBall:
- count how many times the ball is juggled
- measure the acceleration of the ball when being shot
- keeping track of the scores and displaying them in a scoreboard
The features of the storage box:
- a login system so that multiple players can play
Supplies
computing units:
Raspberry Pi:
- the main controller of the system
ESP32:
- the microcontroller inside the ball
- connected with raspberry pi via Bluetooth
Electronics:
- Breadboard with jumper wires (optional)
- set of resistors
- GPIO extension Board
Sensors and modules:
- KY-002 Shock Sensor Module
- 3 Axes Gyro Accelerometer MPU6050
- RFID RC522
- Liquid-crystal display (LCD)
- Servo motor
- Potentiometer
Tools:
- electric knife
- screwdriver
- drill
- saw
- soldering iron
- file
Materials:
- Foam Ball
- 11 MDF boards
- Velcro
- plug box
- 2 shell handles
Downloads
Prototype
Here you can see the circuit of this project, before I made this circuit physically I worked it out in Fritzing
Database
1. Devices
This table contains every sensor. It describes the sensor name, description and measuring unit.
2. History
This table contains the history of every action coming from a device. It contains the actionID and the date of the action it also has the deviceID.
3. Actions
This table contains action and gives it its own ID and description.
4. User
This table contains every user logged in with the RFID sensor. It has the name of the user and the Tag of the RFID badge.
5. Score
This table contains the scores from all users.
6. accelleration
This table contains the x/y/z -values of the accelerometer.
You can find the dump file on my GitHub.
Cut the Planks
What you need for this project are 11 MDF boards:
- 4 boards 13cm x 30cm
- 4 boards 10cm x 30cm
- 2 boards 31,6cm x 31,6cm
- 1 board 28,5cm x 28,5cm
these dimensions depend on the thickness of your plates
Glue the Planks Together
Glue each of the 4 boards to a 30 by 30 board so that you have 2 halves. This provides extra strength to the box and makes drilling easier. I chose not to use screws, it worked just as well with the mounting glue.
Saw the Planks
- Saw out a hole through which your ball does not fit.
- Do the same for your LCD-screen and RFID
- Saw out a hole where your cables can go through
- Don't forget to saw 2 holes in the intermediate shelf for the chains to pass through, these will be discussed later.
Drill the Holes in the Planks
- Drill 2 holes for the RFID, only the upper holes are drilled as a part of the RFID will come out.
- Drill 4 holes for the LCD so that it is firmly attached
- Drill 4 holes, 2 parallel on each side, to which the chains will then be attached, each 20 centimetres long
- Drill 6 holes for the hinges at the back
- Drill 2 holes to place the power off button from the raspberry pi
The Foam Ball
- cut out a compartment from the Foam ball in which your power bank fits
- cut a pocket from the other side of the Foam ball to fit your ESP32, accelerometer and shock sensor
- You can also cut out a few lines to hide the wires
Configuration of Raspberry Pi
Enable I2C and SPI on the Raspberry Pi with:
sudo raspi-config
Interface Options --> enable (I2C & SPI). --> Localisation Options --> change timezone and WLAN Country.
reboot the Pi:
sudo reboot
Add WiFi.
Adding your own home wifi.
sudo wpa_passphrase 'Networkname' 'Password' >> /etc/wpa_supplicant wpa_supplicant.conf
Reload your wireless network card in the PI.
wpa_cli -i wlan0 reconfigure
You can now check the connection by requesting the ip-address (wlan0).
ifconfig
Installing the needed packages.
sudo apt updatesudo apt upgradesudo pip install flask-corssudo pip install flask-socketiosudo pip install simple-websocketsudo pip install mysql-connector-pythonsudo pip install geventsudo pip install gevent-websocketsudo pip install seleniumsudo apt install chromium-chromedriversudo pip3 install rpi_ws281x adafruit-circuitpython-neopixelsudo python3 -m pip install --force-reinstall adafruit-blinkasudo apt install python3-dev python3-pipsudo pip3 install mfrc522
reboot the Pi.
sudo reboot
Backend
In the backend you make the connection with the frontend, I used routes, socket.io and threading.
Socket.io is used to transmit live data to the webpage
threading is used to start multiple task at the same time
Go to config.py. You have to set your Database credentials (user, password and database).
This takes care of the connection with your database.
Automatic Start-up of Backend
If you haven't already, head over to my GitHub and clone/download the repository. Under the folder Backend you will find the full backend for the project.
Create a file called myproject.service
Place the following code in the file:
[Unit]Description=ProjectOne ProjectAfter=network.target[Service]ExecStart=/usr/bin/python3 -u /home/student/<naam_van_je_repo>/backend/app.pyWorkingDirectory=/home/student/<naam_van_je_repo>/backendStandardOutput=inheritStandardError=inheritRestart=alwaysUser=student[Install]WantedBy=multi-user.target
Copy this file as root user to /etc/systemd/system with the command
sudo cp myproject.service /etc/systemd/system/myproject.service
Now you can test the file by starting it:
sudo systemctl start myproject.service
The file can be stopped by entering the command:
sudo systemctl stop myproject.service
If all works well you can start the script automatically after booting:
sudosystemctl enable myproject.service
The logs / console output can be seen via
journalctl -u myproject.service
Bluetooth Connection Between ESP32 and RPI
This is to test the bluetooth connection
set up bluetooth server
code Arduino (ESP32):
#include "BluetoothSerial.h"#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it#endifBluetoothSerial SerialBT;void setup() {Serial.begin(115200);SerialBT.begin("ESP32test"); //Bluetooth device nameSerial.println("The device started, now you can pair it with bluetooth!");}void loop() {if (Serial.available()) {SerialBT.write(Serial.read());}if (SerialBT.available()) {Serial.write(SerialBT.read());}delay(20);}
Raspberry Pi : Set up client :
https://bluedot.readthedocs.io/en/latest/
sudo pip3 install bluedot
RPI Code :
from bluedot.btcomm import BluetoothClientfrom signal import pausedef data_received(data):print(data)c = BluetoothClient("ESP32test", data_received)c.send("sensor data 1")pause()
You can also use an app to start serial communication / bluetooth.
With the "Serial Bluetooth Terminal" App you can connect, and exchange characters (text)
https://randomnerdtutorials.com/esp32-bluetooth-classic-arduino-ide/
attached you will find the full arduino code to read out the shock sensor and accellerometer to the raspberry pi