Introduction: Pike - Drive Safer, Drive Smarter, Drive a Pike!
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!
Step 1: The Parts
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)
- 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)
* 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.
Step 2: Wire Everything Up
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.
Step 3: Let's Configure Your Raspberry Pi!
My Database schedule is quit minimal. It contains 4 tables:
- UserID (tinyint, 2) AUTO INCREMENT, UNSIGNED
- UserName (varchar, 175)
- UserLogin (varchar, 180)
- UserPassword (varchar, 255)
- UserActive (tinyint, 1) UNSIGNED
- SessionID (int, 10) AUTO INCREMENT, UNSIGNED
- SessionDate (date)
- SensorID (tinyint, 3) AUTO INCREMENT, UNSIGNED
- SensorName (varchar, 150)
- HistoryID (bigint, 20) AUTO INCREMENT, UNSIGNED
- HistoryValue (varchar, 255)
- HistoryTime (time, 3)
But you can also take a look at the .sql dump file
Step 4: Let's Start Coding
You can find my code for to make the project work here.
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.
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:
- sudo raspi-config
- Interfacing Options
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.
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.