Introduction: AINA: Field Lab Using Edison IoT

About: Founder of Maui Makers

AINA (Automated Information on Nature Attributes) is an electronic sensor field laboratory built on the Intel® Edison IoT platform. The acronym, "AINA", references the a Hawaiian word for land or place.

Project Overview:

Our project is a proof of concept for a re-configurable sensor platform or field lab kit that can collect environmental data, utilizing the Intel Edison processor. The lab can be run on battery/solar completely offline. It uses a store and forward approach to minimize reliance on network availability. The “store and forward approach” starts with the data being collected and stored locally. It then is transferred to a mobile device via bluetooth connection, and then later transferred to a (web) datastore. This offline collection and transfer is essential for remote placement of the platform.

Our setup:

This project was built as part of the INTEL® IOT Invitational contest. We were provided with the Environmental & Agriculture kit. We were fortunate to also have a variety of Grove sensors and shields available from the Many Labs: Sensors for Students Kickstarter and our own Grove Indoor Environment Kit for Intel® Edison. We also had a Sparkfun Starter Pack for Edison available, which allowed us to do some parallel development.

There are a number of loose ends in the project, not the least of which is a proper environmental housing. Design of a proper housing requires careful consideration of the sensors selected, providing them with both protection from and access to the environment they are measuring. There are also a number of Edison related configuration issues to be resolved.

The main components of this project are:

  • Intel Edison with Kit for Arduino
  • Variety of Sensors
  • Development Environment
  • Mobile Device with Bluetooth ftp capability
  • Software to perform functions on the Edison
  • environmental enclosure
  • solar battery and charger

Intel® Edison

The Intel® Edison is a small linux microcomputer marketed for Internet of Things products. It provides basic computing, communications & storage functions. It supports a wide range of sensors and devices. Intel has been pushing it heavily into the maker market. It is not clear how much marketing is to established industrial developers. Most of the literature and forums available on the web seem to be for small entrepreneurial or hobby builders.

Step 1: The Electronics: Edison and Sensors

The Invitational contest selected a subset of the Grove Sensors available from SeedStudio. The Grove system provides a common 4 wire connection between a Shield (interface board to microcomputer) and a sensor demonstration board. SeedStudio makes Grove Starter Kits for a wide range of microcontrollers (Arduino, Raspberry Pi, Beagle Bone, Photon, LaunchPad, Mbed, etc). Unfortunately, the contest did not supply the interface shield. Fortunately, we had several, along with one from the Grove Starter kit.

Sensors Provided by Intel:

We received the "Environment and Agricultural Kit" as for our part of the contest. Included in this Kit: (links to SeedStudio store page, which links to their wiki)

Additional Sensors Used:

We augmented this with a selection of Grove sensors from the Grove Indoor Environment Kit, and our stock of grove sensors. Some of the sensors tested/used include:

There are (currently) 53 products listed in the SeedStudio catalog for Grove.

Step 2: Set Up the Edison and Development System

The first important step is to properly setup the Intel® Edison and a basic development environment. For simple testing purposes it is useful to have the Arduino environment handy, so even though we are going to use Python, we will install that development environment.

There are several online guides for setting up the edison. The primary guide for setting up the edison is the Intel Getting Started which unfolds slowly requiring you do go through download steps. The Sparkfun Edison Getting Started Guide is a bit better, focusing on setting up the Arduino environment. Another alternative getting started from Intel is at https://software.intel.com/en-us/intel-edison-board-user-guide.

We found this Instructable Getting Started with Intel Edison - Python Programming was quite helpful to us as we plan to use Python as opposed to Arduino, Java, or other languages.

CAVEAT: One issue we found with the various guides is that many of them (incl the Instructable and sparkfun guides) are not up to date with latest Edison Linux software. Ignore any of them that tell you to expand and/or copy the Yacto image to the Edison. You must use the Flash Tool Lite. Follow these instructions from Intel.

For the Instructable guide above, skip steps 2 & 3, substituting the Flash Tool Lite instructions.

Basically initial setup steps:

  1. Assemble the board
  2. Connect to dev system and bring it up to date FlashToolLite
  3. Connect to Edison to Console via serial terminal tool
  4. configure edison, setting its name and giving a root password
    • having a password for root is rudimentary security measure. Do It.
  5. A wifi connection to the Edison is helpful in development, so configure that
    • changing locations and wifi networks will require logging in via console and reconfiguring wifi
    • also the ip address of the edison may change between development sessions. It is assigned by the wifi router dynamically. There maybe different machines connected to the wifi when edison connects.
  6. Setup SFTP to transfer files

The development cycle for python tends to be:

  1. Create initial python code on the development machine
  2. SFTP the file to the Edison
  3. login to edison and run the program from command line
  4. revise program, re-transfer, rerun

An alternative to revising and re-transferring the program is to use an editor on the Edison. The venerable VI editor is available on the Edison, providing screen editing.

Basic Hello World Blink LIght App

Getting a couple simple Hello World and Blink LED applications running will show the basic process. These steps are shown in the latter parts of the Instructable Getting Started with Intel Edison - Python Programming

After The Basics

Once you have got the basic development environment operational, there is a lot of customization to be done. Later sections will deal with the sensors, but quite often you need to modify the Linux environment. This requires a fair bit of specialize knowledge of command line tools and console access to the machine. You saw some of these in the setup of wifi connections in the above linked guides. More will be discussed in later sections, such as Bluetooth.

One area that may require console access on regular basis is enabling WiFi when you move to different development locations. The first time you setup with a new WiFi, you follow the instructions in the above guides. Intel breaks it out to a single appropriately named document: Connecting your Intel Edison board using Wi-Fi. Once a trusted network connection has been established, it *should* be easier to return to that location.

An additional step that the basic configuration skips is setting the time and timezone of your Edison project. Many embedded systems dont need time, but AINA uses timestamps, so it would be good to set it for local time. Otherwise it will be set for GMT. Here is an Intel Forum Thread giving instructions on setting date/time/timezone

Step 3: Unit Testing Sensors

Once the development system is operational, it is time to get busy with the sensors.

The Grove Wiki provides extensive information on their sensors. Each sensor has its own wiki page with descriptions, links to vendor literature on sensor, and Usage example code for a variety of microcontrollers. Unfortunately, the only Python examples are the raspberry pi using the grovepi library. This library doesnt exist on Edison, so we look elsewhere.

Intel MRAA and UPM libraries to provide higher level support of the GPIO functions of various Linux systems. The libraries are written in C/C++ with bindings for Python, Java, JavaScript. Installing these for the Edison was done in the Development Setup.

Our unit testing explores the use of various sensors utilizing the libraries. A Python tool is created for each sensor and tested using terminal output.

Example Unit Tests

Examples of these applications are included here. Others can be found in the UPM GIT repostitory, with the caveat that the sensors are named there by their cryptic chip numbers. For example tsl2561.py is their demo for the digital light sensor module.

Digital Light Sensor Code

http://www.seeedstudio.com/wiki/Grove_-_Digital_Light_Sensor

import time, sys, signal, atexit
import pyupm_tsl2561 as upmTsl2561

# Instantiate a digital light sensor TSL2561 on I2C
myDigitalLightSensor = upmTsl2561.TSL2561()


## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit

# This function lets you run code on exit, including functions from myDigitalLightSensor
def exitHandler():
	print "Exiting"
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)


while(1):
	print "Light value is " + str(myDigitalLightSensor.getLux())
	time.sleep(1)
	


Moisture Sensor Code

http://seeedstudio.com/wiki/Grove_-_Moisture_Sensor

import time, sys, signal, atexit
import pyupm_grovemoisture as upmMoisture

# Instantiate a Grove Moisture sensor on analog pin A0
myMoisture = upmMoisture.GroveMoisture(0)


## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit

# This function lets you run code on exit, including functions from myMoisture
def exitHandler():
	print "Exiting"
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)


# Values (approximate):
# 0-300,   sensor in air or dry soil
# 300-600, sensor in humid soil
# 600+,    sensor in wet soil or submerged in water

# Read the value every second and print the corresponding moisture level
while(1):
	moisture_val = myMoisture.value()
	if (moisture_val >= 0 and moisture_val < 300):
		result = "Dry"
	elif (moisture_val >= 300 and moisture_val < 600):
		result = "Moist"
	else:
		result = "Wet"
	print "Moisture value: {0}, {1}".format(moisture_val, result)
	time.sleep(1)


Temperature Sensor

http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor

Notes: Sometimes the sensor gives odd values, but they're consistent so you can just add the deviation for a more true reading.

Where it says:

celsius = temp.value()

Write:

celsius = temp.value() + [Deviation]

Note this is an analog temperature sensor.
#raw mraa reader
# From the seed studio page http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor
#
import mraa
import time
import math

B=3975
ain = mraa.Aio(1)
while(1):
	a = ain.read()
	resistance = (1023-a)*10000.0/a
	temp = 1/(math.log(resistance/10000.0)/B+1/298.15)-273.15
	print "Temperature now is " + str(temp)
	time.sleep(1)
Analog reader using the UPM library
import time
import pyupm_grove as grove

# Create the temperature sensor object using AIO pin 3
temp = grove.GroveTemp(3)
print temp.name()

# Read the temperature ten times, printing both the Celsius and
# equivalent Fahrenheit temperature, waiting one second between readings
for i in range(0, 10):
    celsius = temp.value()
    fahrenheit = celsius * 9.0/5.0 + 32.0;
    print "%d degrees Celsius, or %d degrees Fahrenheit" \
        % (celsius, fahrenheit)
    time.sleep(1)

# Delete the temperature sensor object
del temp

UV Sensor

http://www.seeedstudio.com/wiki/Grove_-_UV_Sensor

UV Sensor example using UPM library
import time, sys, signal, atexit
import pyupm_guvas12d as upmUV

# Instantiate a UV sensor on analog pin A1
myUVSensor = upmUV.GUVAS12D(1);

# analog voltage, usually 3.3 or 5.0
GUVAS12D_AREF = 5.0;
SAMPLES_PER_QUERY = 1024;


## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit

# This function lets you run code on exit, including functions from myUVSensor
def exitHandler():
	print "Exiting"
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

#### Forever Loop
while(1):
	s = ("AREF:  {0}, "
	"Voltage value (higher means more UV): "
	"{1}".format(GUVAS12D_AREF,
	myUVSensor.value(GUVAS12D_AREF, SAMPLES_PER_QUERY)))
	print s
	time.sleep(1)

Water Sensor

http://www.seeedstudio.com/wiki/Grove_-_Water_Sensor

The water sensor is a simple digital input. It operates like a switch - when water is present it returns true.
import time, sys, signal, atexit
import pyupm_grovewater as upmGrovewater

# Instantiate a Grove Water sensor on digital pin D3
myWaterSensor = upmGrovewater.GroveWater(3)

## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit

# This function lets you run code on exit, including functions from myWaterSensor
def exitHandler():
	print "Exiting"
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)


while(1):
	if (myWaterSensor.isWet()):
		print "Sensor is wet"
	else:
		print "Sensor is dry"
	time.sleep(1)

Step 4: Some Sensors Require Extra Care

Some of the sensors may take extra steps for proper use in a field system.

Inserting a Relay to Control Sensor Power

For example the MQ5 Gas Sensor will use a lot of power for its heater module. If the system is being run on batteries, with a long rest period between sensing, it would be good to power the sensor down and restart it each time. While this conserves energy, it will require using a relay to power cycle the sensor.

This will require cutting the Grove cables and inserting longer wires in the power line. These will connect to the service lines of a relay module.

The relay module will be activated, a delay inserted to allow sensor to warm up, the readings taken, and then the relay will be deactivated.

The delay time used will depend heavily on the particular sensor used. Some may need only short spin up time. Others may require several seconds.

Step 5: CSV File Writer Python App

We want to test the abiltiy of python to write a CSV file that can be transferred to the mobile device

This program makes a CSV file with random values. You can open up and look at this random data in excel or other spreadsheet application.

# python 
# code to try out creating file and writing random numbers to it as a CSV
#

import time
import csv
import random

filename = time.strftime("CSVTest_%Y%m%d-%H%M%S.csv")
print "CSV Test app writing to " + filename
ofile = open(filename,"wb")
writer = csv.writer(ofile)

# add a header row to the file
headerrow = ["timestamp", "r1", "r2", "3","r4"]
writer.writerow(headerrow)
# loop for a bit, filling CSV with random numbers
for i in range(1, 100):
	print ". " + str(i)
	a = [time.strftime("%Y%m%d-%H%M%S"), random.random(), random.random(), random.random(),random.random()]
	writer.writerow(a)
	# might delay a tad here
	time.sleep(0.1)
# and close up to insure data written
ofile.close()
print "CSV Test app finished writing to " + filename

Here is the first few lines of the output. Note that because we are only doing a very short sleep, the timestamp does not increment often....

timestamp,r1,r2,3,r4
20151108-163139,0.5611851908690764,0.9682908848336642,0.051898718146653255,0.46638907621025094
20151108-163139,0.2992019135615285,0.3032409660800295,0.2903114781088916,0.7414746296149242
20151108-163139,0.19505808003251446,0.9916962521953846,0.26570955264204754,0.05736706066844499
20151108-163140,0.018853735834572838,0.4715504160072215,0.5523955022073094,0.46721875406085145
20151108-163140,0.25016277802890174,0.9891860893746997,0.7843232247320402,0.09506447658618244
20151108-163140,0.1918999623831974,0.1725005468544567,0.8327705112809914,0.5925831310566942
20151108-163140,0.94979589120367,0.32612863030201733,0.2880595392950547,0.612279278496031
20151108-163140,0.9737341491740938,0.7065950964196421,0.6959148559606184,0.6186285831562987
20151108-163140,0.6852278959748995,0.6704713231460842,0.5289204781135399,0.45135936062172444
20151108-163140,0.20676111510524253,0.8315171508852308,0.8076818477009704,0.9064169920296251
20151108-163140,0.21963101883403946,0.64327051072023,0.5028898350238824,0.8952101259289462
20151108-163140,0.49839982827953144,0.5077388790381442,0.3336229661903203,0.3524602876830274
20151108-163141,0.6739008572186248,0.22729148491846618,0.4625338157673764,0.05602401248304467
20151108-163141,0.9512747562784171,0.8903159072909446,0.1226888287229666,0.2579334433111614
20151108-163141,0.6783888155545313,0.5032197912068163,0.7283557762660968,0.046661573193862105
20151108-163141,0.3351966897072176,0.5115108087239881,0.8915816805305554,0.3174225856596643
20151108-163141,0.6065222140578028,0.3643585258910006,0.12115528881182158,0.6684725350093842
20151108-163141,0.18059908063925567,0.40649070745137417,0.6173662817134156,0.45163939075016046

Step 6: Integated Application to Save Sensor Data to CSV File

Once the sensors have been tested and proven using the Unit Testing, they are integrated into the Python Application. Each sensor will require its import, setup, and read functions. Not all sensors need to be read on the same schedule but it will help if a common time is used. Some sensors may need some time to warm up if they are put into a hibernation mode (eg. Gas Sensor).

The python app needs to

  1. import the sensor library
  2. create sensor instance
  3. Sensing Loop - called on periodic basis
    1. prepare sensors
    2. read sensors
    3. release sensors
    4. open CSV file for appending
    5. add sensor values to list object in known order
    6. write the CSV line to file
    7. close CSV file

This example program program brings all the sensors taught in a CSV file. This again is a test app on the way to the final application. At this point we dont have the prepare sensors/open/close file in the loop section.

#python 
# sensor integration and output to CSV file<br>#
import time, sys, signal, atexit
import csv
import random
import pyupm_gas as upmGas
import pyupm_guvas12d as upmUV
import pyupm_grove as grove
import pyupm_tsl2561 as upmTsl2561
import pyupm_grovewater as upmGrovewater
import pyupm_grovemoisture as upmMoisture
##############################################
## Exit handlers ##<br># This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit
# This function lets you run code on exit, including functions from myMQ5
def exitHandler():
	print "Exiting"
	sys.exit(0)
# Register exit handlers<br>atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

##############################################
# Attach gas sensor to AIO0
myMQ5 = upmGas.MQ5(0)
threshContext = upmGas.thresholdContext()<br>threshContext.averageReading = 0
threshContext.runningAverage = 0
threshContext.averagedOver = 2</p><p># Infinite loop, ends when script is cancelled<br># Repeatedly, take a sample every 2 microseconds;
# find the average of 128 samples; and
# print a running graph of dots as averages
#mybuffer = upmGas.uint16Array(128)
#while(1):
#	samplelen = myMQ5.getSampledWindow(2, 128, mybuffer)
#	if samplelen:
#		thresh = myMQ5.findThreshold(threshContext, 30, mybuffer, samplelen)
#		myMQ5.printGraph(threshContext, 5)
#		if(thresh):
#			print "Threshold is ", thresh
# function to read and average
gasbuffer = upmGas.uint16Array(128)
gasThresh = 0
gasAvg = 0
def readGasMQ5():
	print "readMQ5"
	samplelen = myMQ5.getSampledWindow(2, 128, gasbuffer)
	print "sampleLen " +str(samplelen)
	if samplelen:
		print "calc threshold"
		gasThresh = myMQ5.findThreshold(threshContext, 30, gasbuffer, samplelen)
	print "gas avg"
	gasAvg = myMQ5.getSample()
##############################################
# Instantiate a UV sensor on analog pin A1
myUVSensor = upmUV.GUVAS12D(1);
# analog voltage, usually 3.3 or 5.0
GUVAS12D_AREF = 5.0;
SAMPLES_PER_QUERY = 1024;
#	s = ("AREF:  {0}, "
#	"Voltage value (higher means more UV): "
#	"{1}".format(GUVAS12D_AREF,
#	myUVSensor.value(GUVAS12D_AREF, SAMPLES_PER_QUERY)))
# myUVSensor.value(GUVAS12D_AREF, SAMPLES_PER_QUERY)</p>

>##############################################
# Soil Moisture to A2
# Instantiate a Grove Moisture sensor on analog pin A2
myMoisture = upmMoisture.GroveMoisture(2)</p><p># Values (approximate):<br># 0-300,   sensor in air or dry soil
# 300-600, sensor in humid soil
# 600+,    sensor in wet soil or submerged in water</p><p>#moisture_val = myMoisture.value()
##############################################
# Temperature to A3
temp = grove.GroveTemp(3)
celsius = 0
farenheit = 0
#print temp.name()
def readtemperature():
	celsius = temp.value()
    	fahrenheit = celsius * 9.0/5.0 + 32.0;
##############################################
# Digital Light to I2C
myDigitalLightSensor = upmTsl2561.TSL2561()
#print "Light value is " + str(myDigitalLightSensor.getLux())
##############################################
# Water sensor to D3
myWaterSensor = upmGrovewater.GroveWater(3)
#if (myWaterSensor.isWet()):
#		print "Sensor is wet"
##############################################
# setup output file
filename = time.strftime("FLEBAC%Y%m%d-%H%M%S.csv")


ofile = open(filename,"wb")
writer = csv.writer(ofile)</p><p># Write a header line for sensors<br># A0-1 I2C then digital in order
headerRow = ["timestamp", 
	"MQ5GasTresh", 
	"MQ5Average", 
	"UV", 
	"Moisture", 
	"Celsius", 
	"Digital Light", 
	"Wet",
	]

print "Starting Loop"
for i in range(1, 100):
	print "loop "+ str(i)
	readGasMQ5()
	
	a = [gasThresh, gasAvg, 
		myUVSensor.value(GUVAS12D_AREF, SAMPLES_PER_QUERY), 
		myMoisture.value(),
		temp.value(),
		myDigitalLightSensor.getLux(),
		myWaterSensor.isWet(),]
	writer.writerow(a)
	time.sleep(0.10) 
<p>ofile.close()</p>

Step 7: Copy CSV File to Mobile Device

A key design aspect of the AINA is that the sensor box can be located in a remote location with no network connections. The data is collected locally and then transferred to some mobile device for transport to a location with network access. The transfer mechanism would use the Edison's Bluetooth capability, as the simplest wireless connection with adequate bandwidth. Most mobile devices (cell phones) have a built in GPS. It will be a simple manual step to record the GPS location when data is picked up from the AINA.

The initial AINA concept used a custom App on an Android or IOS mobile device to provide the transfer and transport. We found the MIT App Inventor as a rapid tool for developing Android applications and spent some time learning to use it. It provides a simple drag&drop visual programming style, akin to Scratch. We found it could access the Bluetooth capabilities. The transfer would also require a special comm protocol between the Edison and Android device. This would be a simple packet exchange, sending csv rows in each packet.

However, after a bit more design time, we realized that the tools to provide the transfer via Bluetooth already existed using the standard SFTP (secure file transfer protocol). This eliminates the need for special transfer code and custom application. It allows any bluetooth sftp capable device (phone, tablet, laptop, etc) to provide the data collection service.

So to move a file, we need to:

  1. enable bluetooth on Edison and mobile device
    1. mobile device is specific to vendor,
  2. enable FTP Service
    1. install a SFTP bluetooth file transfer tool on mobile device
      1. android: https://play.google.com/store/apps/details?id=it....

      2. OSX/Windows: filezilla https://filezilla-project.org/

      3. IOS: (untested) BlueMe https://itunes.apple.com/us/app/blueme/id456598582...

  3. enable ftp server on Edison
  4. Pair the devices (ideally pre-paired so can skip this step)
  5. transfer the files
  6. shutdown server and bluetooth on Edison (to conserver power)

The Edison needs to conserve power, so it should be able to turn on/off the bluetooth connection. It should also pair only with trusted devices (to avoid tampering). This makes for a bit more complex user interface.

Step 8: Enabling Bluetooth and SFTP Server on Edison

Bluetooth on the Intel Edison is discussed briefly in the Getting Started with Bluetooth Guide and at length in the downloadable pdf Intel® Edison Products Bluetooth® User Guide.

The first step is to remove the softblock on bluetooth using the command line:

rfkill unblock bluetooth

then the bluetoothclt tool is used to enable the various aspects and control pairing.

bluetoothctl
  >power on
  >discoverable on
  >agent on 
  >default-agent 
  >pairable on

To initiate paring, the mobile device is placed in scanning mode, then use bluetoothclt to find the device, connect and trust it. The 'devices' command will list all visible devices. Note the MAC Address of the mobile devices and use it in the pair, trust and connect commands...

bluetoothclt
 > devices
(list of visible mac addresses shown)
 > pair devices_mac_address
(may request a PIN and/or request authorization yes/no, answer yes, not y)
 > trust device_mac_address
 > connect device_mac_address
 > quit

This works ok if you have a command line interface (CLI) connection to the Edison (i.e. console). The AINA, however, is supposed to have a very minimal human interface, once it has left the lab. (while in lab, different sensors may be configured in, altering code, wiring, etc.) This requires that the Bluetooth interface for the field be as simple as possible.

Ideally the AINA would pair with a mobile device as simply as one pairs with a new headset or speaker. Unfortunately, the Edison seems to lack a way to automate the pairing request/acceptance.

A mobile device can be Trusted by AINA using the console in the lab. This should add it to the known devices list and make pairing easier in future. It still requires console interaction to set up, but at least the pairing in the field would be easier.

Our investigations turned up a number of posts about this on the web, some seeming to provide partial solutions. We were able to get an android device paired and transfer files. Once. We are not quite sure which set of incantations made this happen. We are continuing to explore this issue.

Some of the web postings:

list items here.. from Intel Docs; from Intel Forums; Other sites (tool ref, etc)

requires knowing how to reconfigure the Edison system (rfkill systemclt opkg, etc)

Step 9: Adding UI to Invoke Bluetooth

The AINA has a no human interface so far, but now we need a way to interact with it to enable Bluetooth.

The simplest interface is to add a button and the LED Bar. When the button is pressed, the edison will turn on bluetooth and start the paring. During this time the LED Bar will cycle, sort of a Larson Scanner effect, providing visual feedback.

Button Unit Test -

  • basic read test
  • invokes external shell/application

LED Bar Larson Scanner Test

This python code instantiates an LED Bar object and implements the Larson Scanner effect...
import time, sys, signal, atexit
import pyupm_my9221 as upmMy9221

# Instantiate a MY9221, we use D2 for the data, and D3 for the
# data clock.  This was tested with a Grove LED bar.
myLEDBar = upmMy9221.MY9221(6, 7)


# Exit handlers
def SIGINTHandler(signum, frame):
	raise SystemExit

def exitHandler():
	myLEDBar.setBarLevel(0, True)
	print "Exiting"
	sys.exit(0)

# This function lets you run code on exit
atexit.register(exitHandler)
# This function stops python from printing a stacktrace when you hit control-C
signal.signal(signal.SIGINT, SIGINTHandler)


directionBool = True
level = 1

x = 0
while(1):
	# If it's less than 10
	# light up the LED now
	# call show_LED again in 50 ms
	if (level <= 10):
		myLEDBar.setBarLevel(level, directionBool)
		level += 1
	# Switch LED lighting directions between lighting cycles
	else:
		directionBool = not directionBool
		level = 1
		time.sleep(1)
	time.sleep(.05)
	x += 1

Start/Monitor Bluetooth Invocation

See the Bluetooth setup section for this. At present we are still investigating how to turn on/off/pair bluetooth functionality from a script.

Step 10: Environmental Enclosure

The AINA kit is intended to be left outside for extended periods. This requires some environmental protection, however it also requires the sensors be exposed to the elements which they are sensing. Examples of similar environmental enclosures can be found in weather systems.

Grove Kit Box

We started the AINA using the Grove kit's rather nice enclosure box for prototyping. This is a nicely designed acrylic box using magnetic clasps and reinforced packing tape hinges. It provides a convenient carry/storage box that folds out flat to expose the sensors (and processor) for development. It is not adequate for a field unit but does serve well as a test bench. The flat layout would require an additional cover for the main board. In the box form with sensors mounted on the outside surface, or other platform, it can serve a bit better. but still leaves much to be desired

Basic Environmental Shielding

A Hawaiian style Hale structure could provide reasonable exposure & protected area. The open sides allow for air flow while, the peaked roof provides protection from rain and sun. This could be adapted to AINA by using a solid surface such as acrylic or metal for the roof.

hawaiian hale

Better Main Enclosure

    The Main Enclosure (aka The Box) must provide weather proof, yet ventilated housing of the main Edison stack. There are commercial off-the-shelf (COTS) solutions such as the Adafruit Large Plastic Project Enclosure - Weatherproof with Clear Top or the selection from Granger

    Additionally there are DIY solutions. Instructables is full of ideas such as this basket and tarp which could easily be adapted for AINA. There are even more options for a maker with access to a laser cutter and 3d printer/CAD system. Check your favorite How-To sites like Make Mag, YouTube, and of course Instructables.

    Additional Sensor Considerations

    Not all sensors can mount on the exterior of the main enclosure. Some sensors need different orientation than flat sides of box (eg. light sensors, gas sensor). Other sensors may be too large (eg dust sensor). And yet other sensors may need to be some distance from the main box and perhaps stuck in the ground (soil moisture sensor).

    Sensors need their own enclosures that shield some of their parts, yet adequately expose them to the environment they are intending to sense.

    A major need for the sensors is a better cable system than the Grove. These, while ok for bench prototyping, are not appropriate for exposure to the elements. The connectors must provide a weatherproof connection between the main box and the sensors. The cable system needs to provide for extension cables of various lengths to allow sensors to be placed at a short distance from the main box.

    • need better connectors than grove
      • Weather Resistant
      • Allow for extension cables of various lengths
      • Adafruit (and elsewhere) Waterproof Polarized 4-Wire Cable Set
      • one end (female?) connectors wired to The Box (panel mounts?)
      • other end wired to sensor in its enclosure
      • extension cables of various lengths allow sensors to be placed at a distance from The Box.
      • other end, probably with extension wires (cat6) wired to sensor module
      • require waterproof heat shrink on connection to extension wire.
      • w/o extension

    Exact selection is left as exercise to the student dependent on the selected sensor's requirements.

    Step 11: Solar Power and Batteries

    The field use of the AINA system may require long duration batteries with solar charging.

    Fortunately a Solar power for USB (or recharger) is a well solved problem. There are a large number of Instructables for Solar USB Charger. Maker vendors such as Adafruit sell the components to make your own charger. There are also commercial off-the-shelf (COTS) solutions such as the Goal Zero Venture 30 Solar ReCharging Kit. There are similar systems available through various online sources. The battery pack should be large enough to deliver enough power to the AINA for a day's operation. The panel should be large enough to recharge the battery pack with a half day of good sunlight. Experience with the larger USB battery packs (15-20AmpHours) has been that they can take a long time to charge.

    The power requirements of a particular AINA configuration will be very dependent on the sensors included and their duty cycle. Selection of an appropriate system is left as an exercise to the student.

    Step 12: Summary and Futures

    The AINA project shows a basic platform on which a field sensor system might be built. There are quite a few TBDs to make this a true field system:

    • Environmental Enclosure & Cables
    • Bluetooth Configuration
    • Easier Sensor Configuration
    • Solar Power System

    Thanks to Maui Makers Inc, and the students of Kihei Charter High School.