Anyone built a wxPython UI to visualize live sensor data from ESP32 or Raspberry Pi?

Hi all, has anyone here used wxPython to build a desktop GUI that displays live data from sensors (e.g. from ESP32 or Raspberry Pi)? I recently read a project about using ESP32 + MQTT to stream sensor values to a web service https://www.theengineeringprojects.com/2021/11/esp32-mqtt.html and it got me thinking a wxPython app might be a good middle‑man for local monitoring.

I’ve also seen Arduino forum threads and Raspberry Pi community projects where people push sensor data to dashboards or loggers but fewer examples coupling that data with a native GUI. If you’ve done similar, how did you handle real‑time updates and threading (for sensor polling vs UI responsiveness)? Any pointers or best practices you’d recommend?

For similar applications I’m running one or more threads for data collection. This will use wx.CallAfter to inform the main thread with the GUI.

Search for ‘wxpython long running tasks’. This will give you some older examples.

For plotting you may use matplotlib or wx.lib.plot or implement your own plotting code. In general matplotlib is slower. It’s probably not suitable if you need refresh rates higher than a few Hz. (For my measurement programs I’m updating every 0.5s.)

The wxPython demo includes a sample for wx.lib.plot.

wxGlade includes examples for matplotlib integration. Unfortunately I did not yet find the time to include an example with a background thread and thread control.

1 Like

Depending on the complexity of your plot, matplotlib may or may not be enough. The attached script uses blitting to plot a random walk as quickly as I can think of - which does not mean there isn’t a faster way, it’s simply that I do not know about it :slight_smile: .

The script has an embedded matplotlib window inside a wx.Frame. On my laptop it manages 60-65 fps, which is not so bad. The refresh rate is displayed in the main frame title every second or so.

If you need faster refresh rates (why?), you will need to adapt your code to use wx.lib.pyplot or move to PyQtGraph.

Andrea.

random_walk.py (3.8 KB)

1 Like

I’ve not ever used ESP32, but I have built several wxPython GUIs for live display of data, mostly using a more comprehensive, distributed control system EPICS used at several large experimental facilities. That also gets numerical data over the network, but with a different protocol. My understanding is that MQTT has good Python libraries (say, with MicroPython) but I have not used it myself.

But I think “getting the data” is not really your question, but whether wxPython is suitable for working with such data sent over the network. I would say Yes.

Most of the data display I do is with wxmplot (GitHub - newville/wxmplot: wxPython plotting widgets using matplotlib) which I wrote and maintain – that does wrap matplotlib (which makes much nicer plots than other libraries), but it it is not that slow. There are some demos there for stripcharts, etc.

And for some largish/fastish 2-D image data from various kinds of cameras, I will also write directly to a panel with DCPaint events.

Some screenshots of some such example apps can be found at Epics Applications with PyEpics — Epics Applications Using PyEpics

I think that is all mostly to say that, this could be done (and run from or on a raspberry Pi or similar device).

1 Like