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)

]]>http://mooresclouddev.markpesce.com/2013/12/23/controlling-a-holiday-from-a-leap-motion/feed/0Using the SecretAPI via PHPhttp://mooresclouddev.markpesce.com/2013/12/19/using-the-secretapi-via-php/ http://mooresclouddev.markpesce.com/2013/12/19/using-the-secretapi-via-php/#commentsThu, 19 Dec 2013 00:17:04 +0000http://mooresclouddev.markpesce.com/?p=634Continue reading →]]>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.

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).

]]>http://mooresclouddev.markpesce.com/2013/12/19/using-the-secretapi-via-php/feed/0Using the RESTful API via PHPhttp://mooresclouddev.markpesce.com/2013/12/19/using-the-restful-api-via-php/ http://mooresclouddev.markpesce.com/2013/12/19/using-the-restful-api-via-php/#commentsThu, 19 Dec 2013 00:00:23 +0000http://mooresclouddev.markpesce.com/?p=641Continue reading →]]>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.

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.

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):

Invocation

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:

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:

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.

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.

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.

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).

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/).

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.

]]>http://mooresclouddev.markpesce.com/2013/07/06/holiday-hardware-is-open-source/feed/0Powering Holiday from batterieshttp://mooresclouddev.markpesce.com/2013/07/05/powering-holiday-from-batteries/ http://mooresclouddev.markpesce.com/2013/07/05/powering-holiday-from-batteries/#commentsFri, 05 Jul 2013 12:26:10 +0000http://mooresclouddev.markpesce.com/?p=568Continue reading →]]>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.

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

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.

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.

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.

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.

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.