Pico:ed V2 - an Introduction
by tonygo2 in Circuits > Microcontrollers
2199 Views, 1 Favorites, 0 Comments
Pico:ed V2 - an Introduction
Elecfreaks have just brought out a new microcontroller board powered by the RP2040 and I would like to show you what it can do. This Instructable covers basic sound, using the built in LED, buttons and what can be done with the 17x7 LED display. In a separate program I will also demonstrate how to drive a ring of 8 Neopixels.
Supplies
- An Elecfreaks Pico:ed V2
- A USB micro to A cable
- Thonny Editor - free download
- A computer to program the microcontroller
- Neopixel ring or strip
Differences Between V1 and V2 - Front
The face appears very similar with a 17x7 LED display, two buttons, connections along the bottom edge, now scalloped, rounded top corners and a less severe colour pallet, probably to give a greater appeal to girls. The Built in LED on pin P25 remains in the dot of the ‘i ’in Pico.
Differences Between V1 and V2 - Back
On the reverse we see that the components have been rearranged and an additional button added, a reset button. The buzzer has been moved from GP0 to P3.
Pinout
This board has been designed to be a slot in replacement for a BBC micro:bit and can make use of a wide range of previously available add-ons such as breadboard connectors, sensors, robot platforms, graphical displays and LED strips. The powerful and up to date built-in RP2040 chip, with plenty of memory, makes it a great upgrade for those with micro:bit kit wishing to upgrade their coding skills from blocks to Python.
Software & Documentation
With Pico:ed V1 Elecfreaks opted for MicroPython as the programming language. With V2 they have chosen Circuitpython. You can use either flavour of with both boards. My V2 board came with CircuitPython already installed:
Adafruit CircuitPython 7.3.3 on 2022-08-29; ELECFREAKS PICO:ED with rp2040
There were also a few files already installed in the lib folder which are shown above on the right. In addition, was a program called code.py. This appears to be test program. It sets all the digital lines as outputs, and then waits for both button A and Button B to be pressed together. It then lights up all the display LEDs. It crashes as it tries to write to an i2c device. You can safely delete it or over-write it.
Elecfreaks have provided excellent documentation in their wiki. It explains, in detail, how to install Thonny, update the firmware in the Pico:ed, if necessary, and how to use the board. You can read it here:
https://www.elecfreaks.com/learn-en/pico-ed/index.html
The documentation for the Starter Kit can be found here:
https://www.elecfreaks.com/learn-en/pico-ed-kit/pico-ed-starter-kit/index.html
It explains how to use the commonly available electronic components such as LEDs, buttons, potentiometers and motors etc.
CircuitPython has a great deal of support online with many examples of the use of peripheral devices such as sensors and display screens. This new board provides a useful additional heart for a project. One of the major differences with this BBC board is the built-in screen of 7 rows of 17 LEDs - a great improvement over the 5x5 display on the BBC micro:bit. My main project demonstrates how to make good use of the screen.
Pin Names
>>> import board
>>> dir(board)
['__class__', '__name__', 'A0', 'A1', 'A2', 'A3', 'BUTTON_A', 'BUTTON_B', 'BUZZER', 'BUZZER_GP0', 'BUZZER_GP3', 'I2C0_SCL', 'I2C0_SDA', 'LED', 'P0', 'P0_A0', 'P1', 'P10', 'P11', 'P12', 'P13', 'P14', 'P15', 'P16', 'P19', 'P1_A1', 'P2', 'P20', 'P2_A2', 'P3', 'P3_A3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'SCL', 'SDA', 'SMPS_MODE', 'VBUS_SENSE', 'board_id']
This was obtained by typing at the prompt in the REPL window at the bottom of the Thonny screen.
Built-in Modules
This also was obtained by typing at the prompt in the REPL window. It lists all the library modules available. You can add additional library modes to the lib folder if needed.
Graphics Project
Here you can view a video of the programming running and download the CircuitPython code.
I will go through the code, step by step, in the following pages. It starts with basic beeps on the built-in buzzer and then takes you through how to use the display.
Basic Tones and Scrolling
The necessary libraries are imported, and a few notes are played. (You need to use the music library to send tones to the built-in buzzer as picoed library takes control of pin P3, connected to the built-in buzzer. You cannot use pwmio to generate tones for the built-in buzzer.)
The width and height of the display are saved and a short procedure, blit(s,x,y,w,h,v) is defined. (It helps to copy a small user defined image to the display.)
The titles are scrolled across the display and then the display is set to different two brightness levels. If the string to be scrolled is 3 characters or less, it remains stationary, but if longer it scrolls.
Part 2 - Changing Brightness
This section draws lines on the display, shows a single pixel getting steadily brighter and a line of pixels with increasing brightness.
This is followed by the edges of the screen being slowing filled in. Note that trying to light up pixels which do not physically exist does not cause an error. The system ignores them - very useful.
Finally, the screen is filled with a graduated display.
Part 3 -Diagonal Line, Squares and Image
The instruction display.pixel(3,4,20) lights up the 4th pixel from the left in the 5th row with brightness 20. (Computers count from zero.) They change immediately. I soon noticed that as you turned pixels on and off you created a rippling effect across the screen and occasional random and irritating flashes from parts of the screen you were not writing to.
The documentation suggests that you use display.sleep(True) to turn off the instant updating while you change pixels and then expose the changes with display.sleep(False) when you have finished the changes.
You can also write to different screen buffers, or frames, numbered 0 - 7. I found that using frames and the corresponding display.frame(frame, show=False) and display.frame(frame, show=True) worked very well in suppressing the screen jitter.
In this section we see a moving diagonal line, a screen full of squares and a simple method of creating and displaying a full-screen image - sunglasses. (I think this method will be easier for children to understand than the list of hexadecimal numbers representing the 17 columns used by Elecfreaks.)
Part 4 - a Bouncing Pixel & Built-in Images
Here a single lit pixel is moved about the screen bouncing off the edges until Button A is pressed and some of the built-in images are displayed.
Part 5 - Defining & Moving Small Images
Here a small heart image is defined and the blit(s,x,y,w,h,v) procedure, defined earlier, is used to position in the display. Initially it is stationary and then it moves across the screen.
- s = image string
- x = horizonal position on screen
- y = vertical position on screen
- w = width of image
- h = height of image
- v = brightness of image pixels
I have commented out the jitter suppression - which does not appear to be too intrusive here.
Part 6 - Swimming Ducks
Stationary and moving ducks. They are smaller at 6x6 than the heart with 6x7 pixels.
Part 7 - Flashing the Built-in LED
The built-in LED is flashed, and stationary text displayed before clearing the display.
Driving a Neopixel Ring
Here is a video and the code using a Pico:ed V2 to drive an Elecfreaks 8 Neopixel ring. The Code follows.
Downloads
Part 1
The code includes two new methods of making the buzzer beep.
music.play("c2:1") # plays a single note for 1 short beat
music.pitch(440) # Sets the buzzer to 440 Hz - forever
music.pitch(0) # Turns it off - thank goodness!
You can put a time delay between the two instructions.
It is all explained in the documentation. (See step-4 for the link.)
Each Neopixel contains a green, red and blue LED which can be set in the range 0-255. We need a buffer to hold the 3 colours for each of the 8 Neopixels (24) before we tell them all to update in a single burst of activity as we send the buffer values out on the data line. We have 8 Neopixels (0-7) in the program but are marked (1-8) on the ring.
I've provided three procedures to aid the process:
neo_clear() sets all 24 values in the buffer to 0 - black/OFF
neo_set(p,r,g,b) sets the red, green and blue values in the buffer for Neopixel[p]
neo_update() sends the buffer data to the individual Neopixels and they change to the new settings as necessary.
The first part of the code sets each of the Neopixels to a different colour.
Part 2
This sets red and green pixels apparently rotating in opposite directions - making yellow when they overlap and emitting a beep. They speed up as time passes.
After 50 steps the rings clears at the end of the program.
Conclusion
I hope you have found this tutorial helpful.
I've enjoyed playing with this board (and returning to CircuitPython after more than a year of sticking with MicroPython.) Both versions are very useful, well built, and easily connect to my existing micro:bit kit. They are easy to program and the documentation from Elecfreaks is of a high standard, please read it. They normally reply on the web helpline pretty quickly, in excellent English. The powerful RP2040 provides both versions with plenty of room for large and complicated programs and which language you decide to use is a personal choice. The RESET button on V2 is a bonus. Do not forget that this a RP2040 board and can do pretty much everything that a Pi Pico can do including driving displays with loads of colourful pixels via SPI or a simple and cheap SSD1306 mono display via i2c. CircuitPython probably has more device drivers at the moment, but MicroPython is catching up.
Either board will be very useful in helping make the progression from block coding to Python while making use of existing components.
Feedback and questions are welcome.