New MicroPython ports on Simba OS

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
eerimoq
Posts: 9
Joined: Mon Sep 26, 2016 5:44 pm

New MicroPython ports on Simba OS

Post by eerimoq » Sun Oct 02, 2016 9:20 pm

Hello,

during the last few years I've been implementing a micro kernel,
drivers and a bunch of other utilitiy modules. It's called Simba. It's
imlpemented in C, open source, free to use and available on Github,
PlatformIO and in the Arduino IDE.

Recently I found MicroPython and was really impressed by the features
and simplicity, and as it was written in C, just as Simba, it was a
fairly simple operation to make MicroPython run on top of Simba. The
Lion King naming continued and I called it Pumbaa. Silly name, I
know... So far it has been tested on three boards; Arduino Due, ESP12-E
and Particle IO Photon (and simulation on Linux), and it works
surprisingly well.

The project started as an experiment to explore MicroPython, and since
I find the experiment a success I intend to continue the
development. As of today my plan is to implement a thin Python wrapper
of most Simba modules (kernel, drivers, sync) to make them avaiable in
Python. This means that I do not intend to implement the machine and
pyb modules, but instead something close to the Simba drivers
package. This is probably a mistake, but will do for now. If the
future of Pumbaa turns in another direction, so be it.

More information about Pumbaa is available on Github and ReadTheDocs:

https://github.com/eerimoq/pumbaa
http://pumbaa.readthedocs.io/en/latest

... and here is some information about Simba:

http://simba-os.readthedocs.io/en/latest
https://github.com/eerimoq/simba

In the long term it would be lovely if Pumbaa somehow could be
considered part of MicroPython, in some sense it is already, just
stored in a separate repository.

Anyway, thanks for MicroPython! It certainly has a bright future!

eerimoq
Posts: 9
Joined: Mon Sep 26, 2016 5:44 pm

Re: New MicroPython ports on Simba OS

Post by eerimoq » Sat Oct 08, 2016 6:58 am

Hi,

here is an example of how to use poll in the select module in Pumbaa.

Using poll makes waiting for input from many sources in a single thread simple, and without timeouts or delays. In Pumbaa there are three kinds of objects that can be polled; Event, Queue and SocketType. Event and Queue are used for inter thread communication and to resume a thread from an interrupt. Sockets are for networking. Allowing polling of these three objects often makes the implementation clean and easy to understand.

In the example below three channels are polled:

1. An event channel that waits for a button to be pressed.
2. A queue channel that the string "foo" is written to in the script.
3. A socket channel waiting for UDP packets.

Documentation: http://pumbaa.readthedocs.io/en/latest/ ... elect.html
Source on Github: https://github.com/eerimoq/pumbaa/blob/ ... ct/main.py

Code: Select all

import select
import socket
from sync import Event, Queue
from drivers import Exti
import board

BUTTON_PIN = board.PIN_GPIO0
UDP_ADDRESS = '192.168.1.103'
UDP_PORT = 30303

button = Event()
exti = Exti(BUTTON_PIN, Exti.FALLING, button, 0x1)

queue = Queue()

udp = socket.socket(type=socket.SOCK_DGRAM)
udp.bind((UDP_ADDRESS, UDP_PORT))

poll = select.poll()
poll.register(button)
poll.register(queue)
poll.register(udp)

queue.write('foo')

while True:
    [(channel, eventmask)] = poll.poll()

    if channel is button:
        button.read(0x1)
        print("button")
    elif channel is queue:
        print("queue:", queue.read(3))
    elif channel is udp:
        print("udp:", udp.recv(1024))

Post Reply