PLEASE NOTE: This site is no longer being actively maintained. For frequently updated BeagleBone resources please visit Beaglebone.org.

Friday, August 8, 2014

On 3:00 PM by Richard St-Pierre

Overview

The BeagleBone is a powerful computer with low power consumption. The analog voltage measurements, extensive GPIO (General Purpose Input Output), data storage and computation capabilities makes it a great science experiment companion... if only it wasn't on a leash!

This project combines and builds on a number of methods previously outlined in tutorials and projects here on Inspire (like our accelerometer tutorial) and will guide you through one simple way to cut the cord!

A 3-axis accelerometer is mounted inside an orange case cover, BeagleBone is battery powered.

Special thanks to contributing author: David St-Pierre

What You Will Need

 

Introduction

In order to have the best battery life, we need a high efficiency voltage regulator. A switching regulator that can deliver 5 volts at 1 ampere or more is ideal. We also want this project to be easy to build. LiPo cells would be nice but "AA" are more readily available.

The BeagleBone will be running 'head-less' with no keyboard or display. We could connect with a wireless link (which would also requires more power), but this may not always be practical (ex: while riding a bicycle, motorcycle or driving a car) - Always use care when using a moving vehicle. A simpler approach is to use a basic push-button to start the BeagleBone program, and request an orderly shutdown and an LED to display status.

Step 1 - Wiring The Circuit

There are two basic ways to power the BeagleBone. You can apply a regulated 5V to the barrel jack, or provide power over the USB cable. Use which ever method is more convenient for you.



I chose to provide the power using the USB cable approach. This makes it easy to plug-in the USB cable provided with the BeagleBone. There are also many USB DC power options available on the market
(including automotive auxiliary power 12V outlet adapters!).


Switching Voltage Regulator



Wiring Connections:
Battery(+) to Voltage Regulator Input
Battery(-) to Voltage Regulator Ground
Regulator Output to BeagleBone +5V
Regulator Ground to BeagleBone Ground

Note: The author mounted the voltage regulator in an 'Altoid' (candy mint tin) container.

Step 2 - Circuit Verification

[CAUTION] Test the power circuit *carefully* before connecting to the BeagleBone.  Make sure the output voltage reads 5.0V and verify that the polarity (+/- ) is correct.

Power up with the battery circuit to the BeagleBone and SSH (putty) and verify that the system is working.

Step 3 - Adding Push Button and LED

We will use the push-button switch to signal that we want our program to start some measurement or task. The LED will provide useful status information. This will allow very simple two-way communication. Alternately, we could use the 'USR' LEDs on the BeagleBone. An external LED is more visible.

Push Button Connection

PushButton Switch pin 1 to BeagleBone (P8-26)
PushButton Switch pin 2 to Resistor (330 Ohms) and then to BeagleBone (P8-45)Ground

LED Connection

LED Anode(+) to BeagleBone (P9-14)
LED Cathode(-)to Resistor (330 Ohms) and then to BeagleBone (P9-1) Ground

Consider an industrial LED push-button switch and the BB100 expandable case. 

The switch assembly in the photo is an OMRON A3DT-7111 with an OMRON A3DT-500GY LED.

Step 4 - Starting a Program, Measuring and Shutting Down

We need to know the status of the BeagleBone at many stages.

First the LED can tell us if the BeagleBone has completed booting up. This can be done by blinking the LED. This tells us that our program has started and we can start to make measurements or begin some control task. This is where the push-button can be used to signal that we are ready to go. Once the program has started its task, we change the LED to solid or change the flashing rate. When we are all done and want to power-off, we can press the push-button to request an orderly shutdown to begin.

Let's look at this control in steps.

Create a (python) program task to run (example provided).

Download myprog.py File (and save it without the txt extension).

or

Create the file myprog.py
nano myprog.py
Enter the following program.

#!/bin/python
#------------------------------------------
# Author : David St-Pierre   Aug 1, 2014
#--------------IMPORTS---------------------
import Adafruit_BBIO.GPIO as GPIO
from time import sleep
#--------------VARIABLES-------------------
toggle = 0
BUTTON = "P8_26"
LED_YEL = "P9_16"
#--------------GPIO SETUP------------------
GPIO.setup(LED_YEL,GPIO.OUT)
GPIO.setup(BUTTON, GPIO.IN)
#-------------WAIT TO START----------------
print("Press the button when you are ready to start")
while(GPIO.input(BUTTON) == 1):
 GPIO.output(LED_YEL, GPIO.HIGH)
 sleep(1)
 GPIO.output(LED_YEL, GPIO.LOW)
 sleep(1)
#--------------START-----------------------
print("Will begin in 10 seconds\nPress the button again to stop reading")
GPIO.output(LED_YEL,GPIO.HIGH)
sleep(10)
GPIO.output(LED_YEL,GPIO.LOW)
sleep(1)

#---------------CONTINOUS LOOP TO READ SENSOR------------------
 while(True):
  
#---------------BLINK LED----------------------
  if(toggle):
   GPIO.output(LED_YEL,GPIO.LOW)
   toggle = 0
  else:
   GPIO.output(LED_YEL,GPIO.HIGH)
   toggle = 1
#--------------INCLUDE YOUR TASK HERE -------------
  
   sleep(2)



#--------------EXIT ON BUTTON PRESS--------------
  if(GPIO.input(BUTTON) == 0):
   print("Button pressed \nExiting Program")
   exit()


Create a script file that will be called at Boot-up.

nano myboot.sh

Enter the following text.

#!/bin/bash
python /root/home/myprog.py
sudo shutdown -h now

Save and exit {ctrl+o, enter, ctrl+x}.
Note the full path name of 'myprog.sh' must be specified.

Make the script executable.
chmod a+x myboot.sh

Finally let's create a cron job that will execute at boot-up.

crontab -e

And add the following:

@reboot  /root/home/myboot.sh 

Overview

Once power is applied, the BeagleBone starts to boot. As part of the completion of the boot process the cron job starts (@reboot) and calls the script that we have created. The script in turn calls our task program.
The python task program starts flashing the LED to indicate that boot is complete and our program has started to execute. The program then looks for a signal from the push-button switch. This allows time for the user to set-up the environment or measurement conditions.

A button press, starts the active portion of the program (what you want to do). The LED state is changed to acknowledge and indicate this new state. After a period of time, you can end the task by pressing the button once more. The task now exits and returns to the script that started the measurement or control cycle.

Next, the shutdown command is executed. This request provides an orderly close and powers down the BeagleBone.Time to review the data, and investigate the results collected by the BeagleBone.

Going Further

This project is a just first step, describing how to cut the cord. We'd love to hear from you about the ways you utilized your new battery powered BeagleBone. Give us some details in the comments below and stay tuned for more projects that will be un-leashed soon!!