Accessing buttons and switch of wio terminal with ardupy

Hello,
I understand that the ardupy is still in early phase, for instance wifi and BLE librairies, and I am fine with that.

However I think it would be possible to easily provide access to the buttons and switch under ardupy.

The equivalent of WIO_KEY_A , WIO_KEY_B and WIO_KEY_C under Arduino. Just a pin HIGH or LOW.

Same for the switch.

Best,
Francois

I don’t know the answer but you might want to post this in the WIO Terminal section as well.

Hi @Losaure

Please refer to this: https://github.com/Seeed-Studio/ArduPy/blob/master/boards/wio_terminal/mphalport.h

1 Like

https://github.com/Seeed-Studio/ArduPy/blob/master/ports/samd/boards/wio_terminal/mphalport.h
The link returns 404. This one can direct to the definitions.

404 ?

Yep, 404. I mean his link returns 404. Probably typo?

You’re right. The software has been updated until it has been adjusted.

This issue doesn’t seem to be resolved as there is not a well documented example. In short, the key aspect that appears missing is the concept of interrupts. As opposed to the core micropython Pin definition, which includes interrupts and handlers (http://docs.micropython.org/en/v1.9.3/esp8266/esp8266/tutorial/pins.html), the current Ardupy build does not include this option. When probing the Pin class functions and attributes only the following are listed:

help(Pin)
object <class ‘Pin’> is of type type
init –
value –
off –
on –
IN – 0
OUT – 1
PULL_UP – 2
PULL_DOWN – 3
IRQ_RISING – 4
IRQ_FALLING – 3
IRQ_CHANGE – 2

So the core question remains, in order to make the Wio Terminal functional with the included buttons, what is the plan to get handlers and interrupts working?

Finally, how do we wrap other Arduino libraries (e.g. https://github.com/Dennis-van-Gils/SAMD51_InterruptTimer)

Other suggestings include: MQTT, Wifi, and a read/write CSV file from SD card. Please, please make this happen. It is a nice little unit with loads of potential.

Hi,
We will bring the external interrupts/ handlers feature to ArduPy in the near future.

Also to answer your second question, you could convert the existing Arduino library to an ArduPy library by following our guide. It is available as a wiki and also as a video.

Finally as per your suggestions, currently the mentioned features such as MQTT, Wi-Fi, and SD card usage are only available to use with Arduino. But we will think about adding these features into ArduPy as well.

Best Regards,
Lakshantha

1 Like

Lakshantha,

I’m glad to hear these items are on the docket. Having some solid examples using interrupts would greatly expand the utility. As I’m sure you are aware CircuitPython does not support interrupts. Please don’t go down that route. A key concept with microcontrollers is obviously the capacity to switch tasks immediately. Keep up the good work. Any chane you all could add a wrapper to the ArduinoMenu library? That could be a slick way to build in some simple UI concepts.

Cheers.

Thank you!

Currently, we don’t have a plan to add a wrapper to the ArduinoMenu library. However, we will let you know if we do so.

Best Regards,
Lakshantha

For those interested, here is a solution using Circuitpython. The only required library not included in the distribution is the debounce library. Works reasonably well. To get this to work with Ardupy, I had to put in the exact pin numbers which was a real pain–it was for this reason that after coding up the 2nd button I bailed on that approach. Until regular updates occur with Ardupy, I’m gonna work with Circuitpython. However, I’d love to have true interrupts with the micropython support.

Finally, I know the code could be cleaner…

Cheers

Using Circuitpython 6.0

import time
import board
from digitalio import DigitalInOut, Direction, Pull
from adafruit_debouncer import Debouncer


led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT


def setupWioButton(pinRef):
    pin = DigitalInOut(pinRef)
    pin.direction = Direction.INPUT
    pin.pull = Pull.UP
    button = Debouncer(pin)
    return button


buttonNames = ['A', 'B', 'C']
buttonList = [board.BUTTON_3, board.BUTTON_2, board.BUTTON_1]
buttonDict = {}

for i,b in enumerate(buttonNames):
    buttonDict[b] = setupWioButton(buttonList[i])



joyNames = ['DOWN', 'LEFT', 'PRESS', 'RIGHT', 'UP']
joyList = [board.SWITCH_DOWN,
               board.SWITCH_LEFT,
               board.SWITCH_PRESS,
               board.SWITCH_RIGHT,
               board.SWITCH_UP]

joyDict = {}

for i,j in enumerate(joyNames):
    joyDict[j] = setupWioButton(joyList[i])


while True:
    for i,b in enumerate(buttonNames):
        curSwitch = buttonDict[b]
        curSwitch.update()
        if curSwitch.fell:
            print("Button %s Pressed"%b)
            led.value = True
            # print("LED ON")
            time.sleep(1)
        if curSwitch.rose:
            print("Button %s Released"%b)
            led.value = False
            # print("LED OFF")
            time.sleep(1)

    for i,j in enumerate(joyNames):
        curSwitch = joyDict[j]
        curSwitch.update()
        if curSwitch.fell:
            print("Joystick %s"%j)