uPydevice - Python library to interface with Micropython devices (WebREPL or Serial connection)

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

uPydevice - Python library to interface with Micropython devices (WebREPL or Serial connection)

Post by cgglzpy » Mon Oct 21, 2019 4:22 pm

Hi, I've been working on a simple python library based on my previous work uPydev (see viewtopic.php?f=15&t=6808).

This library 'uPydevice' is basically a couple of python classes that defines a MicroPython based device (wireless or serial), so it is possible to send commands and receive its output easily. There is more info here https://github.com/Carglglz/upydevice

It is on PYPI so it can be installed with:

Code: Select all

$ pip install upydevice
A simple example would be:

Code: Select all

>>> from upydevice import W_UPYDEVICE
>>> esp32 = W_UPYDEVICE('192.168.1.56', 'mypass')
>>> esp32.cmd("uos.listdir('/')")
['boot.py', 'webrepl_cfg.py', 'main.py']
It works in Jupyter Notebooks, python REPL / python scripts, etc, so it can be implemented in python command line tools or python applications (tested on PyQT) for example.

Full documentation is still on the way, but I will try to upload more examples in the next month.

Cheers.

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: uPydevice - Python library to interface with Micropython devices (WebREPL or Serial connection)

Post by cgglzpy » Mon Oct 28, 2019 5:00 pm

Hi, the documentation is now in the GitHub repo DOCS

Also I've introduced some decorators that allow to do something like this:

Code: Select all

# In MicroPython do:
from pyb import LED

# In Python3 do:
from upydevice import PYBOARD, upy_cmd_c
pyboard = PYBOARD('/dev/tty.usbmodem3370377430372')

class LED:
    def __init__(self, number):
        """Phantom pyb.LED class"""
        self.name="{}({})".format('LED', number)
    
    @upy_cmd_c(pyboard, rtn=False)
    def toggle(self):
        return self.name

green_led = LED(2)
green_led.toggle()
Or like this:

Code: Select all

from upydevice import W_UPYDEVICE, upy_cmd_c
esp32 = W_UPYDEVICE('192.168.1.53', 'mypass')

class UOS:
    def __init__(self):
      """Phantom UOS class"""
      self.name='uos'
   
    @upy_cmd_c(esp32)
    def listdir(self, directory):
      return self.name
      
    @upy_cmd_c_raw(esp32)
    def uname(self):
      return self.name

uos = UOS()


uos.listdir('/')
['boot.py', 'webrepl_cfg.py', 'main.py', 'lib']

uos.uname()
(sysname='esp32', nodename='esp32', release='1.11.0', version='v1.11-422-g98c2eabaf on 2019-10-11', machine='ESP32 module with ESP32')
Enjoy!

Post Reply