Home-made name badge pcb with scrolling messages on led display

For people at FOSDEM 2012 (great event by the way!), you’ve surely seen my name badge around. For others, here is a picture :

As promised to some people there, here are all the details :

I used an MSP430F5171 16-bit ultra low power microcontroller (mcu), and my own arduino port for that platform (that supports nearly all the msp430G, MSP430F2xxxx and msp430F5xxx by the way, with all their ports, and pwm on all the ports if needed).

However, to save some room on the board and to limit the bill of materials, I haven’t used any resistors, playing on the multiplexing effect and praying that the mcu would handle that current (very bad practice for production designs, but for an experimental name badge… ;)).

Enough chatting, here is the schematic :

And pictures of the badge being built :

If you wonder how I made the pcb, I used the toner transfer method (cheap store catalog paper and laminator), with traces as small as 6 mil, so it works perfectly once you’ve tried all the methods on the web and found the one that is ok for you. I hand soldered all the components using a regular iron.

And, finally, of course,a video of it scrolling :

As you may see, there is a final row on the right that doesn’t light up, that’s because I tried to put high intensity blue smd leds, that took too much current from the mcu pin, another reason why it’s a bad practice to do what I did without resistors there was just a badly soldered via, now fixed 🙂

If I had to to do it again, I’d probably use real led drivers, but trying to find some that are low power (it’s a name badge after all and it runs on battery) and maybe use a bigger resolution, as reading it with a 5×3 font was a bit hard.

If people are interested, I can publish the code here if needed, and I’ll of course post a full version of my arduino lib for msp430 as open source soon don’t worry 🙂

Have any question ? Use the comments 🙂

Data-flow made easy: PyF 2.0

As you may know, I work a lot on a python flow-programming framework named PyF.

We just released its 2.0 version, and I thought it may be a good occasion to present it here (I used Mathieu’s article as a basis for this presentation):

PyF is a Python framework for writing highly scalable data processing, data mining applications, and more. PyF is Free software, distributed under the terms of the MIT license.

To achieve the scalability, PyF is based on flow programming: instead of processing « a certain quantity of data », we process a « flow » of data, so that at any point, we only ever have one object in memory, no matter how much data we will process in total. That’s right, mining your huge customer database and generating reports with PyF will not take your servers down to their knees.

To achieve this, we use Python generators (no need for python extensions like stackless):

Each unit of the whole processing chain takes a generator as input and yields values as soon as they were processed. We could even handle a never ending flow of input data and keep processing them, yielding each one after the other!

Now, down to the details, PyF is composed of several layers:

  • At the low level, you have only the basic subset of core functions that will help you write flow-based applications.
  • At the mid level, you can run your processes in your application, using a wide range of plugins (or writing your own)
  • At the highest level though, you will find a full-blown web application that allows you to graphically design your processing chain (we call it a tube) by dragging and dropping processing units (we call them components) and chaining them, output to input. We have several default generic components that can be used to do all sorts of processing and reporting already, and it is pretty easy to write your own if necessary (we will gladly help in any case). We even have a built-in scheduler so you can specify when to automatically launch your processes!

We wrote a simple tutorial to get PyF, and a series of tutorials to actually make your first steps.

We already have some documentation which should be more than enough to get you started, although we are working on making it more comprehensive.

About the new things in 2.0, one of the most exciting is the addition of multiprocessing: you can move any node in your tube to a separate process with a simple checkbox.

If you have any question, come hang out on our mailing-list or our IRC channel:

Oh, and of course, visit our website: http://pyfproject.org/

Create PDF in Python using Genshi and RML with pyjon.reports

Warning, this article is technical… If you don’t care about python development, skip it 🙂

You want to create pdf reports, send letters or any other action needing pdf documents ?

If you are a python expert, you’ll have surely heard about ReportLab. Yeah, I know, to use it, you need to code it, and when you change your template you have to do everything again.

A solution to that, is to use RML, an xml language done by the company that created reportlab. RML permits to use stylesheets, and to have an xml document that generates the pdf (just like html).

There is a problem with RML. The reference handler, (Reportlab RML) isn’t free (neither as in beer nor as in speech)… But the fabulous guys at Z3C did an open source handler for RML, z3c.rml !

Just one problem : when you create big documents, the process will crawl, take all your ram and die badly. The solution to that aspect ? using PyPDF to join pdf files into one (one template per document part).

Now, here comes the real deal : we will template that xml, just like we would do for html, using an xml templating language : genshi.

To ease that task, I’ve made a little python lib that handles the templating, the merging of various documents into one and much more.

For the most impatient, head directly to the examples ! 🙂

How to use it ?

Example case : a data table

First, let’s initialize a factory (a class that allows to create various documents and join them in one pdf):

from pyjon.reports import ReportFactory
factory = ReportFactory()

Now let’s create a test.xml file containing our template:

<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
<!DOCTYPE document SYSTEM "rml_1_0.dtd">
<document xmlns:py="http://genshi.edgewall.org/">
<template pageSize="(595, 842)" leftMargin="72" showBoundary="0">
  <pageTemplate id="main">
    <frame id="first" x1="1in" y1="1in" width="6.27in" height="9.69in"/>
  </pageTemplate>
</template>
<stylesheet>
  <blockTableStyle id="mynicetable" spaceBefore="12">
    <lineStyle kind="OUTLINE" colorName="black" thickness="0.5"/>
    <blockFont name="Times-Bold" size="6" leading="7" start="0,0" stop="-1,0"/>
    <blockBottomPadding length="1"/>
    <blockBackground colorName="0xD0D0D0" start="0,0" stop="-1,0"/>
    <lineStyle kind="LINEBELOW" colorName="black" start="0,0" stop="-1,0" thickness="0.5"/>
    <!--body section-->
    <blockFont name="Times-Roman" size="6" leading="7" start="0,1" stop="-1,-1"/>
    <blockTopPadding length="1" start="0,1" stop="-1,-1"/>
    <blockBackground colorsByRow="0xD0FFD0;None" start="0,1" stop="-1,-1"/>
    <blockAlignment value="right" start="1,1" stop="-1,-1"/>

    <!-- closing the table when restarting it on next page -->
    <lineStyle kind="LINEBELOW" colorName="black" start="0,splitlast" stop="-1,splitlast" thickness="0.5"/>
  </blockTableStyle>
</stylesheet>
<story>
  <h1>$title</h1>
  <blockTable repeatRows="1" style="mynicetable">
    <tr><td py:for="i in range(10)">Row ${i}</td></tr>
    <tr py:for="line in data"><td py:for="col in line" py:content="col" /></tr>
  </blockTable>
  <para py:content="dummy" />
</story>
</document>

Let’s have a look at this template:

  • The template node permits to choose the document size
  • The stylesheet node permits to define the styling of the document
  • The story nodes contains the document content (just like body in html)
  • Like in html, h1 defines a level 1 title (we print the title var inside)
  • A para is like an html p (a paragraph)
  • The blockTable is the table tag containing rows and columns (td and tr). The py:for attributes define the iterations over list vars
  • The first one (py:for=”i in range(10)”) defines the columns (Row 0 to Row 9)
  • The second (py:for=”line in data”) shows the whole content of the data var (item per item)
  • The last one (py:for=”col in line”) shows the content of each line (with a py:content printing it inside the tag)

Now let’s generate a document with this template:

template = 'test.xml'
testdata = [range(10)] * 100

factory.render_template(
        template_file=template,
        title=u'THE TITLE',
        data=testdata,
        dummy='foo')

We passed various variables and a data list (testdata) containing the numbers 0 to 9, 100 times: [[0, …, 9], …, [0, …, 9]].
Please note that all keyword arguments passed to the function (beside template_file or template_string) are passed to the genshi template, and accessible as root variables there.

Needing to add another secion in the document with the same template ? No problem !

factory.render_template(
        template_file=template,
        title=u'THE TITLE 2!',
        data=testdata,
        dummy='bar'
        )

Eventually, we will create a single pdf files, with all the content, finalising the factory (cleaning it):

factory.render_document('test.pdf')
factory.cleanup()

And voilĂ ! It’s as simple as that.

How to install it ?

To install pyjon.reports it’s very simple: just type easy_install pyjon.reports in your console (in a virtual env or globally), and you’ll be able to generate pdf documents in your applications in less than 5 minutes.

If you want to see the source code or contribute, see the bitbucket page: http://bitbucket.org/jon1012/pyjonreports

For more info:

New blog…

Hi dear readers.

What you did know as JonDesign disappeared. But fear not, as instead comes my personnal blog, hopefully updated much more often!

I’ll blog about tech, development (python, css, javascript), design or otherwise interesting news and tutorials.

SmoothGallery continues to live at http://smoothgallery.jondesign.net/.

For all contact about professionnal activities, please use my company website (JMSI).

See you soon here !