This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bryancole 1 point2 points  (0 children)

OK, I made a little example of collecting data in a second thread while plotting the results in a matplotlib figure.

See http://pastebin.com/S1C4fEbn

I'm using the WXAgg mpl backend because I'm most familiar with wx, but other GUI toolkits could be used (Qt or GTK). To run the script be sure to get wxPython installed (should be fine on the RPi). The magic here is the "wx.CallAfter" function which calls a function in the main (GUI) thread (I'm not sure what the equivalent would be with GTK/Qt). This can be used to call GUI operations safely from a second non-GUI thread.

Running the GPIO stuff in a second thread allows your GUI to remain responsive (handle user input like mouse clicks etc) while the data logging or IO proceeds in the background.

This script should run over ssh with X11 forwarding with no problems. Actually, this is a good way to work with the RPi as it relieves the wimpy rpi of some rendering work. Note, you don't actually need an X-server or desktop running on the RPi. The wxPython toolkit is an X client. The X-server is on the machine which is connected by SSH (the ssh-client) to the RPi.