About my blog

I am multithreaded, and sometimes the threads get tangled.

tagline


a Studiolab production.

FIY

food design course at TUDelft
I blog in Italian
I have a LinkedIn profile
my lab is Studiolab!
I love Jasper van Kuijk's product usability weblog

the wind I am enjoying


Disclaimer

De meningen ge-uit door medewerkers en studenten van de TU Delft en de commentaren die zijn gegeven reflecteren niet perse de mening(en) van de TU Delft. De TU Delft is dan ook niet verantwoordelijk voor de inhoud van hetgeen op de TU Delft weblogs zichtbaar is. Wel vindt de TU Delft het belangrijk - en ook waarde toevoegend - dat medewerkers en studenten op deze, door de TU Delft gefaciliteerde, omgeving hun mening kunnen geven.

Posts in category Technical and really nerdy

my Arduinia on GitHub

GitHub has made it easy and even faintly entertaining to manage code. I am not so convinced by their octopus cat logo, but everything else is quite nice. I have two little projects you might want to use up there:

AFRO: Arduino FRObber. A bit like Firmata, only easier to understand. You load a program on your Arduino and then shoot serial commands at it: turn on that pin! what is the value of that sensor? Call that procedure 10 times! This sort of things. Comes with Python bindings. Afro aims at making simple installations really fast.

Ardulink: an optical data link for Arduino. With one LED you can get data out of your Arduino. With one light sensor you can receive it. The main advantage of this code is size and simplicity. If you choose to #undef RECEIVE symbol and #define only SEND, the code compiles to less than one kilobyte and runs also on an ATtiny 45. It uses one CHANGE interrupt to avoid polling. Currently the speed is pathetic, because I am not using the microsecond resolution timer. But for sending little squirts of data it is quite OK.

Lights in the sky

Being a nerd is all about seeing things in a different light. And about absorbing vast amounts of knowledge about all sorts of things, and being able to apply it (or at least regurgitate it) when it is necessary. Or also when it is not necessary at all, but you just think it is neat. In this spirit, I once read through the Atmospheric Optics site to satisfy my curiosity about some strange colored spot I had seen in the sky.

It turns out that, of course, there are people that do whole PhDs on this type of thing. Without further ado, here is one photograph.

 

This was taken in Brussels, shooting directly towards the sun with a fisheye lens. I am holding the lens cap in front of the sun in order to reduce light ghosts and flares. If you look in the upper portion of the picture, close to the flue on the left, you can discern something like a rainbow. A bit lower, right above the sun, there is another slight spray of color like a smiling mouth. These are not artifices from the lens: they were visible then and there. To help you see them, I have increased contrast and saturation along a top to bottom gradient.

 

 

 

 

In the enhanced picture, you can see the upper arc, the lower upturned arc (very weak) and two curious spots of color on either side of the sun. The one on the right appears just behind that irritating tree, the one on the left is barely visible. I have added outlines to the pictures, so you know what I am talking about.

 

 

OK, but what are these things? you are asking yourself. They are optical atmospheric phenomena produced by the interaction of sunrays and tiny ice crystals in the high atmosphere – contrast that with the rainbow, that is produced by interaction with tiny drops of water. The ice cristals can take on various shapes and orientation, giving rise to various phenomena. The best place to see them is not Bruxelles, but rather the South Pole. You can find more detailed information at the Atmospheric Optics website.

My best identification is as follows; the lower two twin splotches of light are sundogs also known as parhelia (always at 22 degrees from the sun!), a useful word for casual conversation. The weak one in the center  is an upper tangent arc, and the big one on top looks to me like part of a supralateral arc. From this information, you can deduce many cheerful facts about the state of the high atmosphere over Bruxelles. 

 

Lua, a programming language that could be your new friend.

The programming language Lua (moon, in Portuguese) looks very interesting. It is small, contemporary and could be the complete solution for interactive prototyping, since it runs on single board computers, PC (Win, Mac, Linux) and servers. It can be a scripting language for Apache,  but it also hides inside Adobe Lightroom and vlc, the best videoplayer in the universe. In sort, it is interesting to people like me. If you find Lua interesting too, perhaps you are people like me, which means that we should never meet it or we risk boring each other to death.

At any rate, here is a small taste of Lua as a quick and dirty Fibonacci function:

function fib(i)
 if (i==1 or i==0)
  then return (i)
 else
  return fib(i-1) + fib(i-2)
 end
end

Of course, one would use a smarter form of recursion in order not to kill your computer as soon as you try printing fib(100). As you can tell from this brief snippet, Lua is dynamically typed and the end of a block is indicated by the keyword end, not by curly brackets (as in C) or fancy indentation (as in Python). The sprinkling of ends feels a bit Pascal-like.

The name of nothing

Amusingly, when you access an undefined variable you don’t get an error but the value nil. In the following code you find some educational language bits: text prefixed with a > sign was typed at the interactive interpreter.

 this very brief chat with Lua tells us that

  1. accessing an undefined variable produces a value of nil. Your program does not die instantly, but you do get a warning. This sort of implicit nil looks like a good thing, but it is probably a veritable quarry of trouble the moment you start playing around with it. And I kind of like the difference between a never-declared variable (perhaps because of a typo) and a variable that has been declared and happens to contain nil (or the local equivalent in the language at hand). But this is just me.
  2. this language does not care about whitespace.
  3. first-class functions, again typical of dynamic languages. You can also get them in Python and LISP. The moment you understand that a function is nothing magical but just another data type, you feel the light of understanding shine on your brow. No, C programmer: your pointers to functions are not first-class functions. Go back to scratching your silicon.
  4. the unary = operator is used for printing a value. Bizarre, but still within the limits of reason.
  5. even if I declared the function to take no arguments, I can call it with arguments and nothing happens.

 so many little details! Lua also has iterators, which is nice, and some really strange constructs for managing return values from function. Functions can return lists of values, which do not correspond to any other data type, which means that you need special syntax for converting them to reasonable value. For example, if foo returns a list of value, but you want only the first value returned by foo(4), you call (foo(4)). Or if you want to convert a list-of-return-variables into a table, you call {foo(4)}. Python too has not-so-wonderful syntax (I find it difficult to remember) around argument lists. 

Different, not equal

If you are a Pythonista or a C programmer, you are going to hate this. The symbol for "different" is ~= (tilde equal), not != (bang equal). Notice that if you fall into this very easy mistake, Lua outputs a useless error message. Be on the lookout.

Scope

Scope is where you go whoo, this is wacky. All variables declared inside a function are global. If you are a C programmer, your head just exploded, and what is left of your visual system is trying to turn that global into local. But no. So, supposing you have defined this trivial function:

function foo(x)
 z=1
 b=x*2
end

this is what happens in the interpreter:

> =z
variable ‘z’ is not declared
> foo(3)
> = z,b
1
6
> =x
variable ‘x’ is not declared

at least we don’t get x! The formal paramaters of a function do not count as variables declared inside it. There is still something sacred in the world. Notice that there is also a local keyword, and that local variable access goes faster than global variable access.

Nice stuff

We get coroutines. A classic computer science concept that can be used to write generators, a classic computer science concept that can be used to write better programs. 

We get metamethods, stored inside metatables (a word that looks funnier and funnier as you stare at it), and they are a bit like operator overloading. They can also be used to build some object oriented machinery, like classes and inheritiance. Lua also has lexical scoping, which will get all the computer science weenies excited since it is the road to closures.

Finally, we also get the bizarrely called function: if you call a function that does not exist on a table, lua looks for the function in the table’s metatable and calls it. In other words: we can build really reliable code that protects itself against programming mistakes. And we can really go crazy with metaprogramming. Examples here.

 

YouTube Preview Image

 

As you can see, there is a lot of emotion riding on programming languages, it is not just me.

 

PS: apologies for having to write with a tiny little picture, but I am not able to turn off the autoformatter, and lines and lines of underlined text might turn off even the most motivated reader.

Hacking the bread machine – 1

 I realize that, if I wait until all is done before writing it up here, it will simply never happen. Also, the motto of this blog means "a little and frequently" in my hometown dialect: I should heed my own advice.

 I have more or less succeeded in subverting the bread machine for my purposes, and I have added temperature control via a PID controller running on an Arduino (I am using the arduino-pid-library). It works, after a fashion, although

  • I have not calibrated the NTCR (aka thermistor), so I have no clue about real temperature, only very arbitrary units: room temperature is around 90.
  • this thing is sluggish. It takes several seconds before you see any effect from the 500W heater.
  • the bread machine has a built-in thermal safety that will melt and cut the power when the vessel overheats. But I have no clue at what temperature this happens, so I feel very nervous whenever it gets a bit hot.

The idea behind this activity is that, ultimately, a bread machine is just a pot surround by a vessel with a heater, plus a stirring device. If you ignore the bread aspect of it, you could do many things with such hardware, ranging from pasta sauces to desserts to rice. But, all the bread machines I know of are not programmable. They have a number of pre-programmed sequences of stirring, heating and cooling, and you are limited to them – I became acutely aware of the issue when playing around with sourdough bread and very long raising times.

Just for fun, here is the temperature graph with the current parameters:

  Tick marks on the X axis are at 250 seconds divisions, and the setpoint is at 400. The Y axis is, as I said before, in arbitrary units where 400 is probably around 100 degrees and 1000 is even brandweer bellen (call the fire brigade, please). The PID controller is running with a 1 second duty cycle, and the parameters are

P = 10.0

I = 0

D = 2.0

 In the graph above you can see a little overshoot at the beginning, moderate oscillations, a sag at the 4th division when I opened the machine and then recovery. The noise on the pink line is due to sensor noise being amplified by the derivative term – I think. Since I am just driving a heater, the noise is not a reason for concern. You can also see that the temperature never quite reaches the setpoint: this is as expected, because the integral term is zero. I tried to give the integral term a non-zero value, but this gave me big scary overshoots, even with ridiculously small values (I went as low as 10-17 before I gave up.) This is relatively easy to fix by adding a little bias to the setpoint. Since everybody likes graphs, I am including another one with a longer run. Here I am changing the setpoint, as indicated by the orange line.

 

this is a graph, it must be science!

 

  Tick marks are again at 250 second intervals. The orange line is the setpoint. Somewhere around the 10th division I had to go to teach in Food, Design and Culture (that I keep mixing up with a journal called Food, Culture and Society). Since I don’t trust my hardware or software at all, I cut the power to the heater, but did not stop the PID, who tried desperately to do its job without any control authority. The temperature decays beautifully along what looks very much like an exponential. I am not publishing any pictures of the hardware because it both very simple and very messy. Just wires and loose components, not even a breadboard.

(I realize that any Industrial Design Engineering bachelor student can build and tune PID controllers in his sleep, but I did not study at TUDelft. Heck, I did not even know about the very existence of control theory until five years ago).

 The temperature "program" here was just a switch statement inside an Arduino program, but in the future I will make it much more generic.

 The next steps are: building a programming interface, so I can load my own sequences of activities and doing a workshop with food-obsessed people here in Delft. I trust that they will provide me with brilliant ideas on what to do with my toy. Publish the design (HW/SW) so that other people can play with it. And write a brilliant paper about it all. Maybe I will claim that it is action research, who knows.

 In other news, ITD is going strong, and so are UTAR and Food, Design and Culture. Two papers are making their way through the review process, I am trying to get funding, together with Aadjan et al., for a startup  (this sounds unnecessarily grand), there may be an exhibition project happening in Qatar this summer and of course my lovely and wonderful graduations students are progressing. Some of them will even graduate soon! There is indeed light at the end of the tunnel. I am also wondering if Petri Nets are an appropriate representation for recipes – this makes it difficult for me not to start playing around with a wonderful Python library for doing all things Petri. It is called, appropriately Snakes.

 In other other news, I am currently in Romania on vacation. Will be back in Delft next week, right on time for the flavorful, exciting ending of Food, Design and Culture. I will be bringing back a typical Romanian product called ţuica: it is colorless, it smells good and it can knock you under the table with no effort at all.

 

making the FoxBoard talk to Arduino

Suppose you have a sketch loaded on your Arduino, and suppose that you need some serial communication. You try it out on your Windows box, and all is happiness. Then you attach the cable to the Foxboard (a single board computer running Linux) and nothing works anymore. Why?

Because apparently the default settings of the serial port are wrong for your purposes.

To set the serial port your way, you have to use the wonderful stty command, something that our hairy ancestors used to do when setting up terminals in the Lascaux caves. First of all, run the dmesg command. You will see lots of stuff, and at the end you should see something like this


crisv10_irq dbg: ctr_status_irq, controller status: host_mode started
crisv10_irq dbg: ctr_status_irq, controller status: host_mode started running
usb 1-1: new full speed USB device using hc-crisv10 and address 4
ftdi_sio 1-1:1.0: FTDI USB Serial Device converter detected
drivers/usb/serial/ftdi_sio.c: Detected FT232BM
usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0

This means that the USB serial converter in the Arduino is recognized, the driver has been loaded, and the Arduino is mapped by ttyUSB0. I have marked in bold the most important part. It mans that the Arduino’s serial port is now available as the /dev/ttyUSB0 file, for reading and writing.

To see the current configuration of the port type stty -F /dev/ttyUSB0

[root@vdhelm1 /dev]118# stty -F /dev/ttyUSB0
speed 9600 baud;
-brkint -imaxbel

This is a quite typical configuration, good for controlling your UNIX minicomputer from a VT100 terminal, and if we were on a time machine to Dr. Who land it would be probably the perfect configuration. For our purposes, though, we need to dumb it down a bit.

I have noticed that to make things work "like on Windows" I have to kill the local echo. This is done with the command

stty -F /dev/ttyUSB0 -echo

and then things work pretty nicely. Send stuff to the Arduino like this:

echo "whatever" >/dev/ttyUSB0

and see on screen what the Arduino is sending back like this:

cat </dev/ttyUSB0

extra info: if things work strangely, or don’t work at all, one reason can be that your application on the Foxboard side is sending out the right stuff, but the terminal is not sending it to the Arduino because it is in "canonical" mode. Canonical mode means, among other things, that information is sent one line at a time – which really made a lot of sense for controlling printers. But it may be that you need your data to reach the Arduino as soon as you send it. Additionally, binary protocol data cannot really be divided in "lines". What you want is a device that will just shoot stuff out on the wire as soon as you send it. To get just that, you need to put your device in "raw" mode.

[root@vdhelm1 /mnt/flash/root]116# stty raw -F /dev/ttyUSB0
[root@vdhelm1 /mnt/flash/root]116# stty -F /dev/ttyUSB0
speed 9600 baud;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost
-isig -icanon

the parts in bold are the ones you type. Without delving too much in the output of stty, notice that "raw" is actually a macro for a bunch of configuration options. The "-" means NOT, so these are all character processing options having been switched off. If you want to find out why this whole wacky tty mess exists, and why it makes a sort of sense (historical, at any rate), there is a great page about The TTY demistified.

caveat: if, by mistake, you set your current tty to raw mode, things will become very funny indeed. Time to get another tty 🙂

Apple and Sony according to the Onion, a most fundamental news source

required viewing for people that do UTAR.

 

 

 

"Anyone mystified by the device’s numerous extraneous features can scroll through the interactive help menu, a labyrinthine maze of indecypherable topics of use to fucking no one"

And of course there is one for Apple users: nothing is simpler than a single giant button.

How to setup a fresh Foxboard development environment

 

I am writing this, of course for my own purposes, which include controlling a large number of outputs. I would like, as a first exercise in controlling stuff from the FoxBoard, to take over one of Daniel Saakes Lampan lamps (read the instructible) and control the individual lamp units. This means -for now- 12 output ports. The ports will be provided by the Foxboard LX, a single board computer that runs Linux – in other words a quiet, cheap, silent and hackable computer smaller than a postcard.

To have an idea of the size of the board, keep in mind that the big metal thing in front is an Ethernet socket and the two meta ports on the right are USB sockets (perfectly working, by the way).

 

To develop on the Foxboard LX you need to use a development machine that runs a specialized SDK environment. This is where you do most of the programming and configuring. The results of your effort are converted into an "image" file, that consists of a complete image of the board’s filesystem. The image is then written into the flash memory of the board. The board then boots in about three seconds and does what it has been told to. To get to this, there are a few hoops to be jumped through.

Continue reading

© 2011 TU Delft