Naveen
Published © MIT

Using MicroPython on Seeed Wio Link

Deploying MicroPython on Wio Link development board.

IntermediateFull instructions provided30 minutes59
Using MicroPython on Seeed Wio Link

Things used in this project

Hardware components

Wio Link
Seeed Wio Link
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Code

wiolink_grove_ultrasonic_ranger.py

MicroPython
MicroPython class to get readings from a Grove ultrasonic Ranger in centimeters.
from machine import Pin, time_pulse_us
from time import sleep_us

class GroveUltrasonicRanger:
    def __init__(self, sig_pin, timeout=10000):
        self.sig_pin = sig_pin
        self.timeout = timeout

    def activate(self):
        self.signal = Pin(self.sig_pin, mode=Pin.OUT) # trigger pin
        self.signal.value(0)
        sleep_us(2)
        self.signal.value(1)
        sleep_us(10)
        self.signal.value(0)
        self.signal = Pin(self.sig_pin, mode=Pin.IN) # echo pin

    def get_distance(self):
        self.activate()
        t = time_pulse_us(self.signal, 1, self.timeout)
        distance = t / 29 / 2 # in centimeters
        return distance

Credits

Naveen

Naveen

1 project • 0 followers
Day time bioinformatician, maker at heart.

Comments

Add projectSign up / Login