Searduino: @FOSDEM, new GUI simulator and some thoughts on Java

First a small introduction to Searduino. Searduino consists mainly of two things. First, a couple of libs (mainly the Arduino source code compiled and archived) and some Makefiles that together make it possible and easy to write pure C/C++ code for Arduino boards. Secondly, Searduino comes with a simulated Arduino board environment. This can be used to unit test your Arduino code (think automated tests). There’s also a couple of simulators, using the simulated environment, with which you interactively typically can validate your software. The simulation is implemented in a library which loads the Arduino code (on GNU/Linux and Unices using dlload) and runs it in a thread (pthread).  This library can quite easily be wrapped by simulators and extensions for other languages That’s as much of an introduction I’ll give here.

After several attempts to get the Python/Gtk simulator called Pardon, using the Python extension to Searduino (called Pearduino), to work well , I gave up trying. The threading support in Gtk seems to make it impossible to get both speed (and we do need speed) as well as an app that doesn’t crash due to too quick/unsynchronised GUI updates from the underlying thread. Don’t get me wrong – I like working with Gtk and I am a Gnome user since … hmm around 2001 (I think). The problem we’ve seen relates to the rather complex problem of combing C binaries loaded by Python and run that in a separate thread and have the results (via callbacks) update the Gtk GUI. So what to do next?

How about a GUI in Qt? I have tried to get into Qt many times but always lacked the time to give it the time it needs.

We didn’t have to think for a long time, since part of my new job at Gothenburg University will be supervising students in Java. Wow – or perhaps uhh – it’s been a while since I did some Java hacking. A long while. The students should also learn Swing so that will be supervised too. To be able to supervise in Java and Swing I needed, it turned out I really needed it, to refresh my almost forgotten Java and almost non existing Swing skills. What better way to do this than implementing a GUI frontend to Searduino in Java/Swing? Yup, that became the task during the Christmas holiday and also the answer to what gui framework to use for the simulator.

I am more of an imperative/procedural (think C) hacker than an OO hacker (think C++, Java). I often use some concepts from OO when hacking C though – hey I don’t go about saying or thinking that mixing C++ and C is a good idea. Either you write OO (C++) or you write procedural (C). For me writing Java code for a Free Software project is a new thing.

Anyhow, over the last days I have, to my surprise, found that I’ve started to like hacking GUIs in Java. Ok, I fall in to the traps of writing C-ish Java code (send the Spanish inquisition after me for doing that!!!) and I figure most pattern fascists probably will cry so much their bodies will dry out when looking at my Java code. Nevertheless I am happy with the speed of which I wrote the GUI. And apart from some rare and odd behavior when stopping (pthread_cancel) the pthread running the Arduino code it works really well. Updates in the GUI are really really quick.

To be able to communicate with and control the C code I had to write a small JNI layer. Just as we did for Python with the Python extension. Comparing writing a Java extension to writing an extension for Python I would say they are equally easy to write.

I think the fresh GUI is the “final” piece for Searduino to make it really useful for many people – so this blog post feels really nice to write. But hey, so many words and yet nothing has been said. I will try to say at least something useful.

  • I am slightly surprised to say that I enjoyed writing a GUI in Java.
  • Searduino has now become useful for more people
  • It’s easier to join the project now – so join us!!!! We need you!

Next step then. Next steps for Searduino that is? For me personally, I would like, for the fun of it and inspired by Andy Wingo‘s post on Scheme to finally be giving Scheme a go – it may not be the strategically most optimal choice but I’ve been wanting to learn Scheme for a while so why not. Leaving myself and my ego alone for a while and instead start thinking about what the next steps for Searduino should be…. I guess that’s up to you to decide.

… and finally. I will be doing a lightning talk about Searduino at FOSDEM (thanks all FOSDEM volunteers for your friendly and informative emails!). So if you’re interested in seeing Searduino simulate some leds blinking and also actually seeing some real leds blinking – and all of this done in C/C++ – pop by the Searduino lightning talk on Saturday at FOSDEM.