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.

About these ads

9 responses to “Searduino: @FOSDEM, new GUI simulator and some thoughts on Java

  1. Pingback: New Java GUI added « Ramblings from Searduino developers

    • I may have run it once, just to try it. If it looks useful then it might be worth contacting the author to see if he started working on something else.

      I searched for Arduino-related tools that might implement something similar to what you want, but it seems like you’re looking for some examples of PyQt applications that handle threads nicely. I found this interesting-looking project, anyway: https://bitbucket.org/lbaldini/plasduino/overview

      Have you thought about using multiple processes instead of threads? It might be possible to use some kind of simple interprocess communication to keep the GUI updated.

      • I have thought about integrating and if so how to best integrate an editor so yes, this might be something to look into. A while ago I wrote a translator (hey, that’s really changing the suffix of a file, adding some makefile fluff) of Arduino examples into C that can be loaded into Searduino/simulator. That could be a nice thing for new Arduino users in general – to see the Arduino examples on a “virtual” board before putting it on a real board.

        I guess that somewhere in between a full blown IDE (or perhaps more preferable a theme/plugin to an existing IDE) and the current plain C/C++ dev env plus simulator is perhaps where Searduino should aim at becoming.

        Re: threads and IPC;
        When doing the first version of the Simulator I let the library executing the Arduino code communicate simple printout/reads on stdin/stdout. A GUI, or any other simulator could attach to that stream (via some kind of pipe), After a while this solution got a bit shaky and the need to implement a protocol arose – so I abandoned the idea. Using shared mem between two processes would be good. I figure that the problems with threads and platforms are just about the same as shared memory across various platforms. Using threads makes it easy to do function/method calls – which is nice. But at the same time the complexity of threads is always there. When can I do this and that? How does this GUI get updated? ….

    • Sounds great! Have been skiing with my family. Mostly offline. I am currently in a train back to home. Will contact you when i (finally (and perhaps IF)) get back home.

  2. Pingback: Newsletter FSF Europe, Mars 2013. Le blog d'ANDRE Ani » Le blog d'ANDRE Ani

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s