A bit of NYE colour for Holiday!

Here’s a small Python program that uses the SecretAPI to send a stream of randomly coloured lights scrolling down your Holiday.

Usage: python nye.py ip-address-of-holiday optional-frame-rate

And here’s the code.  Copy and paste it in and have fun!

#!/usr/bin/python
#
"""
Holiday class implementation for the Secret API for Holiday by Moorescloud

Homepage and documentation: http://mooresclouddev.markpesce.com/

Copyright (c) 2013, Mark Pesce.
License: MIT (see LICENSE for details)
"""

__author__ = 'Mark Pesce'
__version__ = '1.0b4'
__license__ = 'MIT'

import sys, array, socket

class HolidaySecretAPI:

	NUM_GLOBES = 50

	# Storage for all 50 globe values
	# 
	globes = [ [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00] ]

	def __init__(self, addr=''):
		"""If remote, you better supply a valid address.  
		We'll throw an exception when you don't do this."""
		self.addr = addr    # IP address we're chatting with.
		self.port = 9988	# Secret API port
		self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP

	def setglobe(self, globenum, r, g, b):
		"""Set a globe"""
		if (globenum < 0) or (globenum >= self.NUM_GLOBES):
			return
		self.globes[globenum][0] = r
		self.globes[globenum][1] = g
		self.globes[globenum][2] = b

	def fill(self, r, g, b):
		"""Sets the whole string to a particular colour"""
		for e in self.globes:
			e[0] = int(r)
			e[1] = int(g)
			e[2] = int(b)

	def getglobe(self, globenum):
		"""Return a tuple representing a globe's RGB color value"""
		if (globenum < 0) or (globenum >= self.NUM_GLOBES):
			return False
		return (self.globes[globenum][0], self.globes[globenum][1], self.globes[globenum][2])

	def chase(self, direction="True"):
		"""Rotate all of the globes around - up if TRUE, down if FALSE"""
		return

	def rotate(self, newr, newg, newb, direction="True"):
		if direction == "True":
			for i in range(1, self.NUM_GLOBES):
				self.globes[self.NUM_GLOBES - i][0] = self.globes[self.NUM_GLOBES - (i+1)][0]
				self.globes[self.NUM_GLOBES - i][1] = self.globes[self.NUM_GLOBES - (i+1)][1]
				self.globes[self.NUM_GLOBES - i][2] = self.globes[self.NUM_GLOBES - (i+1)][2]
			self.setglobe(0, newr, newg, newb)
			return
		else:
			return		

		"""Rotate all of the globes up if TRUE, down if FALSE
		   Set the new start of the string to the color values"""
		return

	def render(self):
		"""The render routine sends out a UDP packet using the SecretAPI"""
		# Create the 160-byte array of data
		packet = array.array('B', [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])  # initialize basic packet, ignore first 10 bytes
		for g in self.globes:
			packet.append(g[0])
			packet.append(g[1])
			packet.append(g[2])

		# Send the packet to the Holiday
		self.sock.sendto(packet, (self.addr, self.port))
		return

# Just some basic testerating from the command linery
#
if __name__ == '__main__':
	if len(sys.argv) > 1:
		hol = HolidaySecretAPI(addr=sys.argv[1])
	else:
		sys.exit(1)
	if len(sys.argv) > 2:
		fps = float(sys.argv[2])
	else:
		fps = 10.0
	rate = 1.0/fps
	import random, time
	clr = [0, 1, 2]
	while True:
		clr[0] = random.randint(0, 255)
		clr[1] = random.randint(0, 255)
		clr[2] = random.randint(0, 255)
		clr[random.randint(0,2)] = 0  # knock out one colour component for richness
		hol.rotate(clr[0], clr[1], clr[2])
		hol.render()
		time.sleep(rate)

Update: Had a little think about it, and added some interpolation code. Now the string generates a random colour and moves from that to another random colour in a smooth transition. Essentially it means the globes become a series of rainbow washes moving down the string.

Usage: python nyebow.py ip-of-holiday frames-per-second frames-per-transition (last two are optional and both default to 10)

#!/usr/bin/python
#
"""
Holiday class implementation for the Secret API for Holiday by Moorescloud

Homepage and documentation: http://mooresclouddev.markpesce.com/

Copyright (c) 2013, Mark Pesce.
License: MIT (see LICENSE for details)
"""

__author__ = 'Mark Pesce'
__version__ = '1.0b4'
__license__ = 'MIT'

import sys, array, socket

class HolidaySecretAPI:

	NUM_GLOBES = 50

	# Storage for all 50 globe values
	# 
	globes = [ [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00],
	[ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00], [ 0x00, 0x00, 0x00] ]

	def __init__(self, addr=''):
		"""If remote, you better supply a valid address.  
		We'll throw an exception when you don't do this."""
		self.addr = addr    # IP address we're chatting with.
		self.port = 9988	# Secret API port
		self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP

	def setglobe(self, globenum, r, g, b):
		"""Set a globe"""
		if (globenum < 0) or (globenum >= self.NUM_GLOBES):
			return
		self.globes[globenum][0] = r
		self.globes[globenum][1] = g
		self.globes[globenum][2] = b

	def fill(self, r, g, b):
		"""Sets the whole string to a particular colour"""
		for e in self.globes:
			e[0] = int(r)
			e[1] = int(g)
			e[2] = int(b)

	def getglobe(self, globenum):
		"""Return a tuple representing a globe's RGB color value"""
		if (globenum < 0) or (globenum >= self.NUM_GLOBES):
			return False
		return (self.globes[globenum][0], self.globes[globenum][1], self.globes[globenum][2])

	def chase(self, direction="True"):
		"""Rotate all of the globes around - up if TRUE, down if FALSE"""
		return

	def rotate(self, newr, newg, newb, direction="True"):
		if direction == "True":
			for i in range(1, self.NUM_GLOBES):
				self.globes[self.NUM_GLOBES - i][0] = self.globes[self.NUM_GLOBES - (i+1)][0]
				self.globes[self.NUM_GLOBES - i][1] = self.globes[self.NUM_GLOBES - (i+1)][1]
				self.globes[self.NUM_GLOBES - i][2] = self.globes[self.NUM_GLOBES - (i+1)][2]
			self.setglobe(0, newr, newg, newb)
			return
		else:
			return		

		"""Rotate all of the globes up if TRUE, down if FALSE
		   Set the new start of the string to the color values"""
		return

	def render(self):
		"""The render routine sends out a UDP packet using the SecretAPI"""
		# Create the 160-byte array of data
		packet = array.array('B', [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])  # initialize basic packet, ignore first 10 bytes
		for g in self.globes:
			packet.append(g[0])
			packet.append(g[1])
			packet.append(g[2])

		# Send the packet to the Holiday
		self.sock.sendto(packet, (self.addr, self.port))
		return

# Just some basic testerating from the command linery
#
if __name__ == '__main__':
	if len(sys.argv) > 1:
		hol = HolidaySecretAPI(addr=sys.argv[1])
	else:
		sys.exit(1)

	if len(sys.argv) > 2:
		fps = float(sys.argv[2])
	else:
		fps = 10.0
	rate = 1.0/fps

	if len(sys.argv) > 3:
		steps = int(sys.argv[3])
	else:
		steps = 10

	import random, time
	sclr = [ 0, 0, 0 ]
	eclr = [ 0, 0, 0 ]
	diff = [ 0.0, 0.0, 0.0 ]
	clr = [0, 1, 2]
	while True:

		# Copy the end colour to the start colour
		sclr[0] = eclr[0]
		sclr[1] = eclr[1]
		sclr[2] = eclr[2]

		# Generate a random colour end colour
		eclr[0] = random.randint(0, 255)
		eclr[1] = random.randint(0, 255)
		eclr[2] = random.randint(0, 255)
		eclr[random.randint(0,2)] = 0  # knock out one colour component for richness

		# Calculate the difference per frame
		diff[0] = float((eclr[0] - sclr[0]) / steps)
		diff[1] = float((eclr[1] - sclr[1]) / steps)
		diff[2] = float((eclr[2] - sclr[2]) / steps)

		for i in range(steps):
			r = int(sclr[0] + (diff[0] * i))
			if (r < 0): 				r = 0 			elif (r > 255):
				r = 255
			clr[0] = r
			g = int(sclr[1] + (diff[1] * i))
			if (g < 0): 				g = 0 			elif (g > 255):
				g = 255
			clr[1] = g
			b = int(sclr[2] + (diff[2] * i))
			if (b < 0): 				b = 0 			elif (b > 255):
				b = 255
			clr[2] = b

			hol.rotate(clr[0], clr[1], clr[2])
			hol.render()
			time.sleep(rate)

Have fun!

Using the SecretAPI via PHP

There are two APIs you can use to manipulate the Holiday: the RESTful API, which has a bunch of methods or the SecretAPI, which uses crafted UDP packages to paint colours onto the Holiday light string directly. While the RESTful API has more functionality, the SecretAPI is much, much faster.

You can find a PHP class library to access the Holiday via the SecretAPI at https://github.com/Djelibeybi/PHP-Holiday-SecretAPI. Sample scripts are provided as well.

Bug reports, pull requests, comments welcome.

Currently, the following methods are defined:

setglobe($globenum, $r, $g, $b)
Sets the globe with number $globenum (base 0 to 49) to the colour represented by $r, $g and $b.
fill($r, $g, $b)
Fills the entire string, i.e. all globes, with the same colour represented by $r, $g and $b.
getglobe($globenum)
Returns an array of the RGB colour values for the globe with the number $globenum as represented internally within the object. Note that the SecretAPI doesn’t have a query mechanism, so we can’t actually retrieve the currently active value for the globe. This is the value we think the globe is.
render()
This crafts the 160-byte UDP packet and paints the current state of the globes onto the Holiday. Used after calling fill() or setglobe() to paint the values onto the light(s).

Using the RESTful API via PHP

There are two APIs you can use to manipulate the Holiday: the RESTful API, which has a bunch of methods or the SecretAPI, which uses crafted UDP packages to paint colours onto the Holiday light string directly. While the RESTful API has more functionality, the SecretAPI is much, much faster.

You can find a PHP class library to access the Holiday via the RESTful API at https://github.com/Djelibeybi/PHP-HolidayAPI. The GIT repository includes some sample scripts that use the class library.

Bug reports, pull requests, comments welcome.

Currently, the following methods are defined:

setglobe($globenum, $r, $g, $b)
Sets the globe with number $globenum (base 0 to 49) to the colour represented by $r, $g and $b.
fill($r, $g, $b)
Fills the entire string, i.e. all globes, with the same colour represented by $r, $g and $b.
getglobe($globenum)
Returns an array of the RGB colour values for the globe with the number $globenum as represented internally within the object. Note that the SecretAPI doesn’t have a query mechanism, so we can’t actually retrieve the currently active value for the globe. This is the value we think the globe is.
render()
This submits a JSON-encoded query to the RESTful API and paints the current state of the globes onto the Holiday. Used after calling fill() or setglobe() to paint the values onto the light(s).

The functions above are the base building blocks you can use to paint almost anything onto the Holiday string. However, there are also some pre-defined animations that can be accessed directly via the RESTful API. The first (and currently only) method implemented is for the Gradient API:

gradient($begin, $end, $steps)
Automatically animates a gradient between the RGB colour represented by the $start array and the $end array using $steps per second. The gradient method will automatically start the animation and return once the gradient has finished animating. If you call the render() method after using the gradient() method, it will repaint the previous state of the lights back onto the string.

Holideck – Development and Simulation for Holiday by MooresCloud

home screen for Holideck the Holiday simulator

We want everyone to be able to develop applications for Holiday by MooresCloud; but we’re still about 12 weeks away from shipping our first units.  In order to speed development (both internally and externally) we’ve put together a simulation and development environment which provides a platform that is roughly 99% identical to the code that will be running on the Holiday when it ships.

Holideck is a pure Python simulator for Holiday by MooresCloud, which allows anyone to write apps for the Holiday in two of its three available development environments – HTML5 Web apps using IoTAS, and pure Python.

To install Holideck on your own computer, type the following command into a terminal window (making sure that you’re in the directory where you want holideck installed):

% git clone https://github.com/moorescloud/holideck.git

You should now have a directory named holideck.

If you don’t want to use git, grab the ZIP archive and unzip it wherever you like.

Invocation

% python holideck.py

When holideck launches it opens two ports on the localhost, one for simulator access, the other presenting the web app interface to Holiday.

The HTML5 simulator simpype will try open port 8888; if that port is unavailable, it will increment the port number until it finds a free port.

IoTAS, the Internet of Things Access Server, will try to open port 80 (which is only possible if python has been run with root privleges), or if running as a user program, will try to open port 8080. This port is often occupied by other applications (Apache, Tomcat, etc), so IoTAS will increment the port number until it comes to an available port.

All of which is to say that the simulator could be found on port 8888, but might be at a higher port number, and IoTAS could be found on port 8080, but could easily be at a higher port number.

The port numbers are given in the output generated by holideck as it is initializing.

To quit holideck, simply type a Control-C in the terminal window.

Holideck – specifically IoTAS – currently produces voluminous output for debugging purposes. Eventually, this will be moved to a log.

Using Holideck

Holideck is designed to provide a complete simulation and development environment for Holiday by MooresCloud. It is implemented in pure Python.

Holideck is composed of three pieces:

simpype

Simpype is the HTML5-based simulator for the Holiday. Simpype simulates the 50 individually-addressible 24-bit colour globes on the Holiday.

To use simpype, point a browser to the simulator’s web page – generally that will be http://localhost:8888, with the caveats as given above.

You should see something like this:

simpype in browser

What looks like a dashed-line extending from the Holiday image on the left side of the page is actually the string of globes, with each globe initialized to black.

The Javascript in the page loaded by simpype will poll the simulator at approximately ten updates per second, so you do not need to reload the page to see updates to the simulation.

The simulator can be opened in multiple browsers simultaneously, with the caveat that each browser will poll the simulator at 10 Hz, so many browser windows pointing to a simulator instance will produce quite a bit of load on the simulator.

IoTAS

The Internet of Things Access Server, or IoTAS, provides both the RESTful interface to Holiday by MooresCloud and the web-based application, control and configuration interface for Holiday.

The interface for IoTAS looks best on a mobile device.

After holideck has been launched, point a mobile device to port 8080 (or possibly higher, with the caveats given above) on the computer running holideck.

For example, if the computer running holideck is named iris.local, you should point your mobile browser to http://iris.local:8080. The home screen for Holiday’s HTML5 web app interface should then load:

holiday home screen

To test holideck, tap on the ‘API demo’ icon, flip the switch, and – if the demo is working correctly – you should see a random selection of colors sent to the simulator.

IoTAS defines a detailed RESTful interface to Holiday by MooresCloud.

This will be documented in the holideck wiki.

Holiday web apps

MooresCloud has created a number of demonstration HTML5-based web apps. These can be used and adapted for your own web apps.

A number of these apps, although included within holideck, are not yet fully functional and should not be used.

The apps which are functional include:

Colorwheel – Select a colour from the colorwheel, and the entire string of lights on the simulator will reflect the color change.

API Demo – Generates 50 random colour triplets and sends them to the simulator.

NRL – Prebuilt color patterns for all 16 teams in Australia’s National Rugby League.

AFL – Prebuilt color patterns for all 18 teams in Australia’s Australian Footbal League.

Examples

The examples subdirectory contains two Python applications that illustrate some of the capabilities of Holiday by MooresCloud when connected to a process running either locally on the hardware, or externally on another computer.

Twug-of-War

Twug of War creates an animated Twitter tug-of-war between two competing hashtags.

It’s invoked as follows:

% python tow.py hashtag1 hashtag2

The first time the program is run, it will attempt to authorize itself with Twitter. A browser window should open, ask for your Twitter credentials if you’re not logged in (a Twitter account is a prerequisite for Twug-of-War), and, once logged in, will ask you to authorize the app. Once the app has been authorized, Twitter will provide a code that must be entered at the terminal prompt. Once authorized, Twug-of-War will be able to register a stream listener on Twitter.

The string will initialize to half green, and half blue, with a yellow counter in the middle of the string. As matching hashtags are seen in the Twitter ‘firehose’, the counter will move one directon or another. When the string is completely one colour, the program will terminate.

Soundlevel

Soundlevel turns the Holiday by MooresCloud into a real-time sound level monitor.

It requires some prerequisites to be installed, specifically PortAudio library and the PyAudio module. Consult the documentation at those websites for more details. (Ubuntu/Debian users can probably install both with sudo apt-get install python-pyaudio, but for OSX and Windows it’s considerably more involved.)

It’s invoked as follows:

% python soundlevel.py

In general the application will correctly detect and use the microphone input on the computer running Soundlevel, but that may not alway be the case.

Many thanks to Josh Deprez for Soundlevel.

More Caveats

Holideck has been tested on Linux (Ubuntu & Mint), OSX 10.7 & 10.8, and Windows 7/8.

This is a first release; there are bound to be numerous problems. We apologize in advance for this.

If you have any serious problems, please leave a message on this thread.

All of this code is released under the MIT License.

Holiday Hardware is Open Source

The Holiday controller is an open source hardware design, originally inspired by the Olimex OlinuXino (https://www.olimex.com/Products/OLinuXino/iMX233/) – a Freescale iMX233 based embedded linux development board.

Holiday-PCB-panel

We used the OlinuXino iMX233 Maxi and Micro boards during development and testing of both the Light and Holiday, before designing our own custom PCB layout to suit the form factor and specific requirements.  The Holiday also incorporates an ATmega328 (running the “Arduino” environment) that communicates with the Linux environment for handling control during Linux boot-up and providing the tight timing requirements of sending data to the WS2812 LEDs.

Holiday-PCB-front

Shown above and below are our revision 1 prototypes in a CNC’d plastic enclosure made specifically for use at PyCon Australia 2013.  The picture below also shows a 3 pin serial debug connected (at the centre top).

Holiday-PCB-rear

The revision 2 hardware design is in Altium Designer (v13) format, and the Altium files along with the BOM, PDF, and gerber outputs are now available under the Creative Commons Attribution Share-Alike license (http://creativecommons.org/licenses/by-sa/2.0/au/).

See the MooresCloud holiday-hardware github repo for the files.

Footnote by Kean 18Sep2013: Due to supply issues with the 16MHz crystal we included in the BOM, the production Holiday will actually use a 20MHz crystal for Y2 (the ATmega328 “Holidayduino”).  This leads to some special set up for compiling your own code in the Arduino environment.  I’ll be documenting this soon.

Powering Holiday from batteries

Our Holiday lights are designed to normally run from a 5V 3A mains power supply (we’ve been using the excellent Phihong PSAA15W-050V), but it is certainly possible to power them off a battery pack if you understand a few requirements & limitations.

LiPo_BEC_Supply

First, some typical Holiday usages will draw the following current from the power source:

–          Linux booted, but no LEDs on – approx. 180mA (0.18A)

–          As above with WiFi active – approx. 250mA (short bursts) (0.25A)

–          Medium brightness static colour or animation – approx. 1000mA (1.0A)

–          Bright colour – approx. 1400mA (1.4A)

–          Full brightness white – approx. 2000mA (2.0A)

For reliable operation of the main CPU and WiFi adapter, the power supply needs to be within +/- 5% of 5.0V – i.e. 4.75V to 5.25V.  If the voltage drops below about 4.7V into the controller, the CPU will likely detect a “brownout” condition and reboot.  The voltage drop along the cable out to all the LEDs isn’t so critical, and as along as the voltage to the LEDs at the far end of the string is above 3.4V or so, everything should be fine.  At about 3.4V the LEDs will begin to lose their “blue” brightness, but this amount of voltage loss should only happen at high currents on the cable.

One battery power option is to use a USB power pack.  Testing a few of these, both cheap and expensive, I found that even the ones rated for 2.1A output could not sustain a good 5V supply for very long when drawing 1.5A or higher.  It would often drop to 4.5V or less (depending on cable length and quality).  In any case, at currents above 1.5A the batteries would run flat very quickly.  But I found I was able to draw at least 1A, and in some cases close to 1.5A with few problems.  The key is to get a decent quality unit, and make sure the power cable (described next) is of a decent gauge.

You will need a cable that adapts from the USB port on the battery pack (USB A plug) to a 5.5×2.1mm DC barrel connector, with a centre positive connection.  There are lots of these available (e.g. SparkFun TOL-08639), but none I found could handle more than 500mA without a high voltage drop, largely because that was the limit in the original USB standard.  So I recommend that you actually make one yourself, or find a friend with soldering experience who can make one for you.  Something like DigiKey part CP-2191-ND has the appropriate plug with a decent 18AWG cable.  Attach this to a USB A male plug, like DigiKey AE10637-ND, and cover the USB connector with some double walled heat shrink for grip/aesthetics.  Even with 18AWG cable, you’ll ideally want to keep the cable short, like say under 300mm (12”).

If I do located a source of pre-made cables of good quality that can handle 1.5A or more, I’ll post a link here.

Some testing showed that drawing about 1A from the power pack, we could get nearly one hour of runtime from a 2000mAh rated USB power pack (cheap one from eBay at <$20) before it dropped below 4.7V, or nearly 6.5 hours from a high capacity one rated at 11200mAh (Konnet PowerEZ Pro at about $80).  If you’re wondering, the reason these values are lower than might be expected based on theory, is because of the low-ish efficiency of the boost circuit, and the (somewhat dodgy) way that battery manufacturers rate their battery capacities.  I have some more low cost USB battery packs on order, and if they give good results I’ll add a note here.

Alternatively, if you’re a somewhat comfortable with electronics, you might want to go with the heavy duty solution we’ve been using as shown above.  We took some cheap 7.2V Lithium Polymer RC packs (from DX.com – 11.1V and higher capacity models also fine), and combined them with a 5V 3A Micro UBEC (from Hobbyking.com).  This gave a very reliable 5V supply that could last for quite a long time.  Efficiency is quite good as it is down converting the 7.2V to 5V, rather than boosting from 3.7V up to 5V.  In the above picture, you can see I also used a larger ferrite toroid and heavier wire than the standard HobbyKing UBEC.

If going with this solution, you will of course need a suitable LiPo charger, but there are many available from places like HobbyKing at reasonable prices.  Also be very careful not to short out the LiPo battery as they are capable of outputting very high currents, and can even catch fire if mishandled.

There is a good post at the Homebrew Robotics Club http://hbrobotics.org/wiki/index.php?title=Pololu_2110_power_supply which shows the process of making something similar for powering a Pandaboard robot controller off a 12V (or higher) battery pack.

We also plan to include a feature in the compositor part of the MooresCloud control software that allow you to set a maximum total LED current for the system.  So for example, if an LED pattern is going to be displayed that would require 1500mA, but the limit it set to only 1000mA, the compositor would scale back the brightness of all the LEDs to reduce the overall system current to approximately 1000mA.  This will be useful for people wanting to run from a battery pack, either with limited output capability, or to maximise run time.  It will also be very useful for people who want to control larger strings of LEDs (e.g. 100 to 300, and maybe more…) and avoid accidentally displaying patterns that would overload the power supply.

MooresCloud events at PyConAU 2013

python sprint IoTAS MooresCloud Holiday

photo – gjcross

If you’re attending PyConAU 2013 (and really, why wouldn’t you?), MooresCloud will be doing three separate events during the conference.

Saturday Evening Dinner: MooresCloud co-founder Mark Pesce has been invited to give the dinner talk.  We’ve had a peek at what he’s working up – it features some fun and games.  Hint: It will add to your enjoyment of his talk if you have Twitter client on your mobile or tablet.

Sunday Hackathon: MooresCloud is bringing both pre-production prototype Holidays plus a number of other prototype units – fully functional, but with LED strip lights rather than Holiday globes – to hack away with all day Sunday. Hacking light is both fun and beautiful, so join us!

Monday Code Sprints: We’ll be doing an IoTAS code sprint – bring your favorite Internet-of-Things API along and integrate it!  We’ll have Holidays, Philips Hue and Belkin’s WeMo to play around with. Work on IoTAS, or write a Python app that uses IoTAS to do some cool things!

All you need is a laptop and some enthusiasm.  Everything else will be supplied.

MooresCloud Proudly Sponsors PyConAU

MooresCloud proudly uses Python in its smart Christmas lights

It’s no secret MooresCloud depends heavily on Python and local Python talent, so we’d like to announce our first official corporate sponsorship: as a Conference Contributor for PyConAU 2013. It’s our hope that this contribution will allow other folks with more modest means (students, particularly) can attend the conference and gain the full benefit of all the learning and networking that takes place at such an event.

I was privileged and honoured to be invited to give the opening keynote at the first PyConAU, back in Sydney in 2010. The conference seems to have found a home in Hobart under the steady hand of Chris Neugebauer, and is flourishing.

All of us at MooresCloud are very proud to be able to contribute to the Python community.

Three Flavours of Development: IoTAS, pure Python and Native

MooresCloud IoTAS Python native API Holiday

photo – camknows

When writing apps for Holiday, there are three paths you’ll be able to take, as we will be defining, implementing and documenting three different APIs.  Each has their strengths and weaknesses. You’ll want to pick the one that’s best suited for your application.

IoTAS (REST & JSON)

IoTAS is a full web server, implemented in Python (using Bottle.py and Cherry.py), that provides both the server for the web apps to control Holiday, and a rich API so that the Holiday globes can be individually controlled, animated, and so forth.  All access to IoTAS is through HTTP: either standard GET requests, or through PUT and POST requests that access various features of the API.

IoTAS apps can either run locally on the device – using cURL or the Python requests module to manage communication with IoTAS – or they can run on any other device anywhere on the Internet.  For this reason, IoTAS is the preferred method to link Holiday to events and processes outside of itself.

Within the next fortnight we’ll upload our existing (bare-bones) implementation of IoTAS to GitHub so you can have a look, pull it, and have a play.

Python (pipelights)

It is possible to write pure Python applications on Holiday. Python provides such a range of capability for such a small investment of time, it provides the easiest pathway to construct applications that run on Holiday. Python is well connected (and we will have the requests and feedparser modules available as standard components) so it is ideal for reading and interacting with remote data sources.  If you can think of other interesting Python modules we should include in our standard set, please let us know!

The downside of Python is that it incurs a substantial start up penalty. It takes a few seconds for the interpreter and modules to load. This isn’t a huge issue if your application runs for a long time, but if it is expected to wake up at short intervals, do something quick, then exit, it probably isn’t ideal.

We will be implementing a module loader architecture that allows pure Python Holiday applications to load and run from within the IoTAS framework. This means there is no startup time (IoTAS is always running as a demon process), but as Python runs as a single process, a complex Python application could slow IoTAS’ ability to process REST API calls.

To drive the string of globes, we’ve implemented a compositor daemon – currently known as ‘pipelights’, though this will likely change – which provides a named pipe to which 50 color triplet values can be written, and producing a corresponding change in the colour of the globes on the string.  Writing 50 values to a file object is a very efficient operation in Python, and we’ve had no trouble getting flicker-free animations using this technique.

Native (Sing framework)

Finally, for those of you who feel the need for speed, we are providing the ‘Sing’ framework, which is essentially a ‘C’ language implementation of the Processing framework. Fill in the body of the setup() and loop() functions, and Sing does the rest. With a small API of function calls to control the globes, Sing provides a guaranteed 50 Hz loop-call-time so that you have exactly what you need to produce smooth animations.