Skip to content
Self Balancing Robot
C++ C Makefile Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc added documentation Jan 10, 2019
src project expo May 18, 2016
tools lowered the number of attempts per min Mar 1, 2016
LICENSE Initial commit Jan 12, 2016 Cleaned up readme a bit Jan 10, 2019
balancing_filter.pdf cleaned up code for final report May 6, 2016
tuning_a_PID_loop.pdf cleaned up code for final report May 6, 2016


Self Balancing Robot


The new makefile system allows us to easaly compile all the files togeter. It does some fancy things like only compileing what was changed, and allows us to install the program in the ~/bin folder. This means that when you type rollie from anywher it will exicute the program.

For testing run:

sudo ./rollie

When you wish to install:

make install
sudo rollie

Getting angles

Complementary filter

The gyroscope is located at 0x68 and returns a device id of 0x69 The accelerometer is located at 0x53 and returns a device id of 0xE5

PID controller

The PID controller is provided by a github library.

We run two PID controllers in cascaded configuration to allow us to both balanced and maintain position.




Edit raspi-config

Enter sudo raspi-config and set the host name to a number ex 2223. This is used to represent the port number to distinguish it between the other clients on the server.

Edit Chron tab

run crontab -e to open the cron tab editor. Then add the following:

@reboot /home/pi/rollie/tools/ >> boot.log 2>&1

*/1 * * * * ~/rollie/tools/ >> tunnel.log 2>&1

BCIT Network Setup

Add the following to sudo nano /etc/wpa_supplicant/wpa_supplicant.conf Make sure to edit the user and password.

        identity="a00######"      <--- Here
        password="super_secret"   <--- And here

Remote Server

To be able to connect to the raspberrypi enter pi1, or 'pi2', on the server. This will auto connect to the raspberrypi provided that it has established a reverse ssh tunnel.

To make those aliases, add the following to the .bashrc file:

alias pi1='ssh -p2220 pi@localhost'
alias pi2='ssh -p2222 pi@localhost'

You will also need share the ssh keys with the server and clients

Connecting the IMU

To connect the IMU to the raspberry Pi connect the ground and 3.3V and connect the SCL and SCA to their respective inputs on the Pi. Follow this pinout for the PI.

Raspberry Pi pinout


Reading from the IMU

Accelerometer reg map

Accelerometer Register Map

Gyro reg map

Gyro Register Map

Stepper drivers


Realy great stuff:


You can’t perform that action at this time.