Please select an option to see content specific to your location and shop online.

Project

Create A #WhereIsMyBus Alert With Raspberry Pi

Scroll down

You know the story: while you’re calmly eating your cornflakes you go to check-out bus times on your phone app – only to be side-tracked by that irresistible click bait on social media…and before you know it, you’ve missed the No 42. Again.

Or, when you do check your app, you’re at the bus stop in plenty of time only to be kept waiting for about seventeen hours in the teeming rain.

Well at last there’s an answer to this bus catching quandary – the amazing #WhereIsMyBus

This neat visual alert tells you precisely when to leave for your bus stop. And, as if by magic, the No 42 will trundle up just after you arrive.

#WhereIsMyBus will even warn you if there are no buses running, so you can make other plans. Isn’t that just the ticket?

But there’s more. Because, when you’re not using it as a bus alert, this nifty little beast transforms into a #Cheerlights light.

So enough of the hype already. If you really want to catch that bus, here’s the secret of how to make the #WhereIsMyBus alert.

What you’ll need:

  • Raspberry Pi connected to the Internet
  • An ESP8266 device
  • Strip of eight neopixels https://www.adafruit.com/products/1461
  • Wires to connect WeMos pins to Neopixel.
  • Sugru for sticking everything together
  • Something to use as a Neopixel diffuser, such as: – 3D printed bus

 

You’ll also have to know one end of a soldering iron from the other, but it’s pretty basic stuff.

Setting up your Pi

For starters, let’s sort out the Raspberry Pi Setup bit.

Connect the Pi to your wifi and find the IP address. (You can find it by hovering the mouse over the wifi icon on the top right of the screen or by typing “ifconfig” into a terminal window:

ifconfig

The Internet address is likely to be listed by the Wlan0 block – it should look something like “inet addr:192.168.1.XX”)

Before you go any further, make sure your Pi is up to date and has some extra software on it. You’ll be glad you did. Now type these instructions into a terminal window (be warned – some take ages to install and make you go through the whole yes/no rigmarole, which is a real drag):

 

sudo apt-get update 

sudo apt-get dist-upgrade 

sudo systemctl enable nodered.service 

sudo apt-get install mosquitto 

sudo reboot

You can now run your Pi “headless” – i.e. it no longer needs a monitor, keyboard or mouse to be connected.

On another computer connected to the same wifi network, type in the IP address:1880 (type the actual IP address of the Pi e.g. 192.168.1.13:1880). The Node-RED flow page will flash up.

If you didn’t know, Node-RED is an awesome visual flow programming tool – check it out at http://www.nodered.org

You can get the Node-RED flow here:

https://github.com/DrLucyRogers/WhereIsMyBus/blob/master/WhereIsMyBusNodeRedFlow

Click on Raw

Copy all the code to the clipboard.

In the Node-RED flow page click on the Menu (three horizontal lines at the top right)

Click Import

Click Clipboard

Paste the flow into the grey box

Click Import

Click somewhere on the flow screen (white area in the middle) to drop the code.

Click Deploy

Boom – you should now be gazing at something like:

 

 

Now double click the white “Edit the TFL API” node!Double click here for info” node for instructions on how to get the bus route, bus stop and direction information you need.

Double click the “TfL API node” and edit the URL with the information you require.

Click Deploy

And that’s the Pi done! Simples!

If you’d like to change the 3-6 minute threshold, just adapt the ‘thresholds’ Function node. For more info on what each node does, why not buy the book “Wiring the IoT” by Lucy Rogers and Andy Stanford-Clark http://shop.oreilly.com/product/0636920049104.do#

Solder time

Right, time to sort out your hardware.

Take your trusty soldering iron and solder a wire between:

  • +5V of the neopixels and the WeMos.
  • Gnd of the neopixels to the Gnd of the WeMos
  • Data In (DIN) of the neopixels to the Pin 4 (D2) of the WeMos

 

WeMos code

Use the latest open-source Arduino Software (IDE). You can download it here: https://www.arduino.cc

Now plug the WeMos into your computer using a USB cable.

You’ll need to install the following – the readme files have installation instructions.

In the Tools menu:

  • Select the “WeMos D1 R2 & mini” board in the board manager menu.
  • Select CPU frequency: 160MHz
  • Select Flash Size 4M (3M SPIFFS)
  • Select: Upload speed 115200
  • Port: – make sure this is the correct one

Download and open the Arduino file busLocalPiv3.ino

In the code, replace the ****’s in

const char* wifi_ssid = "****"

and

const char* wifi_password = "****"

with your wifi name (ssid) and password.

Update

#define BROKER "192.168.1.28"

with the IP address of your Pi.


If you want to use more than one WeMos connecting to the Pi, each has to have a unique CLIENTID. This can be whatever you like.

e.g.

#define CLIENTID "BusWeMos1"

Final touches

Remember we said this nifty little beast transforms into a #Cheerlights light when you’re not using it as a bus alert? Well we’re now going to show you how. Hold tight, ding ding…

First of all, let’s check out this cute 3D printed bus which we’ll light up cheerfully…

 

 

Simply print the file 20161111BusShellj.stl (the shell of the bus) and two lots of 20161111Wheels2.stl (the wheels).

 

 

Lovingly cover the inside of the upstairs windows with plasticard to give an atmospheric diffuse glow from the neopixel light.

Insert the #WhereIsMyBus and voila! A quirky addition to any bedroom or pad.

We hope you enjoyed creating this brilliant little device – and it makes your (bus) journey through life a little easier.

 

Like what you read? Why not show your appreciation by giving some love.

From a quick tap to smashing that love button and show how much you enjoyed this project.