Raspberry Pi running from Batteries

Read this first http://simon.fearby.com/blog/?p=2202

Parts:
1x Raspberry Pi Model 2B
1x MoPi: Hot-Swap Mobile Power for the Pi (Manual)
1x 12V18AH Sealed Lead Acid Battery from JayCar (Manual)

1x 2 Watt 12 Volt Solar Panels – Amorphous 2 Watt 12 Volt Solar Panels – Amorphous

Read this post to see how my pi is configured and setup.

The Pi is running a public facing website here: http://sipi02.fearby.com

Step 1: Running on battery.

This is my battery and pi on my work bench.

PiBattery01

This is a close up of my Raspberry Pi + WittyPi (RTC and auto startup/shutdown hat) + MoPi (dual power and safe shutdown on low battery hat).

PiBattery02

I am not going to detail how to setup the MoPi but here is the MoPi output from the MoPi configured to be run from Lead Acid batteries.

PiBattery03

The default 6 cell Lead Acid battery profile says there is a low power condition when the battery is at 10.42v and the minimum charge s 9.48v.

Status Screen.

PiBattery04
This is the battery reading I have from the Pi itself.

PiBattery05

After 3 days of 24/7 use (saving an image every minute) and running a web server for the camera the battery has fallen from 12.73v to 12.28v.

Cheap multimeter reading (after 2 days use).

battery_3day

Mopi Reading (after 3 days use)

mopi3day

I will ignore my multimeter and trust the Mopi to decide when to power down the Pi.

mopi3dayb

I would expect the MoPi to shut down the pi when the battery falls another 2,456mv (that may be i n 18~25 days based on current trends (pun intended)).

voltchart1

Step 2:  Have the battery in Standby and top up the battery with Solar.

I have a cheapie “2 Watt 12 Volt Solar Panels – Amorphous 2 Watt 12 Volt Solar Panels – Amorphous”.  I have no idea if this will be enough to charge up the battery during the day? I have no idea about the solar stuff.

solar

Time to ask the experts at http://www.eevblog.com/forum/beginners/raspberry-pi-running-from-batteries-and-solar/

Update 30th March 2016

Ian.M at EEV Blog informed me that the lowest the battery should be discharged to is 10.5v.  I have edited the “/etc/default/simbamond” file to now specify safer low and shutdown power levels.  The “Sinabamond” service is a battery monitoring service (read about it here)

new-limits

If you edit the “/etc/default/simbamond” you may need to run the following command before and after you edit the file

  • sudo service simbamond stop
  • sudo service simbamond restart

Now when the MoPi detects the battery is below the low level the lights flash and broadcast messages appear on the terminal.

new-limits-warning

If the battery gets below the critical it shuts down the pi (safely).

Testing it (letting the battery getting below the critical limit).

new-limits-shutdown

The good think about the MoPi it shuts down the Pi safely and turns off the power (all power).

I must be getting a few low power spikes as the spikes because the Pi seems to be shutting down early.

I adjusted my max, good, low and critical values to 1200 11500 11100 and 11000 to test the levels of where my battery was at and the MoPi flashed to say it was shutting down then decided not to.  I ran a few volt outputs and the voltage detection was dipping.

new-limits-shutdown2

You may want to space your voltages enough to prevent voltage dipping triggering an early shutdown.

Ok this is the voltages that I will set my pi to shutdown at.

new-limits-shutdown3

Recharging the battery.

Ok, time to shutdown the pi and recharge my battery.

cahrger

Building the Prototype box

Installed 12v supply, 5v backbone, master off, RTC  and Dual PSU safe shutdown reset triggers. Next analog/digital sensors (smoke/co2, light, lazers, temp, humidity, pressure, moisture, motor and proximity motion sensor and vibration sensor), speaker and 240v relay for external control. Wifi, SMS and push notification code ready.

I killed a MoPi dual power input Pi board (silly me put the wrong colour shrink wrap protective layer over the top) and when I turned on the power with reverse polarity much blue smoke was released.

The main compartment will we air right with silica bags and protected from the elements with loads of styrofoam. I don’t think I need active cooling (therms electric peltier element).

proto-working

Raspberry Pi 2 Setup

Here is a quick guide to setting up a Raspberry pi 2 (OS, Wifi etc) using a pre loaded NOOBS Raspian OS on a Micro SD card.

I ordered the Raspberry Pi 2 Model B WiFi Pack from Wiltronics.

      This Raspberry Pi 2 Model B WiFi Pack includes a Raspberry Pi 2 Model B computer, durable clear case, a power adaptor, a USB WiFi antenna, an HDMI cable and an 8GB micro SD Card with NOOBS OS loaded.

WEB_RPiB340C2

Plug in a keyboard, mouse, wifi, HDMI and power and you are good to go.
sipi02_install_001

I had to check my old guides to refresh myself:

1. Select Raspian and press enter
sipi02_install_002

2. Press Y
sipi03_install_003

3. Wait for the install to complete.
sipi02_install_004

sipi02_install_005

sipi02_install_006

4. The Pi will ask to reboot (this is what it looks like)
sipi02_install_007

5. The first program that will run is the Raspberry Pi Configuration.
sipi02_install_008

6. I tried to expand the file systems but my card was already expanded.
sipi02_install_009

7. I followed the prompts to change the device password

sipi02_install_010

sipi02_install_011

sipi02_install_012

8. I reviewed the Internationalisation Options
sipi02_install_013

9. Change Locale.
sipi02_install_014

10. tip use space to deselect UK and select em_AD.UTF-8 UTF-8.
sipi02_install_015

11. em_AD.UTF-8 UTF-8
sipi02_install_016

12. Select Australia.
sipi02_install_017

13. Select Sydney
sipi02_install_018

14, Under Advanced change the Hostname (computer name)
sipi02_install_019

15. I entered “sipi02”.
sipi02_install_020

16. I selected Enable SSH (remote login)
sipi02_install_021

17. Select Finish and Yes to reboot.
sipi02_install_022

sipi02_install_023

18. After the raspberry Pi rebooted I could login with the user name “pi” and my new password
sipi02_install_024

19. If you are new to Linux and are not sure of any Terminal commands (like DOS commands) check out this Linux Commands Cheat sheet from http://linoxide.com/linux-command/linux-commands-cheat-sheet/

Linux Commands Cheat Sheet
Linux Commands Cheat Sheet

Booting up the GUI desktop.

20. GUI Desktop

You can type “Startx” to start the Raspian Desktop.

21. Desktop

The Pi Desktop is easy to use and navigate.

sipi02_install_025

sipi02_install_026

sipi02_install_027

sipi02_install_028

sipi02_install_029

sipi02_install_030

22. Internet Check

I plugged in in a spare USB TP-Link TL-WN821N wireless adapter, followed the wireless setup and verified I had a network connection by typing the following commands.

ping www.google.com

ifconfig

I did indeed have an internet connection.

23. Update/Upgrade

I dropped back out of X and ran the following commands to update the Pi’s firmware and software.

sudo apt-get update
sudo apt-get upgrade
sudo reboot

Then after reboot.

sudo rpi-update
sudo reboot

This took a while to download and install 130MB of data.

24. FTP Server

I setup an FTP server.

25. I2C Tools

Installed i2c-tools and configuring it. Troubleshooting here.

Added the following to “/boot/config.txt”

dtparam=i2c1=on
dtparam=spi=on

sudo apt-get install python-smbus
sudo apt-get install i2c-tools

26. Installed Python2 GPIO

sudo apt-get install python3-rpi.gpio

27. MoPI (Dual Power supply board)

Setup my MoPi

sudo apt-get install simbamond

FAQ’s here, here and here.

I did things a bit out of order and I think I needed to power up the MoPi/Pi from batteries (and no mains power) for 2iC to detect. But all is god, I can power up and shutdown my Pi from 6xAA batteries.

mo_pi_01

mo_pi_02

28. Install Python Camera module

sudo apt-get install python3-picamera

29. Python

Installed Python PIP

sudo apt-get install python3-pip

30. Monit System Monitoring

Installed Monit System Monitoring Web server to keep and eye on the MoPi from a web server (config here)

sudo apt-get install monit

More info here https://www.the-hawkes.de/monitor-your-raspberrypi-with-monit.html

31. Temperature Sensors

Add temperature sensing service to Monit (guide here)

sudo apt-get install lm-sensors

32. NGINX Web Server, PHP and Perl

Ok, now I am going to install a web server (NGINX, PHP and Perl) using this guide http://youtu.be/I_2yGGPus90

sudo -i
apt-get update
apt-get install nginx php5-fpm php5-cgi php5-cli php5-common libfcgi-perl

33. Python and raspberry Pi GPIO Pin Library

sudo apt-get install python-dev
sudo apt-get install python-pip
sudo pip install RPi.GPIO

33. Witty Pi – Realtime Clock and Power on/off scheduling board. Good review here.

wittypi

wittypi_02

wget http://www.uugear.com/repo/WittyPi/installWittyPi.sh
sudo sh installWittyPi.sh

Everything installed for me.

sudo shutdown -r now

On reboot I noticed warning on boot up about GPIO pin conflicts with my MoPi. Maybe the MoPi and Witty Pi are clashing? I changed GP17 on the Witty Pi and rebooted. I still had a conflict so I set GP4 on the Witty Pi to also be custom. After a reboot I still had MoPi warning.

wittypi_03

I am now researching how to redirect the GOI pins that the Witty Pi uses.

Do’h, I just realised that the Pi is powered by Mains USB on the pi and the MoPi warning may just be a warning about the MoPi not controlling the external power. I removed the mains power ad instead connected up the MoPi to a 9v DC supply.

wittypi_04

I reset the Witty Pi pins to their defaults and powered up the Pi via the Pi MoPI power button. All MoPi warnings have gone. Now to resume the WittyPi setup.

I will possibly use the MoPi to power down the Pi when battery gets low and use the Witty Pi to boot up the Pi every day and to use the Realtime clock.

tip: Make sure the folder you install witty pi to is spelled exactly like “%HOME%/wittyPi” and not “%HOME%/WittyPi”. My daemons would not start because it way looking for “/home/pi/wittyPi” and not “/home/pi/WittyPi”.

Now I configured the Witty Pi’s time.

sudo ./wittyPi.sh
1
7

34. SD Card Check

Ok run the following command to get the location of your boot filesystem

df

Now run this command to check your boot disk (replace the boot disk with the one identified above).


fsck -fy /dev/mmcblk0p5
reboot

You may notice potential corrupted files and fixes from the output above.


sudo dosfsck -w -r -l -a -v -t /dev/mmcblk0p5

Also run a check after reboot.


sudo shutdown -F -r now

You can run these commands to review any errors.


cat /var/log/fsck/checkfs
cat /var/log/fsck/checkroot

35. Filesystem Update
sudo apt-get update
sudo apt-get upgrade
sudo reboot

Then after reboot.

sudo rpi-update
sudo reboot

35. SD Card Backup

Type “distil list” to show your connected disks. My Pi is “disk5”

diskutil list
/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *500.3 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_CoreStorage Macintosh 10.9 HD 499.4 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1 (internal, virtual):
#: TYPE NAME SIZE IDENTIFIER
0: Apple_HFS Macintosh 10.10 HD +499.0 GB disk1
Logical Volume on disk0s2
532F6F24-17C1-4187-8637-45392549B220
Unencrypted
/dev/disk5 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *7.9 GB disk5
1: Windows_FAT_16 RECOVERY 858.8 MB disk5s1
2: Linux 33.6 MB disk5s3
3: Windows_FAT_32 boot 62.9 MB disk5s5
4: Linux 7.0 GB disk5s6

Clone the SD Card (this command has no feedback so please wait).

sudo dd if=/dev/disk5 of=/Users/simon/Backup/SiPi02/Jan3rd2016.dmg

Eject the SD Card


sudo diskutil eject /dev/rdisk5

How to restore a Disk Image to the SD Card.


diskutil unmountDisk /dev/disk5
sudo dd if=/Users/simon/Backup/SiPi02/Jan3rd2016.dmg of=/dev/disk5
sudo diskutil eject /dev/rdisk5

36. No back to reading the MCP3008 Analog to Digital Converting chip.

The following commands were taken from this video.

wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
unzip master.zip
cd py-spidev-master
sudo python3 setup.py install

Enable SPI at boot (video guide here)

sudo rasps-config
advanced options
SPI
Enable: Yes, Yes Finish
sudo reboot

Note:I completed the code above but my python script could not see spider (it was if the module was not installed. This resolved it.


cd ~
sudo git clone git://github.com/doceme/py-spidev
cd py-spidev/
sudo python setup.py install

 

todo

Part 3 (convert data):

Part 4 (advanced):

Part 5 (humidity sensor)

Comfast CF-WU755P WIFI

This guide may help me: https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=109919&p=755521

I might try this guide: https://blog.samat.org/2014/12/15/realtek-8188eu-based-wi-fi-adapters-on-the-raspberry-pi/