• Micropython: Using Coroutines for blinking LEDs Micropython

    I just made my first steps with the uasyncio module in Micropython and I'm impressed. Here is a small example how to use coroutines for letting all 3 LEDs on the Pyboard v1.1 blink with different intervals. The resulting code is unexpectedly short but also readable.

    import pyb
    import uasyncio as asyncio
    
    
    async def blink_led(led, interval_s):
        """Let the LED blink in the given interval."""
        while True:
            await asyncio.sleep(interval_s)
            led.toggle()
    
    
    led_red = pyb.LED(1)  # red led on the pyboard
    led_green = pyb.LED(2)  # green led on the pyboard
    led_yellow = pyb.LED(3)  # yellow led on the pyboard
    
    
    # get a new event loop
    loop = asyncio.get_event_loop()
    
    # create new tasks for each led
    loop.call_soon(blink_led(led_red, interval_s=0.5))
    loop.call_soon(blink_led(led_green, interval_s=1))
    loop.call_soon(blink_led(led_yellow, interval_s=2))
    
    # run all tasks
    loop.run_forever()
    

    For a comprehensive tutorial on Micropython async have a look at https://github.com/peterhinch/micropython-async.

  • WiPy2 Micropython: Temperature measuring via 1-Wire Micropython

    One of the first IoT use cases that comes in ones mind ist measuring the temperature of your environment. An easy and cost-efficient way is to use an 1-Wire bus sensor like the DS18S20. You can get this sensor for around 2,15€ and it is really easy to implement in your µC as there are a bunch of libraries for the 1-Wire protocol. So the first thing to do is put the sensor in a bread board and connect it to your WiPy2 breakout board. The pin assignment is simple. Connect Pin1 of the sensor to GND, Pin2 to G10 and Pin3 to 3.3V. That' s it.

    WiPy2_with_DS1820

    Read more
  • WiPy2 Micropython: Getting started Micropython

    Lately I proudly got hold of a WiPy2.0 board and this post is about how I got started with it, established a connection to my Wifi and made the WiPy to connect automatically on boot.

    Read more