Outils pour utilisateurs

Outils du site


issue196:micro-ci_micro-la

Ceci est une ancienne révision du document !


OHHHHH WIIIIO … WIOOOOOO

Greetings again, fellow beings. It’s me again, broadcasting from across the known universe!

Awwww, ok. Not from across the known universe. From Central Texas, but it sounded kinda cool, huh?

First, you might be wondering what the heck the title of this month’s article is, or if you figured it out already, why am I butchering the Castle Guard chant from the Wizard of Oz? (Ronnie says: extra point if you can name the Metallica song that uses that chant).

It’s talking about the Wio Terminal from Seeed Studio (YES with all the “e’s” in Seeed).

It’s a REALLY neat little device that has a HUGE amount of potential and has recently gotten micropython support.

If you look REALLY close at the top of the image, you will see three little blue bumps on the left side of the device. That’s three user defined buttons. At the bottom-right of the device, there’s a four-way thumb pad that also can be depressed for a fifth button for a total of 8 buttons.

The screen is a 2.4” 320×240 touchscreen and there is an onboard IMU(LIS3DHTR), microphone, buzzer, microSD card slot, light sensor, infrared emitter(IR 940nm) and more!

In addition to all of that, there is a Raspberry Pi 40-pin Compatible GPIO female header on the back that should allow you to use any RPi that that you might have, if you happen to have Micropython drivers for them. One more thing of note (at the moment), the Wio has 512KB of Program memory, 4MB of External Flash memory, and has 192KB of ram.

There is also WiFi and bluetooth. I must admit that I don’t think the touchscreen interface, WiFi and bluetooth are working quite yet. I have also seen some comments that I2C and SPI don’t work well at this point, but I haven’t had a chance to test those yet.

All of this for about $45 USD makes this a great little device to test out. So, let’s get started!

Loading Micropython

Before we can get started, we need to load Micropython onto the device. Go to https://micropython.org/download/SEEED_WIO_TERMINAL/ and download the latest nightly build.

Next, plug the device into your computer using the USB Type-C connector. In a terminal type

$ ls /dev/tty*

This should show you all the tty ports and you should (by this point) be able to figure out which one the Wio is plugged into.

Now, here is the difficult part. You need to put the Wio into bootloader mode. The power switch on the left side of the device has three positions. Up is off, middle position is on, and down is a momentary position for reset. Push the switch all the way down twice very quickly. It can take a number of seconds to “kick in”, but just like with the RPi Pico, you should see a new File browser window open. Now drag and drop the UF2 file you just downloaded into the File Browser window and wait about 10 seconds. Once the window disappears, you are ready to go.

Now open Thonny and select the Generic Micropython on your USB port. In a moment, you should see the REPL show the Micropython version and prompt.

PROJECT 1 - LED

There is a blue LED inside the Wio just to the left of the USB-C connector. In this simple project, we’ll make it flash.

Copy this code (top right) into your Thonny code window and save it to the Wio as “wio_terminal_LED.py”.

Now run it. If everything works, in a couple of seconds look at the bottom of the Wio just to the left of the USB connector. You should see the LED flashing. To get it to stop, you can reset the Wio, turn it off for a moment, or press the stop button in Thonny.

Project 2 - Button Test

I REALLY wanted to call this section “Button, Button, Who pressed the button”, but I didn’t. Aren’t you glad?

This next project will test all 8 of the user buttons, the three on the top, the four way thumb switch and the press of the thumb button.

Get the code (bottom right)and name it “Wio_terminal_Buttons.py”. Copy it to the Wio memory.

The first part of the program does the imports and creates a list with the names of the buttons. The WIO apparently has three ways to name the pins. First is a string like “BUTTON_3”, the second is a pin definition and the third is a pin definition using a scheme like the GPIO name, but named to the WIO specifications.

The diagram (next page) is available at https://www.seeedstudio.com/Wio-Terminal-p-4509.html .

Anyway, the rest of the code (bottom left) handles setting up the actual pins, and then looping until a button is pressed. Then it will print a “1” for which of the 8 pins was pressed. The output in the REPL is a simple string of 8 zeros like this “00000000”. The far left position is the top left button, the next position is the top middle button, and so on, ending with the thumb pad press button.

So when you run the program, the output in the REPL continually prints

0000000

Until one of the buttons is pressed. Then that position turns to a “1” until the button is released. Since the program polls all the button pins, you could see multiple “1”s in the string of zeros. For example, if you pressed all three of the top buttons at the same time, you would see

11100000

Project 3 - Graphics on the screen

Now for the hard project. It is a series of coloured diamonds animated on the screen. For this, you need to download the screen driver from https://github.com/rdagger/micropython-ili9341/blob/master/ili9341.py. You can move up a level and get the entire zip from the same base site. Copy the ili9341.py file onto the Wio. Then you will want to copy the following code (top right) onto the Wio.

This first part is simply the header and the import section.

The next function (bottom right) (wheel565) takes a value and returns a RGB color value. Next (top right), the LED that we played with in Project 1 is used to signal things are working. The screen is a bit slow to turn on.

The next bit of code (bottom right) creates the coloured pixels and coloured rectangles, draws them on the screen and then keeps looping.

Finally, if the program is ended, the backlight is turned off, the led is turned off, and the display itself is turned off.

This code is from the website

https://scruss.com/blog/2022/11/04/micropython-on-the-seeed-studio-wio-terminal-it-works/ . There is a small bug in the published code there, but the author left a comment near the bottom of the page on how to fix it. I’ve already put the fix in the above code and the code in my repository.

Name the program “wio_terminal_screen.py”. When you run it, you will see something like this (and in MUCH better definition and animation).

I’m running out of time and space here, so I’m going to leave you hanging on this for now. I haven’t really had much chance to test any more of the WIO either I2C support, WiFi support or any further into the Screen library. I’ll try to give you an update on my website (https://thedesignatedgeek.xyz ) and something updated next month.

Until then, if you are interested in learning more about the WIO Terminal, here are some good links to get you started…

https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/

https://wiki.seeedstudio.com/Wio_Terminal_Intro/

The next link is to a site with a number of good projects and is where I got the three projects for you. https://scruss.com/blog/2022/11/04/micropython-on-the-seeed-studio-wio-terminal-it-works/

https://www.youtube.com/watch?v=Q0sv9TyYHHQ

As I often try to do, I have put the three project files and the base screen driver in a github repository at https://github.com/gregwa1953/FCM196_MTMT .

By the way, neither Full Circle Magazine nor I get paid or receive free products for any of the devices that I review here.

Until then, as always; stay safe, healthy, positive and creative!

issue196/micro-ci_micro-la.1692979489.txt.gz · Dernière modification : 2023/08/25 18:04 de auntiee