Tuesday, July 08, 2014

Using an Adafruit PowerBoost 500 charger as UPS for a Raspberry Pi

 

One of the main tasks of a Raspberry Pi I have is monitoring my automatic backup generator and sending out alerts via SMS and email when the generator kicks in. This works fine, with up to now 1 glitch: when the outside power to the house is cut off, it takes at least a minute for the generator to kick in and start providing electricity to the house. So, under that scenario, the Raspberry Pi reboots and although the monitoring applications start up again, it just didn't seem to me as though it was foolproof.

So, I had been searching for a long time for a reliable, affordable Uninterruptable Power Supply (UPS) for this Raspberry Pi. I could probably have used one for a PC, but that was just too bulky and expensive. I even went so far as to try and design e backup power circuit using supercapacitors (after all, I don't need backup power for more than a minute), however, 'miserable fail' is the only term I can accurately and honestly use to describe that effort. Theoretically, it should have worked, in practice my circuit couldn't supply power for more than about 15 seconds, before the voltage dropped below acceptable levels and the Pi conked out.

Enough about that. By having Adafruit on my Twitter feed, I became aware of their PowerBoost 500C charger. Digging a little deeper, I found that this could also act as a UPS for Raspberry Pi, Arduino, etc. So, I decided to purchase one.

It arrived in mere days, which is pretty much a miracle when you realize it had to cross the US-Canada border. I soldered the USB connector in place (this is the output side from where the power is fed to the micro USB connector on the Pi), plugged in the Lithium Ion Polymer Battery I purchased at the same time and plugged the whole ensemble into the wall outlet via a standard USB wallmount charger. No smoke! On the contrary, the on-board LEDs lit up (and bright they are). I had to wait a little while until the yellow LED (indicating battery is charging) was replaced by the green LED (indicating battery charged).

Following that, a made a little YouTube video illustrating what happens when you plug a Pi into the output side, and then unplug the wall power etc.

In the video, I only have the Pi running off the battery for a short while (approximately 30 seconds), which should be sufficient for my purposes. However, in a subsequent test, I had the wall plug removed for more than 3.5 hours and the battery (2500 mAh) was still going strong.

So I think I finally have a reliable solution for my UPS problems.

Sunday, February 02, 2014

Raspberry Pi and peer to peer networking

 

Normally, when using the Pi and doing development work, I use it headlessly. It sits somewhere in the basement and I communicate with it using Remote Desktop. However, since I am testing NFC (Near Field Communications), I had a need to be close to the Pi when doing development work.

So I installed peer-to-peer networking. After the usual Google searches, I was able to piece together how to do it. This write up really is for my own reference so I will know how to do it at some future point in time. Note that I am doing this using a cable, not a wireless dongle. Apparently using a wireless dongle is possible as well, I just haven’t tried it.

First my setup: I work from a Windows 8.1 lap top and and when the Pi is setup in the basement, I wirelessly connect to it, via my router of course.

Be forwarned, unfortunately, there is no way to make the necessary changes on the Pi without hooking it up to a monitor of sorts, be it through HDMI, VGA.

So, to install peer-to-peer networking: Take an Ethernet cable of any length, I used a short six feet (2m) cable, and plug the ends into the PC and the Pi. Restart the PI. Don’t worry about this cable needing to be a cross over type: the Pi is auto sensing.

Next, in Windows, go to Start, run and type in ‘cmd’ (no quotes). In the command window that appears type ‘ipconfig’ (no quotes). In the listing that follows, look for a heading that says ‘Ethernet adapter Ethernet’. Within that section, look for Autoconfiguration IPv4 address and write down the address that follows this. Mine was 169.254.212.0. On the next line, you should see Subnet Mask, write this down well, mine was 255.255.0.0

On the Pi, type ‘sudo nano /etc/network/interfaces’ (no quotes) In the file that opens make sure that the following lines appear:

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 169.254.212.1

netmask 255.255.0.0

Modify the address line with your own IP address that you found on your PC, but add 1 to the last number (look at my example). Furthermore, use exactly the same subnet mask on the Pi as on the PC. You can comment out any other lines that appear by putting a # hastag in front of it.

Save (Control-x, then press Y). Reboot the Pi and test.

I found Remote Desktop as well as my wireless to the router and Internet to be working as usual.

Sunday, January 19, 2014

Raspberry Pi: clean install of NFCPY

NFCPY is a Python library allowing for Near Field Communications readers to be accessed directly from Raspberry Pi. As part of a project I am working on, I needed to install this library on a clean Raspbian install of a Raspberry Pi.

Once the installation was completed I used the base ‘history’ command to retrieve all the commands that I typed in the terminal to accomplish this task. I removed all the commands that were wrong or superfluous.

Please note that this was a brand new install: I used a NOOBs SD card and chose Raspbian. Once the operating system was installed, the following commands were typed in:

$  sudo nano /boot/cmdline.txt
$  sudo nano /etc/inittab

The above two commands need to be modified in order to free up the UART on the Pi (to be totally honest, I’m not sure if this needs to be done for nfcpy.) Follow these directions from Clayton Smith’s website. Initially, I used Adafruit’s website for these instructions, but they were not totally clear.

$  sudo raspi-config

This allows you to personalize your Pi through the Raspbian Configuration utility.


$  sudo reboot –n

A reboot to ensure it all still works.


$  sudo rpi-update

Update the firmware on the Pi

$  sudo apt-get update
$  sudo apt-get upgrade

Install the latest Raspbian operating system updates and upgrades


$  sudo apt-get install xrdp

Install Remote Desktop


$  sudo apt-get install python-dev
$  curl -O http://python-distribute.org/distribute_setup.py
$  sudo python distribute_setup.py
$  curl -O https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py

$  sudo python get-pip.py
$  sudo pip install virtualenv

Install (fairly) standard Python utilities


$  sudo pip install pyserial

Install serial library for Python used by NFCPY.



$  sudo apt-get install bzr

Install Launchpad bazaar, a VCS (Version Control System), which allows you to download NFCPY.


$  mkdir pythonprogs
$  cd pythonprogs

Above 2 commands create and then switch to the directory where my Python programs will be stored on this machine.


$  bzr branch lp:nfcpy

Download the latest version of NFCPY.


$  cd /pythonprogs/nfcpy/examples

Switch to the examples directory of NFCPY.


$  python tagtool.py --device tty:AMA0:pn53x show

Run the Python program tagtool. The ‘device’ switch following tagtool.py specifies that we want to use the serial device.

Then put a card near the reader: partial success. There is output on the screen, but the reader cannot read the card, apparently NFCPY cannot handle MIFARE Classic 1K cards. So I ordered some other ones, hopefully they will work!

UPDATE 2014/01/29 The cards I ordered from OverAir Proximity Technologies do work! They are

NFC Card - White - NTAG203 PAC-N3Card

UPDATE 2014/08/02 I purchased a Raspberry Pi B+ (mainly for the form factor) and found I needed to modify to contents of some of the links above in order to successfully install nfcpy.