Category: Internet of Things

Raspberry Pi based location tracker

My recently published DIY instructable to track any moving vehicle based on cell tower information  has got 500+ visits in just a few days.

Simple Python scripts are used to fetch data from USB dongle, upload data to cloud. Client side HTML/JavaScript code shows location on Google Maps.

Try some DIY this holiday season 🙂

Advertisements

UPS for Raspberry Pi

Raspberry Pi Operating Systems are by design meant to be powered off gracefully just like others. If they are hard booted often, OS gets corrupted and the only solution I found is to reinstall the OS. This also means you will have to back up your data first.

The power supply that I use for RPi is 24 hours but it’s not uninterrupted. When electricity from pole goes off, power backup from generator takes a few seconds to start and that’s enough to cause RPi reboot.

I had this problem from day one, but a mobile/tablet power bank is the solution for it.

Since RPi has modest power requirement of 5V and 1A, the output from such a power bank meets power requirement. Now I’ve connected it between the USB mobile charger(that I had been using as power supply) and RPi.

It makes a perfect Uninterrupted Power Supply for my little computer 🙂

Upgrade Raspberry Pi disk storage

To start with Raspberry Pi, I had installed Raspbmc OS a.k.a. Kodi on a 4GB MMC card that I took from my phone. This little computer is impressive and now I’m a proud owner of this cheap yet powerful media center.

I wanted to upgrade memory to 16GB so I can store more videos. But I wanted to keep the OS as is and didn’t want to redo the installation and configuration , backup and restore data.

So that’s the solution? At a high level, you need to backup the entire memory card(including it’s partition table) onto a file and restore from it.

On Windows, you need to use Win32DiskImager, the same software that you probably used during Raspberry Pi installation

  1. Install the s/w on a Windows system and insert the memory card. You can buy a cheap MMC card to USB adaptor from your local shop, in case your computer doesn’t have a MMC card slot.
  2. Run Win32DiskImager, give a name to the file where you want to backup your MMC card and hit ‘Read’.
  3. Now insert the new MMC card.
  4. Run Win32DiskImager again and this time, restore the backup onto the card by clicking ‘Write’
  5. At this point, your OS has been restored to a new card, but if you boot up Raspberry Pi, it sill still show old disk space.
  6. To make Raspberry Pi ‘aware’ of new disk size, I ran fdisk and resize2fs commands as mentioned in this accurate answer.

And this is all about it!

You have successfully upgraded the storage.

Although watching videos on a media center OS like Kodi using existing TV is much better experience than any other OS, one outstanding feature was about subtitles support. On VLC payer, I manually search for subtitles, jostle with ads on those sites, download and then point VLC to that file. It’s no longer the case with built in media player on Kodi. You just need to click ‘Download subtitles’, it will search for best match automatically.

Operate AC from smartphone

Recently I saw this TVC of Voltas all weather AC, where it shows you can control your AC with a smartphone. It’s a brilliant idea, and not surprisingly the prerequisite for the app is – your smartphone should have IR transmitter.

So if you are buying that AC and want to use it’s app, there are chances your smartphone turns out to be not smart enough in this case and you may have to buy a new one!
Well, not necessarily. If you are ready for some DIY stuff, you may use Raspberry Pi and possibly use any AC + smartphone combination.

At a high level, this is what I’m thinking of-

  • Connect an IR transmitter to RPi. Record the IR codes from AC remote and ‘train’ the LIRC. The most accurate and comprehensive blog I found is from Alex Bain
    http://alexba.in/blog/2013/01/06/setting-up-lirc-on-the-raspberrypi/
  • To send commands remotely, either create an app or a host a web page inside RPi’s in-built web server.
  • Connect smartphone to RPi over your home wifi.

Now you are all set to control AC from any device on your home network. Controlling it from outside the home network is also possible.

Internet of Things Temperature sensor

My first IoT project is a room temperature sensor publishing data to cloud.

Google DS18B20 + Raspberry Pi and you fill find many posts about it. I followed one of them

https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/temperature/

Purchasing the hardware and electronics part was a big difficult in India. The parts are cheap, but finding the correct ones on internet or local shops was a bit challenging for me.

Once I procured all the hardware, the only change in the above circuit diagram is to use 5V rather than 3.3V. With 3.3V, sensor was getting detected, but there was no reading from it.

Data is read by Python function

def read(precision):
inputfile = open("/sys/bus/w1/devices/28-031464907dff/w1_slave")
text = inputfile.read()
inputfile.close()
tempdata = text.split("\n")[1].split(" ")[9]
temp = float(tempdata[2:])
temp = temp / 1000
temp = int(round(temp,precision))
return temp

To upload use API provided by data.sparkfun.com

import urllib2
def publishtoInternet(temp):
url = "http://data.sparkfun.com/input/<public_key>?private_key=<your_key>&temp=" + temp
result = urllib2.urlopen(url).read()
print result

And that’s it! This is an always on temperature sensor. You can not only publish it to internet, you can also use the reading to take decisions like controlling other IoT things.

Raspberry Pi- Internet enable your TV, turn it into media centre

If you want to watch live streaming from internet to your non smart TV, you have an option to either to use it as a external display unit connected via HDMI from your computer or purchase something like Chromecast. I used Raspberry Pi.

Media centre Kodi on TV

Media centre Kodi on TV

Why RPi?

This $35 ‘computer’ continues to enjoy attention worldwide for educational purpose, DIY projects and home automation. I had bought one to play around and found how easy it is to turn TV into a media centre. It has turned my TV much smarter than my imagination

  • Watch HD quality streaming video from YouTube, Dailymotion and other channels
  • Download and record from these channels
  • Configure subtitles add-on
  • Play media stored in USB drive or from network share or from your mobile as well
  • Use your mobile as remote control for your TV
  • Download from transmission torrent app
  • And the best part is, you can still use other popular features of RPi like hooking up an IR or temperature sensor to the GPIO pins in RPi.

What you need?

  • Along with RPi, you need some accessories like USB mobile charger as power supply, connectors, etc. Check out my previous post for this.
  • Download and install RASPBMC, flavor of media center OS Kodi for Raspberry Pi.
  • If your TV doesn’t have HDMI port, you will a converter.
  • Additionally you may also want to install these Google Play apps or similar ones from your app store.
    • Fring – Without logging onto RPi, you can know the it’s IP address. The app will do a network scan and list down all the machines along with their IP and MAC addresses.
    • Juicy SSH – Turn your smart phone into SSH client. You will never feel like you are not using a computer while firing remote commands
    • Yatse – Kodi remote control for smartphone. No limitations of IR remote; control your ‘smart TV’ from anywhere in your home. You can also play media files stored in your phone wirelessly to your TV.

And this is it !

The best case is when your TV has a spare HDMI port, so you don’t need to use the existing cable or satellite connection port for Kodi. You may leave both of them connected to your TV and choose whether you want a watch conventional TV or a want to have a smart TV experience.

Setting up IR receiver on RPi is also not that difficult. Once setup and configured on Kodi, you can use the TV’s remote to send commands to RPi as well as your TV. It’s very exciting to learn how IR receiver and sender work and create a programmable transceiver using RPi. I’ll blog about it later.