Pike - Drive Safer, Drive Smarter, Drive a Pike!

by nicolas.maas in Circuits > Raspberry Pi

423 Views, 0 Favorites, 0 Comments

Pike - Drive Safer, Drive Smarter, Drive a Pike!

IMG_20180618_185921.jpg

Welcome to my project called Pike!

This is a project as part of my education. I'm a student NMCT at Howest in Belgium. The goal was to make something smart by using a Raspberry Pi. We had complete freedom in which we wanted to make smart.

For me it was an easy choise to make my bike a bit smarter. I live in a place where riding a bike gets me faster to my destination in the city.

Also I fell with my bike once. I broke my ellbow. I fell down because I was pointing to the driver behind me that I wanted to go right. The road was slippery and I lost control because I only had one hand on my steering wheel. That's why my first idea was to attach directional indicators to my bike. From there I started to think what else I could add so I came up with GPS-tracking so you can later see which route you took.


So what can the Pike do?

The Pike will keep record of your driving sessions. It will keep track of which route you took, it calculate your average speed and the distance you've driven. After each session you can then login into the website to check where and how your ride was. We will also create something so you can choose who will ride the bike so more people can use your Pike if they want to!

The Parts

parts-header.jpg

So obviously you need to know what you need to recreate my project. Before we begin I would like to say that this project wasn't exactly cheap. Also I bought wires at a local shop which were overpriced. You can buy them online for a couple euros/dollars (which I recommend you do). I didn't have the time to wait. That's why I bought them from my local shop at a high price.

The shopping list

- Raspberry Pi

- Jumper Cables

- Powerbank any will do as long as it gives your Pi enough power

- Maxxter Smartphone Holder (basically the cheapest one you can find...)

- Maxxter Smartphone Holder (the white circular ones also very cheap to fit my plastic tubes)

- Plastic Tubes (drilled a hole in it to fit the buttons which fit in the smartphone holder to attach on the steering wheel)

- Buttons*

- 6x 220 Ω resistors

- 1x 5K Ω resistor

- LCD Display

- DS18B20 One Wire Temperature Sensor

- Adafruit GPS-module Ultimate Breakout 66 Channel

- GPS Antenna - External Active Antenna - 3-5V 28db with 5 meter cable SMA (to amplify GPS signal)

- uFLto SMA Adapter (to connect extra antenna to the Adafruit GPS-module)

Notes:

* The ones you'll see in the pictures are metal ones, maybe not the most ideal ones but those were the ones they had at my local shop. You can go fully waterproof buttons but those were 15 € a piece which I thought was way to expensive for a button. You could buy whatever button you want as long as it works with a pull up system you will be fine.

Wire Everything Up

fritzing-schema-breadboard.png
gps.png

It's not that difficult. Since the GPS module is connected with USB. You can see in the picture above that you can match the colors with the cables on the USB adapter. The buttons and LEDS are connected to 220 Ω. The DS18B20 Temperature sensor is wired up to a 5K Ω resistor.

Let's Configure Your Raspberry Pi!

github.png

First you'll need Raspbian which you can learn here and afterwards you need to follow the steps in this repository.

My Database schedule is quit minimal. It contains 4 tables:

  1. tbluser
    1. UserID (tinyint, 2) AUTO INCREMENT, UNSIGNED
    2. UserName (varchar, 175)
    3. UserLogin (varchar, 180)
    4. UserPassword (varchar, 255)
    5. UserActive (tinyint, 1) UNSIGNED
  2. tblsession
    1. SessionID (int, 10) AUTO INCREMENT, UNSIGNED
    2. SessionDate (date)
    3. UserID
  3. tblsensor
    1. SensorID (tinyint, 3) AUTO INCREMENT, UNSIGNED
    2. SensorName (varchar, 150)
  4. tblhistory
    1. HistoryID (bigint, 20) AUTO INCREMENT, UNSIGNED
    2. SensorID
    3. SessionID
    4. HistoryValue (varchar, 255)
    5. HistoryTime (time, 3)

But you can also take a look at the .sql dump file

Let's Start Coding

code.jpg

You can find my code for to make the project work here.

GPS

It's really simple to get started with the GPS Module. All you need to do is install the gpsd-py3 package in your Python Environment. Then you can use this library to make your life easier. You can use the coding examples to get the data such as longtitued, latitude, speed, etc. from your GPS.

LCD-Display

To make the LCD Display work you need to install the library from Adafruit. Coding examples can be found here.

DS18B20 One Wire Temperature Sensor

To find your one wire sensor you'll have to do a bit more work. First of all we need to activate the one wire bus. To do this follow the steps:

  1. sudo raspi-config
  2. Interfacing Options
  3. 1-Wire

To start reading the data from the sensor we need to know how our one wire is called. To this type in cd /sys/bus/w1/devices/

You will see two devices, one is the Raspberry Pi itself and the other one should look something like 28-0... etc. Well that long string of numbers and letters is how you'll be able to read data in Python. To read data in python you'll need to open it as a file. So the path to open the file should look something like this: /sys/bus/w1/devices/28-04177032d4ff/w1_slave.

Buttons and LED's

These are basic functions, you can look at my code in this Classes folder.

SQL-Statements

Almost every statement are basic SQL statements. However I would like to give a bit of explanation on how I saved my sensors their values. I manually added my sensors to my tblsensors. So I knew which sensor had which ID. So I keep track of Longtitude, Latitude and my Speed. For every value I made a different function. I would just make 3 sql statements that are the same but depending on which value I would like to store I changed the WHERE statement.

ENJOY YOUR PIKE!

pike1.jpg
pike2.jpg
pike3.jpg