Tuesday, January 24, 2017

BeagleBone Green Wireless IoT Developer Prototyping Kit

Have you noticed that Google Cloud is promoting an IoT Developer Prototyping Kit which features the BeagleBone Green Wireless (BBGW)? I purchased one, because I was hoping for better instructions on using the Grove System w/BBGW.

Sadly, the only documentation included w/the proto kit is a lame brochure w/a cloud solutions URL with unhelpful Arduino examples.  Yaay for Arduino, but I bought the BBGW kit.

Fine.  Challenge accepted.  Here are some notes on using BBGW and Grove System.

There are dedicated images for the BBGW and any Debian reference (within this post) is tied to bone-debian-8.6-seeed-iot-armhf-2016-11-06-4gb.img

"Grove is a modular, standardized connector prototyping system." which is a good single line summary.  The catalog is full of many sensors, switches and shiny, blinky things which plug into standard connectors.  The BBGW exposes two Grove connectors, one for I2C and the other to UART.  Two connections are OK to start, but you most likely will want the Grove Base Cape (included in proto kit) because this offers more connections and access to the ADC.

If you already know the BB, you will not be surprised to learn that the Grove connectors map directly to P8/P9 and there is no added functionality apart from the connectors.  Put another way, anything you can implement w/Grove could also be implemented the usual way via overlays and P8/P9.

There has to be software to control the interfaces and BBGW Grove promotes MRAA as a wrapper to the BBGW devices.  MRAA comes w/the Debian Seeed image and has (yet another) pin encoding scheme.  Look here for pin mapping.  The Debian Seeed image also has example python code in /usr/share/mraa/examples/python

Start easy w/a GPIO demo "blink-io8.py"

import mraa
import time


# Using BBG GPIO_51
x = mraa.Gpio(62)
x.dir(mraa.DIR_OUT)

while True:
  x.write(1)
  time.sleep(0.2)
  x.write(0)
  time.sleep(0.2)


Note the "mraa.Gpio(62)" which maps to P9_16 on BBGW and has a dedicated socket on the Grove Base Cape (look at the middle row, the GPIO are silk screened next to the Grove sockets).

Use the 3 axis accelerometer from the proto kit as an I2C example.  One of the Seeed example worked, scroll to item "03 How to use Grove - 3-Axis digital Accelerometer (16g)" for a python example.

Now for an ADC example, look at this Seeed project (scroll to "02 How to use Grove - Light Sensor & Temperature Sensor").  The wiring diagram is OK (i.e light sensor to AIN0 and temperature to AIN2) but the code is not quite working.  Here is the corrected code:
import time
import pyupm_grove as grove

light = grove.GroveLight(1)
temp = grove.GroveTemp(3)

while True:
 print light.name() + " raw value is %d" % light.raw_value() + ", which is roughly %d" % light.value() + " lux"
 celsius = temp.value()
 fahrenheit = celsius * 9.0/5.0 + 32.0
 print "%d degrees Celsius, or %d degrees Fahrenheit" % (celsius, fahrenheit)
 time.sleep(2)

What about those two Grove connectors on the BBGW?  One is for UART, the other is I2C, both support GPIO.  Here is an example Python script which uses the UART connector w/a button:
import mraa
import time

x = mraa.Gpio(68)
x.dir(mraa.DIR_IN)

while True:
 time.sleep(1)
 if x.read() > 0:
  print 'button press'
 else:
  print 'button not press'


BeagleBone Black vs BeagleBone Green

Yet another post comparing the BeagleBone Green Wireless (BBGW) to the BeagleBone Black.

Mouser has a great (hardware) comparison.

The links on the BBGW documentation pamphlet are mostly wrong, but you can find the BBGW wiki here (worth a visit).

Brief recap of differences between the BBB and BBGW hardware: HDMI is gone along w/the 5V barrel jack.  USB connector has gone from mini to micro, and if you need 5V it must be injected via the P9 header.  The RJ45 (ethernet) connector has been removed, put there are now bluetooth and WiFi radios.  There are now 4 USB ports which are tall and will interfere w/most capes.  

There are dedicated images for the BBGW and any Debian reference (within this post) is tied to bone-debian-8.6-seeed-iot-armhf-2016-11-06-4gb.img

The BBGW I2C bus maps i2c-0 and i2c-2 while BBB maps i2c-0 and i2c-1.  Expect this to be an issue when migrating applications from BBB to BBGW.

BBGW $SLOTS is at /sys/devices/platform/bone_capemgr/slots.
root@beaglebone:~# cat $SLOTS
0: PF----  -1
1: PF----  -1
2: PF----  -1
3: PF----  -1



Sunday, January 15, 2017

BeagleBone Green Wireless as a LAMP Server

This post demonstrates how to configure a BeagleBone Green Wireless (BBGW) first for WiFi tethering and then as a LAMP server.  For context, I have an IoT project (not described here) which uses the BBGW for data collection which can be examined using a web browser.

Flash your BBGW w/the latest image.  I am using "Jessie for SeeedStudio BeagleBone GreenWireless" (bone-debian-8.6-seeed-iot-armhf-2016-11-06-4gb.img).

After updating the BBGW image, log in to configure WiFi using connmanctl(1), there are example instructions in /etc/network/interfaces.

Now that you have internet connectivity, update the software using apt-get(8):
  • "apt-get update"
  • "apt-get upgrade"
Perform a gratuitous reboot for luck.

When the BBGW returns from reboot,  you should detect a fresh WiFi SSID in the form "BeagleBoneXXXXXX" where XXXXXX are integers.  This SSID was created by wifidog which is part of the BBGW Debian distribution.  

I don't need a captive portal for my purposes, so login to BBGW and invoke "apt-get remove wifidog-gateway" then reboot.

Now when the BBGW returns from reboot, you should detect a fresh WiFi SSID in the form "BeagleBone-XXXX" where XXXX are hex values representing part of the MAC address.

/etc/default/bb-wl18xx contains some tweakable parameters, such as SSID base.

/tmp/hostapd-wl18xx.conf is the actual hostapd(8) configuration file, note the wpa_passphrase "BeagleBone"


SoftAp0 is the WAP device:
root@beaglebone:/etc/default# ifconfig SoftAp0
SoftAp0   Link encap:Ethernet  HWaddr b0:d5:cc:ff:65:be  
          inet addr:192.168.8.1  Bcast:192.168.8.255  Mask:255.255.255.0
          inet6 addr: fe80::b2d5:ccff:feff:65be/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5220 errors:0 dropped:3 overruns:0 frame:0
          TX packets:703 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 

          RX bytes:1328274 (1.2 MiB)  TX bytes:122059 (119.1 KiB)

From your laptop, connect to the BeagleBone device just as you would any other WAP.

Apache is configured for port 8080.  Verify you can connect to apache2(8) by visiting http://192.168.8.1:8080/ with your browser.

Assuming happy browser response, you now have a BBGW ready for a LAMP stack.  Note that the BBGW still has internet connectivity through wlan0 as configured earlier.

Now install mysqld(8) by invoking "apt-get install mysql-server" - when finished, verify a happy installation using mysql(1) and ensure you can at least login to mysqld(8).

Now install PHP, et al by invoking "apt-get install php5 libapache2-mod-php5 php5-mysql" - when finished, verify a happy installation by placing the usual phpinfo script into /var/www/html and visiting w/a browser.