Building a Motorcycle Dashboard with Raspberry Pi

Building a Motorcycle Dashboard with Raspberry Pi

MAKER: Alexander Everaert / Translated by: Quwujin

This is a project about motorcycle IoT (Internet of Things). As a motorcycle enthusiast, I decided to use my expertise to create a smart motorcycle dashboard with Raspberry Pi. It can better analyze various data during riding and improve my riding skills. Doesn’t it look very cool!

Features of the dashboard:

  • View current riding tilt.

  • View current riding acceleration.

  • Monitor oil temperature.

  • Automatically switch to dark mode when riding in dark environments.

  • Record riding data and view personal statistics.

Materials List

Raspberry Pi × 1, 12V-5V USB charger × 1, 12V relay with 14 pins × 1, breadboard with jumper wires (optional) × 1, resistor set × 1, 10.2mm wire × several, Breakout Pi plus × 1 (prototype board mounted on top of Raspberry Pi), DS18B20 1-Wire waterproof temperature sensor × 1, oil temperature sensor × 1, three-axis gyroscope accelerometer MPU6050 × 1, tilt sensor × 1, accelerometer × 1, light-dependent resistor × 1, MCP3008 with SPI interface eight-channel ten-bit ADC × 1, TFT SPI display × 1, RGB LED × 1, plastic box × 1, Raspberry Pi case × 1, soldering iron × 1, solder × 12.5mm screws × several, washers × several, waterproof wire connectors × 1, strong glue × 1.

Design Circuit

Building a Motorcycle Dashboard with Raspberry Pi

Building a Motorcycle Dashboard with Raspberry Pi

The circuit diagram is shown in the figure, please lay out the circuit according to the PDF instructions. If you are not confident, you can install all components in the project on the breadboard for testing. Note to use the 3.3V pin of the Raspberry Pi instead of the 5V pin.

Please carefully check the circuit for short circuits before powering the Raspberry Pi.

Download the PDF file from the project file library. https://make.quwj.com/project/260

Set Up Raspberry Pi

Building a Motorcycle Dashboard with Raspberry Pi

The Raspberry Pi serves as the operating system for the project, mainly responsible for processing angle sensors, storing service pages, running the backend, and database.

Now we will start setting up the Raspberry Pi.

1. Install Custom Raspbian Image

This image contains the packages needed to start the project:

  • Apache for the website frontend.

  • Database MariaDB.

  • Database operating phpMyAdmin.

  • Custom permissions to avoid problems.

Custom image can be downloaded here: https://drive.google.com/file/d/1wWtb2ZWEqh_-uxrbW7SYPqas-9emT4e-/view?usp=sharing

Once the image is installed, connect the Raspberry Pi to the computer via Ethernet. Then use an SSH client to connect to the IP address 169.254.10.1.

2. Configure Wireless AP

After the above configuration is completed, you can connect to the Raspberry Pi via WiFi, thus it can become a wireless AP. Relevant tutorial: https://thepi.io/how-to-use-your-raspberry-pi-as-a-wireless-access-point/

You can follow the tutorial up to step seven. We do not need step eight.

3. Enable Interfaces

Enter raspi-config

sudo raspi-config

Jump to the interface options, enable 1-wire, SPI, and I2C, then restart the Raspberry Pi.

4. Set Display Driver

Initialize the display by editing the filename: /etc/modules

sudo nano /etc/modules

Add the following two lines

spi-bcm2835
fbtft_device

Edit /etc/modprobe.d/fbtft.conf

sudo nano /etc/modprobe.d/fbtft.conf

Add the following line

options fbtft_device name=tm022hdh26 gpios=reset:25,dc:24,led:18 rotate=90 speed=80000000 fps=60

Restart the Raspberry Pi. If you see the light on the back of the display turn on, everything is fine. The display will initialize every time the Raspberry Pi starts, but now it only shows a black screen.

If you want to display the content of the Raspberry Pi on the screen, we need to copy the main screen’s content to the small LCD. We call it the ‘fbcp’ service.

Install fbcp Service

sudo apt-get install cmake
git clone https://github.com/tasanakorn/rpi-fbcp
cd rpi-fbcp
mkdir build
cd build/
cmake ..
make
sudo install fbcp /usr/local/bin/fbcp

Now, the service is installed. However, since we are only using the Raspberry Pi without a display, to output the screen content on the Raspberry Pi, please edit /boot/config.txt

sudo nano /boot/config.txt

Find and uncomment or add the following lines to this file:

hdmi_force_hotplug=1
hdmi_cvt=640 480 60 0 0 0 0
display_rotate=0
hdmi_group=2
hdmi_mode=87

Reboot the Raspberry Pi and enter fbcp in the console to test the fbcp service. Now, you can see the content on the LCD screen.

Run fbcp at Startup

Edit /etc/rc.local and add the following line between the IP address and exit line

fbcp &

After setting, the display will turn on every time the Raspberry Pi starts.

Design Database

Building a Motorcycle Dashboard with Raspberry Pi

To record and store angle sensor data, I designed my own database. As shown in the figure, it contains four tables.

1. Device Part

This table contains each sensor, including sensor name, description, and measurement unit. This table has a one-to-many relationship with the operation table; in this project, the accelerometer can perform different tasks.

2. Action Part

This table can store actions of different sensors. Ensure that an action is always associated with a specific sensor. For example: Action ‘TEMP’ is connected to the device that measures temperature. This will be the 1-wire temperature sensor.

3. History

This table contains records of all sensors. Each record includes an action ID, a value, a timestamp, and a riding ID.

4. Riding Part

This table stores different riding journeys. Each time the user rides again, it will be re-entered in this table.

You can obtain this database on the Raspberry Pi by copying it from my GitHub repository. In the database folder, you will find two .sql files.

Run them in PhpMyAdmin or MySQL Workbench. Subsequently, the database should be on your Raspberry Pi. https://github.com/EveraertAlexander/motoDash

Backend

If you haven’t copied the repository from my GitHub, you can find the complete backend of the project in the Backend folder.

In the /helpers directory, read the categories of sensors for the files that communicate with the database in /repositories, and the main application is located in the root directory named app.py.

Install Python Packages

Before running the program, we need to install some packages for Python. Enter the terminal of the Raspberry Pi and enter the following commands:

pip3 install mysql-connector-python
pip3 install flask-socketio
pip3 install flask-cors
pip3 install gevent
pip3 install gevent-websocket

Note: If you change the password for MariaDB/MySQL, please change it in config.py.

Test Backend

Run app.py using the python3 interpreter (/usr/bin/python3). Ensure there are no errors.

Run Backend at Startup

Edit motoDash_backend.service and modify YOURFILEPATH to the path of the storage folder.

Copy this file to /etc/systemd/system/

sudo cp motoDash_backend.service /etc/systemd/system/motoDash_backend.service.

Now, the backend will start automatically every time the Raspberry Pi starts.

Frontend

Building a Motorcycle Dashboard with Raspberry Pi

Go to the GitHub Repo. Copy the contents of the Frontend directory to /var/www/html.

Building a Motorcycle Dashboard with Raspberry Pi

This is all the work needed for the frontend. This folder contains all the web pages, styles, and scripts for the web interface. It can also communicate with the backend.

After testing that everything works correctly, connect to the Raspberry Pi and enter the IP address of the Raspberry Pi in the browser. You will reach the homepage of the web interface.

Note: This page is responsive, so you can use it on both mobile devices and desktops.

Display Dashboard on the Monitor

Building a Motorcycle Dashboard with Raspberry Pi

The frontend has hidden web pages specifically for small displays. We will open this website in full-screen mode when the Raspberry Pi boots up.

Make sure to set the Raspberry Pi to desktop auto-login in raspi-config under boot options.

sudo raspi-config

Now enter the hidden configuration folder and create a new file in it.

cd .config
sudo mkdir -p lxsession/LXDE-pi
sudo nano lxsession/LXDE-pi/autostart

Add the following lines to this file and save it.

@xscreensaver -no-splash
@xset s off
@xset -dpms
@xset s noblank
@chromium-browser --noerrors --disable-session-crashed-bubble --disable-infobars --kiosk --incognito http://127.0.0.1/dashboard_main.html

Now, the webpage will be visible every time the Raspberry Pi starts.

Soldering Electronic Components

Building a Motorcycle Dashboard with Raspberry Pi

Solder according to the component structure, connecting the sensors and modules to the correct pins. Ensure the pins are soldered correctly.

Building a Motorcycle Dashboard with Raspberry Pi

Soldering tips:

  • When soldering over a longer distance, use insulated wire.

  • After soldering components or wires, use a multimeter to check for continuity. You can also regularly check for short circuits in the circuit.

  • The use of solder should not be too much or too little.

  • If you don’t know how to solder, you can practice on another prototype board.

Ensure that the wires soldered on the sensors are long enough and use heat shrink tubing to prevent short circuits.

After all soldering is completed, carefully check for any short circuits or poor connections, and ensure that the electronic components are soldered correctly according to the design scheme.

Building a Motorcycle Dashboard with Raspberry Pi

Building a Motorcycle Dashboard with Raspberry Pi

Once everything is working correctly, install the terminal block on the Raspberry Pi and secure it with 2.5mm screws and standoffs, then correctly install the sensors and test it on the website.

Power Supply

I use a 12V-5V USB adapter to power the Raspberry Pi. This adapter will connect to the motorcycle battery. We use a relay to ensure that the Raspberry Pi is powered when the ignition switch is turned on. When the relay detects the taillight voltage, it will turn off the Raspberry Pi power circuit (the taillight is always on when the ignition is on).

For more related detailed tutorials, please click the link below: https://www.hondagrom.net/threads/2017-gromsf-msx125sf-wire-up-auxiliary-power-for-pcv-wb2-and-other-fuel-controllers.16921/

Enclosure

Building a Motorcycle Dashboard with Raspberry Pi

Building a Motorcycle Dashboard with Raspberry Pi

Display Enclosure

The display uses a hard plastic box. The size can match the display, and be sure to drill two holes in the front for the RGB LED and LDR. I used bolts to mount this box on the top of the smartphone holder.

Building a Motorcycle Dashboard with Raspberry Pi

Temperature Sensor Enclosure

3D print an enclosure that matches the size of my motorcycle’s oil gauge.

Building a Motorcycle Dashboard with Raspberry Pi

Raspberry Pi Enclosure

Install the Raspberry Pi in a location inside the motorcycle. I used some Velcro straps to place it under one of the fenders and protected it with a case and some plastic to prevent damage to the components.

Building a Motorcycle Dashboard with Raspberry Pi

Accelerometer

Install the accelerometer in a safe place, preferably on the motorcycle frame.

You can choose the enclosure for the electronic components freely. Ensure that the electronic components are rainproof and dustproof.

Further Reading

“Making a Bicycle Digital Speedometer with Arduino”

Project file library address:

http://make.quwj.com/project/260

Via instructables.com/id/Raspberry-Pi-Motorcycle-Dashboard/

Links in the text can be clicked to read the original text at the end

Building a Motorcycle Dashboard with Raspberry Pi

More exciting content

Making a Smart Pet Feeder with Raspberry Pi

Building a Smart Planetary Observer with Raspberry Pi

Handmade X-wing Clock with Metal Wire Frame Craft

I look like a handle, but I’m actually an adjustable power supply

A cloud that forecasts the weather, based on Raspberry Pi + 3D printing

DIY Stanford Pupper 12 Degrees of Freedom Quadruped Robot Dog

Barrier: PC and Raspberry Pi Keyboard Mouse Sharing Scheme

Building a Motorcycle Dashboard with Raspberry Pi

Leave a Comment

Your email address will not be published. Required fields are marked *