How I met Ubuntu Linux

In the simplest way: I was a lazy Windows user, but curious about Linux. I remembered I had tried something many years before, and I had a vague but not so good memory: yes, pretty, but too difficult, good for initiates.

But when my old PC broke, I changed a lot of hardware, and I didn’t want to fuss over neither complicated and expensive Windows licenses, nor piracy. So I gave Linux a chance: I took the usual (in 2008) Ubuntu CD-ROM sold with a magazine issue and put it in the tray. If you, dear Ubuntu, start smoothly, I will foster you. And that’s what happened.

Everything went fine, no strange questions, no locking. Ubuntu was not so difficult, and much, much more similar to my usual environment than I expected. Five years have passed since then, and now Ubuntu is my usual environment.

So, dear reader, please give you too a chance to Linux: the only thing you really risk, if you reflect, is to find a free and live resource!


Pomodoro pauses

pomodoro_techniqueSome time ago I stumbled across this interesting column. The conclusion is:

Of course, not every mental activity can or should be performed while walking, but this new research reinforces anecdotal evidence and other research findings that suggest being too tightly chained to our desks is bad for our minds as well as our physical health. Science shows we often have creative breakthrough when our minds are disengaged from the problem we’re wrestling with, hence the common experience of getting great ideas while relaxing in the shower.

Getting up for a walk or a jog is another way to achieve this sort of head space–after all, it worked for Einstein and Charles Darwin

It seems to me a strong reinforcement of the importance of pomodoro technique. I make use of this technique quite often, and – al least in my case – I find that its usefulness is strongly linked to the necessity to break your activity after at most 25 minutes. In fact I find it difficult to stop my task(s) and I end up getting too tired and not productive.

Posting 1-wire/RasPi data to Xively without third-party libraries – the simple way

Recently I connected to Xively (you know, the site accepting your environmental data, keeping it and letting you manage it for free – roughly speaking) with Raspberry. I just wanted to send some temperature data with the very famous  1-wire solution. Other help here.

There is a plenty of info about what software to use. I lately fell in love with python, so the language had to be that. If you look for help, you will find that Xively itself and Tinkerforge gives you some handy… pieces of python, and the same with the library owfs  but:

  • Xively gives a library with a full API, very useful but too large for my needs
  • Tinkerforge’s library is based – obviously and rightly – on the hardware they sell. Too large again.
  • OWFS shares – IMHO – the same problems as the Xively one: too large
  • all of them need to be downloaded, installed, etc.
  • really do we need a library? At the end of the day we just must send a PUT call to the HTTP(S) server

So I ended up with a personal version based on the – anyway well done – Tinkerforge version. Mine is “pure python”, using just and only the normal python installation. Probably you still will want to work to refine the code, but that could be considered a good starting point. Here it is:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket
import sys
import time
import math
import logging as log
import httplib
import json
import threading


MIN_TEMP = -100

def read_temperature():
    # the following code will be different in your case
    tfile = open("/sys/bus/w1/devices/28-0000046ca58d/w1_slave") 
    text =

    lines = text.split("\n")

    if lines[0].find("YES") > 0:
        temp = float(lines[1].split(" ")[9][2:])
        temp /= 1000
        return temp
    return MIN_TEMP - 1

class Xively:
    HOST = ''
    AGENT = "my-agent"
    FEED = 'FEED-ID'
    API_KEY = 'unreadeable-code-given-by-xively'

    def __init__(self):
        self.items = {}
        self.headers = {
            "Content-Type"  : "application/x-www-form-urlencoded",
            "X-ApiKey"      : Xively.API_KEY,
            "User-Agent"    : Xively.AGENT,
        self.params = "/v2/feeds/" + str(Xively.FEED)

        self.upload_thread = threading.Thread(target=self.upload)
        self.upload_thread.daemon = True

    def put(self, identifier, value):
            _, min_value, max_value = self.items[identifier]
            if value < min_value:                 
                min_value = value             
            if value > max_value:
                max_value = value
            self.items[identifier] = (value, min_value, max_value)
            self.items[identifier] = (value, value, value)

    def upload(self):
        while True:
            time.sleep(10 * 60) # Upload data every ... min
            if len(self.items) == 0:

            stream_items = []
            for identifier, value in self.items.items():
                stream_items.append({'id': identifier,
                                     'current_value': value[0],
                                     'min_value': value[1],
                                     'max_value': value[2]})

            data = {'version': '1.0.0',
                    'datastreams': stream_items}
            self.items = {}
            body = json.dumps(data)

                http = httplib.HTTPSConnection(Xively.HOST)
                http.request('PUT', self.params, body, self.headers)
                response = http.getresponse()

                if response.status != 200:
                    log.error('Could not upload to xively -> ' +
                              str(response.status) + ': ' + response.reason)
            except Exception as e:
                log.error('HTTP error: ' + str(e))

if __name__ == "__main__":'Start')

    xively = Xively()
    i = 0
    while True:
        i += 1
        print('reading ' + str(i))
        temp = read_temperature()
        xively.put('temperature', temp)


Going to Arduino from C#, Java, … string trouble

As I posted some weeks ago, if you need to work with strings (or, better, character arrays) in Arduino’s C++, coming from a friendlier development environment, things reveal to be quite hard.
There are anyway two approaches that can relief the pain:
1) An F() procedure exists, moving every declared string from the highly expensive SRAM (in Arduino UNO 2kB) to flash memory (32 kB). I used this method and solved my intermitting (and making me crazy…) problems
2) Using PString library, added by NewSoftSerial and put in official version of Arduino. It is very handy: it hands you a nice object managing a char array and allowing you to modify and search your string

Going to Arduino from C#, Java, …

So far I have spent several hours programming Arduino. It has been a very pleasant experience, because, as for many other programmers, seeing things changing behaviour after your code is an exciting sensation. Usually you just see something happening on the screen.

Anyway, first times were sometimes hard: Arduino seemed sometimes doing weird things: stopping, ignoring your code, and so on.

Arduino is programmed in C (ok, C++ if you prefer, at least in theory). As a friend of mine says: “C is well-camouflaged assembler”. So, if you are coming from languages like Java, C#, FORTRAN, Python you likely are not used to think about, for example, array length, You create new arrays, delete them, assign them to variables without any trouble. You don’t know that here in C language everything can hide a trap. In short, arrays are not dynamically managed: you must take charge of their dimension. For instance, if you write:

char arr[2];
arr = "abcdefg";

your code compiles smoothly… and at runtime your last letters will go wandering lost in space somewhere… but surely where they are not allowed to 😉

USB Serial Light Adapter for Arduino in Windows 7 x64

Arduino Ethernet

Arduino Ethernet

I am now trying to use Arduino Ethernet, in order to communicate in LAN with Arduino. Arduino Ethernet allows you to handle just only one board, saving space and money (you could have everything running in – almost – the same way by adding an Ethernet shield to a standard Arduino UNO).

USB serial adapter

USB serial adapter

It seems a straightforward operation, but a problem arises: the board lacks a USB port. A little (reusable) adapter USB-serial is the simplest solution.

Yes, but in my Windows 7 x64 environment the way turns out to be very steep. I searched the net thoroughly. At the end I found, buried in a technical document of FTDI Ltd. about drivers installation, at chapter 5.4, the indication that their driver will not install on Windows 7 x64. In general

Windows 7 x64 OS will only allow certified drivers to be installed. The certified driver supplied by FTDI will work with VID 0403 and PID 6001 for FT232 and FT245 devices. It will also work with VID 0403 and PID 6010 for FT2232 devices and VID 0403 and PID 6011 for FT4232.
If you have a product where the manufacture has customised the driver but has not re-certified it, then the driver will not load. You should contact your vendor to determine if they will support Windows 7 x64.

So, I’ll now retry with Ubuntu. Can anyone suggest other solutions to this problem?

Microsoft and “The Mentalist”, partial sponsorship

Jane and Lisbon running

Jane and Lisbon

Surely you know “The Mentalist”, the successful television series. It’s well-beloved by my whole family, it’s the only one we are accustomed to watch on television .

A strange thing I have always noticed is the nearly last frame of every episode:

theMentalistMicrosoftBut, hey, it’s Microsoft!

So I wonder what is the meaning of this (partial!) sponsorship. At what I saw, there is no quotation of MS products. CBI’s OSes are surely not Windows, neither an MS application is shown in their monitors. They do not write with Word, they do not use Excel, and so on.

I have found just one reason. During their investigative action, detectives in the series make great use of computers to query databases, to look for every possible info about crime suspects. But, do you believe? they never, really NEVER google anything!