Introduction: Skateboard Odometer

About: student NMCT at Howest (Kortrijk Belgium)

My project consists of an odometer that can be placed on a skateboard/longboard.

On the skateboard there is also an LCD mounted where you can see the distance traveled and the speed.

All information displayed on the LCD screen is also visualized in a browser.

But before all the data is visualized in a browser, the data is sent to a database and from the database to the website.

Step 1: How It Works

Basically the odometer consists of a hall sensor mounted on the trucks of the skateboard and a magnet mounted on one of the wheels. As the wheel rotates the magnet triggers the sensor every rotation.

The signal goes to the raspberry pi, which counts the number of rotations and finds the distance covered (you have to enter the circumference of your wheel in the programming code).

The raspberry pi also calculates the speed. The output from the raspberry pi then goes to the LCD.

Step 2: Materials Needed

The full project would cost you about 100€ . The project also requires soldering skills.

The materials:

1. Raspberry Pi 3

2. 16x2 LCD

3. Hall Sensor

4. 10k ohm resistor

5. T- Cobbler

6. T-cobbler cable to connect the T-cobbler with the Raspberry Pi

7. B10k potentiometer to adjust the contrast of the LCD

8. Perf board (you could also use a breadboard if you don't want to solder)

9. Solder

10. Soldering iron

11. Magnet

12. Powerbank to give power to the Raspberry pi while you are riding your skateboard

Step 3: Modify the Board

When you find a skateboard that you want to modify into an odometer, what you need to do first is to measure how big your LCD display is, when you do that you need to cut a piece out of the skateboard so that you can put the LCD through. When all that is done, you need to drill a small hole in a wheel so you can place the magnet in there, but you also need to glue it in there so it stays in place.

After you've done all that you can put a small piece of plexiglass on the skateboard where the LCD is going to be put to protect it from the rain or any other sort of liquid.

Step 4: Setting Up the PI

Before we get started, we must make sure all updates and upgrades are installed.

Enter the following command in the

sudo apt-get update && sudo apt-get upgrade


We also need to install APScheduler on the Raspberry PI, with APScheduler you can run scripts on the background or save data at X time.

You can install it with the following command:

sudo pip install apscheduler


Adding a wireless connection

Open the wpa-supplicant file in nano:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

network={

ssid= "SSID_FROM_YOUR_NETWORK"

psk="YOUR_WIFI_NETWORK"

}

adding a static ip address

open the dhcpcd file:

sudo nano/etc/dhcpcd.confinterface 

wlan0static ip_address=192.168.0.100/24



Step 5: Setting Up Flask

Set Deployment Environment

In Pycharm, go to the default settings and choose Build → Execution → Deployment for Deployment

Please make sure that you enter the correct data. The SFTP host is your Raspberry network address.
If you have made an extra user (not pi - raspberry), you can fill it in with User Name. Then press Test SFTP connection. If the connection is successful you can continue. Also click on the Auto Detector button below the Test SFTP button. Then click OK at the bottom. Also close the following window by pressing OK.

After that, PyCharm will connect with the external device and some "Pycharm helpers " will be uploaded to the raspberry.

By creating a deployment environment, PyCharm will know our external device and communicate with it.

Set Project interpreter

In PyCharm, press Ctrl + Shift + A and type "Project Interpreter" and press enter.

In the window that opens, click on the top right and select add remote.

In the window that opens, click on Create copy of this deployment server in IDE settings.

At the Python interpreter path, choose the folder in which python3 is installed.
Usually it is / usr / bin / python3.

If you do not adjust this, you will hang on to a python2 interpreter. After that, click OK a few times until you're out of the settings again. Now you can upload your project to the raspberry pi.

Step 6: Setting Up MySQL

First, we need to install the MySQL server.

<em> sudo apt-get install mysql-server</em>

In order to connect with the database, we also need a client.

Install the Mysql client with the following instruction:

<em>sudo apt-get install mysql-client </em>

During installation, a password will be prompted to log in as "root" user. This one "Root" user will have complete control over the database.

Connect with the database via the default root user.

<em>mysql -uroot -p </em>

Add MySQL user:

CREATE USER 'km'@'localhost'IDENTIFIED BY 'some_pass'; 
GRANT ALL PRIVILEGES ON *.* TO 'km'@'localhost' WITH GRANT OPTION; 

Creating a database:

CREATE DATABASE KMDatabase; 

Exiting MySQL connection:

quit 

Installation MySQL connector:

Now we need to make Python connection with the MySQL database.

For that purpose we need a MySQL connector.

<em>sudo apt-get install python3-mysql.connector</em>


Create table in Pycharm:

Add as a Data Source a MySQL database

To add a database from the Raspberry Pi, you will need the following settings:

At the General tab:

Host: localhost

Database: ''name of your database"

User:''name of the user that you made"

Password: ''your pass"

At the SSH/SSL tab:

Proxy host: the IP address of your pi

Proxy user: the username of thee pi

Proxy password: your pass

Add tables:

To add a table you need to right click on your schema → new → table.

Step 7: Electronics

A Hall effect sensor is a transducer that varies its output voltage in response to a magnetic field. Hall effect sensors are used for proximity switching, positioning, speed detection, and current sensing applications.

As you can see in the picture you need to connect the left pin to the 5V, the middle pin to the GND and the right pin to a GPIO pin of your choice.

You also need to use a 10k ohm resistor between the 5V pin and the GPIO pin.

The LCD in this project is used to display the distance and speed.

To wire the LCD you need 12 jumper wires. The first pin goes to the GND and the second pin goes to the 5V.

The third pin goes to the middle pin of the potentiometer to adjust the contrast.

The pins RS, RW, E, D4, D5, D6 and D7 go to GPIO pins of your choice.

The anode goes to the 5V and the cathode goes to the GND.

The potentiometer is used to adjust the contrast of the LCD.

The left pin goes to the 5V, the middle pin goes to the third pin of the LCD and the third pin goes to the GND.

Step 8: The Housing

For the housing you can use anything you want as long as everything stays in place and it isn't too heavy.

I used a small plastic box and made sure that everything fits in. Afterwards you need to drill a small hole on one side so that the cables from the perfboard can go outside to the LCD. For the LCD you also need a small plastic box to protect it from the rain or any other liquid.

Then you can place the perfboard in the box, but because it wouldn't stay there without any support, I used a small sponge and glued it on the box, I also glued the other side so that the perfboard stays there.

After that I placed the powerbank on the side with double sided tape with a sponge glued around it so it doesn't fall off.

I also used a small piece of metal that pushes the one side of the box against the powerbank, so now I can press the power on button without a problem.

Then you need to put the cables through the hole and put a shrink sleeve around them so they all stay together so you don't have loose cables laying around and now you are also sure that a cable doesn't get stuck on something while you are riding. Then solder those cables on the LCD.

After the soldering is done, you can place the small plastic box over the LCD and silicone the edges so it stays there. I used some nails too just in case.

Step 9: The Code

For the code you need to make sure that everything is in the same folder.

You can get the code from Github.

The code