Raspberry Pi Motorcycle Dashboard

Introduction: Raspberry Pi Motorcycle Dashboard

About: Student MCT at Howest (Kortrijk, Belgium)

As a student Multimedia & Communication technology in Howest Kortrijk, I had to make my own IoT project. This would combine all of the modules followed in the first year into one big project. Because I ride my motorcycle a lot in my spare time, I decided to use my acquired skills at MCT tu build something for my motorcycle: A smart dashboard.

MotoDash is a Raspberry Pi powered dashboard designed for fanatic motorcyclists that gives the rider the ability to track their performance.

What are the features of this dashboard?

  • Viewing current tilt angle
  • Viewing current acceleration
  • Ability to monitor oil temperature
  • Automatically switch to dark theme when riding in the dark
  • Log data of your rides, and view your own statistics

Supplies

Main computing unit:

  • Raspberry Pi
    This is the main controller of the system

Electronics:

  • USB charger for motorcycle 12V-5V
    Main powersupply for the RPi
  • 4 Pin Fused Relay 12V
    Switch to turn on/off the power circuit of the RPi

  • Breadboard with jumper wires (optional)
    For testing and prototyping

  • A set of resistors

  • Different colors of 0.2mm wire

  • Breakout Pi plus
    This is a prototyping board where you can solder all of your components. It is made to fit directly on top of the Raspberry Pi, so the dimensions of the project stay to a minimum.

Sensors and modules:

  • Waterproof DS18B20 1-Wire Temperature sensor
    Oil temperature sensor

  • 3 Axes Gyro Accelerometer MPU6050
    Tilt/accel sensor

  • Light dependent resistor (LDR)

  • MCP3008 - 8-channel 10-Bit ADC with SPI Interface

  • TFT SPI display (or any other lcd display that fits your needs)

  • RGB LED

Casing:

  • Plastic box
  • Raspberry pi Case

Tools:

  • Soldering iron and solder
  • 2.5mm screws and spacers
  • Waterproof cable connectors
  • Superglue
  • ...

Step 1: Prototyping

Before we make everything permanent, we will put together the project on a breadboard. This step can be skipped if you are absolutely certain you won't make mistakes. The electrical/breadboard scheme can be found in the PDF below. Put the circuit together exactly as described. Make sure to only use the 3.3V pin and not the 5V pin on the RPi. Also before you power up the raspberry Pi double check your circuit. Make sure there are no shorts!

Step 2: Preparing the Raspberry Pi

First of all, we are going to set up the Raspberry Pi. The Raspberry Pi is a mini computer capable of running its own operating system. For this project, it is responsible for processing sensordata, hosting the website, running the backend and database, ...

1. Install custom Raspbian Image

The image provided already contains the software packages needed to jumpstart this project:

  • Apache for the website frontend
  • MariaDB for the database
  • PhpMyAdmin to manipulate the database
  • Custom permissions to avoid problems

The custom image can be downloaded from here.

A tutorial for installing images can be found here:

Once the image is installed, connect the Raspberry Pi to your pc with an ethernet cable. Now you can use an SSH client to connect to it on the IP address 169.254.10.1

It is good practice to immediatly set a new password using the command passwd

2. Configuring wireless AP

When the project is finished, we want to be able to connect to the RPi over wifi, so lets turn it into a wireless AP. A tutorial for this can be found here.

You only need to follow this tutorial up until step 7. Step 8 is not required as we do not need to bridge an internet connection, but create a standalone network.

3. Enabling interfaces

Head into raspi-config

sudo raspi-config

Go to interfacing options and enable 1-wire, SPI and I2C and reboot the Pi

3. Setting up drivers for the display

Initializing the display

Edit the file /etc/modules

sudo nano /etc/modules

Add the following 2 lines

spi-bcm2835
fbtft_device

Now 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

Reboot the Pi. If you see the backlight of the display light up all has gone well. This wil initialize the display every time the Pi boots up, however it will only display a black screen now. To get the contents of the Pi on the display, we need to copy the contents of the main screen onto the small LCD. We will use a service called 'fbcp' for this.

Installing 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 we have installed the service. However, since we are using the Pi headless, there is no screen available to copy contents from. To force the Pi to output screen content, edit /boot/config.txt

sudo nano /boot/config.txt

Find and uncomment or add 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 RPi, and test out the fbcp service by typing fbcp in the console. Now you should see the contents of the screen on the LCD.

Running fbcp on startup

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

fbcp&

Now the display should turn on each time the RPi boots up

Step 3: Database

To log and store sensordata I have designed my own database which contains 4 tables. The EER diagram is shown in the image above.

1. Devices

This table contains every sensor. It describes the sensor name, description and measuring unit. This table has a one-to-many relationship with the table actions, as in my case, the accelero sensor can perform different tasks.

2. Actions

This table stores actions for different sensor. One action is always linked to a particular sensor. For example: the action 'TEMP' is linked to the device that measures temperature. This would be the 1-wire temperature sensor.

3. History

This table contains all sensor logs. Each log has an action id, a value, a timestamp and a rideid

4. Rides

This table stores different rides. Each time the user starts a new ride, a new entry in this table is made

To get this database on your Raspberry Pi, head over to my GitHub and clone/download the repository. Under database you will find 2 .sql files. Run these in PhpMyAdmin or MySQL workbench. Now the database should be on your RPi.

Step 4: 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.

The folder contains classes for reading sensors under /helpers, files to communicate with the database under /repositories, and the main application is located in the root under the name app.py.

Installing Python packages

Before we try to run anything, we need to install some packages for python first. Head into the terminal of your RPi and type the following commands:

pip3 install mysql-connector-python

pip3 install flask-socketio
pip3 install flask-cors
pip3 install gevent
pip3 install gevent-websocket

IMPORTANT NOTE: if you have changed your Mariadb/Mysql password, change the password in config.py!

Test the backend!

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

Running the backend on boot

Edit motoDash_backend.service and change YOURFILEPATH to the path where the repository is saved.

Now copy this file to /etc/systemd/system/

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

Now the backend will start up automatically each time the RPi boots.

Step 5: Frontend

Head into the GitHub Repo. Copy the contents of the Frontend directory into /var/www/html.

This is all you should do to make the frontend work. This folder contains all webpages, styling and scripts for the web interface. It also communicates with the backend. To test if everything works like it should, make sure you are connected to your RPi, and type the IP address of the RPi in a browser. You should see the homepage of the web interface.

Note: The website is responsive, so you can use it on mobile aswell as on desktop

Step 6: Displaying the Dashboard on the Display

The frontend has it's own hidden webpage only used for the small display. We will make the Pi boot automatically to this website in full screen mode.

Make sure the RPi is set to desktop autologin in raspi-config under boot options

sudo raspi-config

Now go into the hidden config folder and create a new file in there

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

Add the following lines in this file and save

@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 Pi should boot to this webpage everytime.

Step 7: Soldering the Electronics

Take the breakout board and lay out your components on it in a structured way. I will not discuss the layout of how i soldered the components on it, as I did a pretty poor job on it. I used seperate pin headers on the board so that i only needed to connect the sensors and modules to the right pin. Make sure you know which pin is for what!

Some tips while soldering:

  • Use insulated wires when crossing larger distances. The last thing you want is shorts in your circuit
  • After soldering a component or wire, check its continuity with a multimeter. Also check regularly for short circuits.
  • Dont use too much or too little solder!
  • If you don't know how to solder, practice it first on another prototyping board. A tutorial on soldering can be found here.

Now solder wires long enoughto the sensors, and put some shrinking wrap around them to make sure everything is not shorted and clean.

When you are finished, double check for any shorts or bad connections, and check every connection with the electric scheme if it is the right connection. Once you are certain everything is done correctly, go ahead and put the breakout board on the RPi, end screw it tight with some 2.5mm screws and standoffs.Hook up the sensors to the right pins and test them all using the website.

Step 8: Power Supply

To power the Raspberry Pi we are going to use a 12V-5V usb adapter. This adapter will be connected to the motorcycle battery. To make sure the RPi powers up when the ignition switch is turned on, we are going to use a relay. The relay will close the RPi power circuit when it detects a voltage from the taillight (taillight always turns on when turning on the ignition).

For a more detailed tutorial about this, check out this page: https://www.hondagrom.net/threads/2017-gromsf-msx125sf-wire-up-auxiliary-power-for-pcv-wb2-and-other-fuel-controllers.16921/

Step 9: Housing

Display Housing

For the display, grab yourself a hard plastic box from around the size of the display. Cut a square hole in it as big as the display, and matching holes to screw the display in. At the front you need to drill 2 more holes for the RGB LED and the LDR.

I mounted this box on top of a smartphone holder using a bolt.

Temperature Sensor

For housing the temperature sensor, I 3D Printed an oil gauge which fits my motorcycle.

Raspberry Pi

Mount the raspberry Pi itself on a secure place inside the motorcycle, I placed it under one of the fenders using some velcro straps. And protected it from the elements using a housing and some plastic.

Accelerometer

Mount the accelerometer on a secure place, preferably on the motorcycle frame itself.

Note:

You don't need to have the exact same housing as I did, you are free to finish it however you like. Just make sure the electronic components are protected from rain and dust.

First Time Author Contest

Participated in the
First Time Author Contest

Be the First to Share

    Recommendations

    • Tinkercad Student Design Contest

      Tinkercad Student Design Contest
    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge
    • Make it Move Challenge

      Make it Move Challenge

    2 Comments