Page 1 of 1

Integrating micropython into python project

Posted: Wed Jul 31, 2019 9:17 am
by lenthal22
Hello everyone,

I've recently started using Micropython for a small home project, where I'm using an adafruit esp32 board to record analogue data. Currently, I deployed the code on the board and save the data to a txt file, from which I can import my readings into my main python project. Looking at some pyboard projects I saw that solutions exists (https://github.com/dhylands/json-ipc) to establish communication channels between a micropython board and a python project. However, my board is not a pyboard and so I'm confused whether any of these would be applicable to me. What I would like to understand is whether I can integrate a micropython code within a standard python project? In this case I could call a function on the esp32 board and also receive data real time (the latter through serial communication potentially). This might be a very simple problem for someone with a hardware background, but I believe I lack the relevant experiences.

An additional constraint is that I need to sample in the kHz range, which might be relevant concerning the communication channel used.

I would appreciate your help with this.

Best regards,
L.22

Re: Integrating micropython into python project

Posted: Wed Jul 31, 2019 11:56 am
by jimmo
Hi,

Yes, you should definitely be able to use dhylands' json-ipc library for this. I'm not sure if you can use the same UART as the REPL though on ESP32?

But ESP32 has WiFi, so perhaps that's a better option? In which case you can adapt the socket example (echo_server.py) to run on the ESP32.

However, it would be worth looking at https://github.com/peterhinch/micropython-iot - which provides a reliable way to send and receive messages to/from your MicroPython device over WiFi. It's not quite function calls, but it's conceptually the same thing - when you receive a certain message, your firmware can start/stop sampling etc.

Re: Integrating micropython into python project

Posted: Thu Aug 01, 2019 8:12 am
by lenthal22
Thanks Jimmo. For now I've managed to grab the txt file using rshell. However, this process is very slow. Using your suggestion, what sampling speeds do you think I could achieve? Could I theoretically achieve real time communication over wifi without losing too many data points?

Thanks in advance.
L.22