Just wondering what the best way to simulate micropython apps on a PC with a GUI (e.g. wxPython Phoenix). I'm thinking of things like keypads, LCDs, LEDs, buttons/switches, Analog input/output.
My work environment uses C for embedded and a Windows based C++ GUI framework to simulate the applications, including fake LCDs, keypads, LEDs, etc.
So how can I do the same with a micropython application (e.g. an STM32 board with a 4x4 keypad and a 20x4 I2C LCD)?
wxPython is probably my GUI of choice. Is it possible to use wxPython with micropython?
There must be a better way of port in a micropython app to CPython for simulation purposes (or vice versa).
The purpose of simulating is to run as much of the app in an easy to use environment for debugging etc, or if there is lack of hardware, etc. It makes sense to use micropython where possible if the target application is micropython.
Simulating hardware for micropython application
-
- Posts: 33
- Joined: Wed Sep 07, 2016 10:46 am
Simulating hardware for micropython application
Last edited by BrendanSimon on Sun Mar 05, 2017 10:50 am, edited 1 time in total.
Re: Simulating hardware for micropython application
You can write your own version of the machine module, that would display stuff in the GUI instead of talking to the actual peripherals. It would be a lot of work, and you would probably need to have some way of configuring what is connected where, but it is certainly possible, and not even that hard.
-
- Posts: 33
- Joined: Wed Sep 07, 2016 10:46 am
Re: Simulating hardware for micropython application
Are you suggesting the `machine` module would be imported to a CPython (e.g. wxPython) app? i.e. the app is a normal python app with a special `machine` module?
Or maybe it runs in MicroPython but communicates with an another GUI app (C, python, java, ...), with comms via TCP/IP, pipes, sharedmem, etc ???
Or maybe it runs in MicroPython but communicates with an another GUI app (C, python, java, ...), with comms via TCP/IP, pipes, sharedmem, etc ???
Re: Simulating hardware for micropython application
No, MicroPython can run on Linux or Windows just fine, so you can run your programs with that, and only provide a mocked access to the peripherals that you wish to simulate.
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: Simulating hardware for micropython application
It would be very difficult, though, to get a full-featured GUI framework running under micropython, so I think the idea of making the machine module a proxy, that calls into a GUI process via some sort of RPC, is viable.
Re: Simulating hardware for micropython application
Yeah - it really depends on what level of abstraction you want.
I often make specialized classes for CPython versus MicroPython and have the code that uses those be regular python (CPython or MicroPython).
For example:
MicroPython serial over USB: https://github.com/dhylands/json-ipc/bl ... sb_port.py
CPython serial: https://github.com/dhylands/json-ipc/bl ... al_port.py
CPython serial over sockets: https://github.com/dhylands/json-ipc/bl ... et_port.py
I typically use the CPython serial over sockets for testing both sides on a PC.
I've also created fake pyb classes for testing: https://github.com/dhylands/bioloid3/blob/master/pyb.py and I've seen some other similar things.
I often make specialized classes for CPython versus MicroPython and have the code that uses those be regular python (CPython or MicroPython).
For example:
MicroPython serial over USB: https://github.com/dhylands/json-ipc/bl ... sb_port.py
CPython serial: https://github.com/dhylands/json-ipc/bl ... al_port.py
CPython serial over sockets: https://github.com/dhylands/json-ipc/bl ... et_port.py
I typically use the CPython serial over sockets for testing both sides on a PC.
I've also created fake pyb classes for testing: https://github.com/dhylands/bioloid3/blob/master/pyb.py and I've seen some other similar things.
-
- Posts: 33
- Joined: Wed Sep 07, 2016 10:46 am
Re: Simulating hardware for micropython application
I'm thinking the simplest thing is to just use CPython, with wxPytohn and standard Cpython modules, and fake the hardware of interest at high level API. This can be used to run/test basic application logic and user interaction, and then do final checking on real hardware with MicroPython.
This is not too different to what I've experienced in C land. It's analogous to using GCC or IAR compiled code on the target, and GCC/VisualStudio/Embarcadero build of or the code (with simulated hardware) for the Simulator.
If I wanted to actually run as much MicroPython code as possible, then I would have to use some kind of RPC/IPC with specialised modules in conjunction with a GUI app.
Thanks, Brendan.
This is not too different to what I've experienced in C land. It's analogous to using GCC or IAR compiled code on the target, and GCC/VisualStudio/Embarcadero build of or the code (with simulated hardware) for the Simulator.
If I wanted to actually run as much MicroPython code as possible, then I would have to use some kind of RPC/IPC with specialised modules in conjunction with a GUI app.
Thanks, Brendan.