There is no denying that the release of the Raspberry Pi Pico, made Micropython even more popular. Board developed primary for Micropython and C++, sparked the interest of makers of all ages. Where there is interest, the manufacturers follow. I ended up with a Raspberry Pi Pico kit (AmazonUK, AmazonUS) put together by GeeekPi, so let’s see what’s inside and how useful it is for makers.

## GeeekPi Raspberry Pi Pico kit

I’m always in favour of learning kits, as these give you a sense of direction where GeeekPi kit brings the most popular modules in a single box with a custom PCB board to house the Pico board and break out all GPIO pins in an orderly fashion.

### Inside the box

Apart from the Raspberry Pi Pico, my kit contains (note that I got the advanced version of the kit, with other configurations available):

There is enough hardware there to keep you busy for some time and get you familiar with different data protocols and ways to command and obtain data.

#### Pico breakout board

It’s a handy little board that has a space for a mini breadboard and breaks out all GPIO pins from Raspberry Pi Pico. In addition to that, 3.3V, 5V and GND rails are included and the board comes with 4 push buttons and 4 LEDs that you can use in your project.

There is a buzzer in the corner which you have to connect to GND if it makes random sounds.

#### Pico guide

The book does a very good job at explaining how individual modules work and goes to fair depth to underline the working principles of boards like MPU6050 or LED matrix. It’s a great read if you want to know how exactly sensors and modules work and report back.

I wish the same could be said for the project part of the book. It’s an illustrated manual of how to get the wires connected with “links” to libraries with the source code. None of the project code is explained or laid out in the teaching manner. If you want to learn how to program, you will be disappointed, as you are expected to understand things by looking at the attached examples.

It’s a shame as what started to be pretty in-depth instructions on sensors and modules ended up skimming over the programming part. If you want to understand how programming logic works, you will need another guide online for that.

## My RaspberryPi Pico experiments

I wanted to use Micropython more. GeeekPi provides a GitHub page with project code to mess around with, so I downloaded that and Thonny to get started. The wiring instructions are provided for each module in the booklet, so I decided to work with MPU6050 and neopixel ring.

A long time ago, I have seen someone using a neopixel ring to display which way the board is leaning. I wanted to have a programming crack at it. The demo code for LED ringboard and MPU6050 contains the functions that will get you the data and show you how to set up a state machine on Pico to drive LED, so all I needed to do is to code the logic.

MPU6050 data is processed by the scrip as x(-5, 5) & y(-5,5) ranges, which brings me beautifully to schooldays where algebra and geometry mattered much more than in my life as a 30-something old human being.

I think you can quickly see that I can plot these values on an x/y graph and perform interesting mathematical operations to convert these into the information of which LED ring should light up.

#### Circles are just triangles in disguise

xÂ² + yÂ²=rÂ²

Pitagora theorem

Circles are many things. They are also triangles hiding in plain sight. Drawing a circle on an XY graph with a radius between the centre point and the coordinate values gives you a lot of data to work with.

On a plane where XY corresponds to tilt and pitch, values can be drawn on a graph where vector direction is represented by the angle between one of the axis and hypotenuse (radius) and the strength is represented by the vector’s length.

- R= strenght of the lean
- Î±= direction of the tilt

To light up the correct LED on a neopixel ring, I need to know the angle between a fixed-line (in my case X-axis) and the hypotenuse. To colour the LED lights accordingly, I need to know how strong is the tilt in that direction (it’s a vector value between values supplied by X and Y).

Armed with that knowledge I can get these values from the following equations:

```
angle = math.sqrt((roll*roll) + (pitch * pitch))
pixel = math.degrees(math.atan2(roll, pitch))
```

As the raw values are not compatible with the script, I need to process it further to get ones in line with the library controlling neopixel LEDs. For the angle strength, these are: absolute value, mapped range and not letting the angle (brightness go over 1.0).

To find the correct pixel, I needed radians changed to degrees and round up the division to the nearest integer.

```
angle_strength = min(convert(math.fabs(math.sqrt((roll*roll) + (pitch * pitch))), 0, 5, 0, 1), 1.0)
pixel = math.ceil(math.degrees(math.atan2(roll, pitch)) / 22.5)
```

Now the angle will get the values from 0-1 and the pixel will create a 16 element array (from -8 to 8). I accidentally used an unknown, to me, property of python, where the elements would be sorted in such a way, that I don’t have to recalculate the figures again to get 0-16 numbers.

What’s left, is to drive these with existing LED functions based on the value of the angle coming from MPU6050:

```
if angle_strength < 30:
pixels_fill(PURPLE)
pixels_show()
if angle_strength > 29:
pixels_fill(BLACK)
pixels_show()
pixels_set(pixel, WHITE)
pixels_show()
```

Take a closer look at `pixels_show()`

function, to understand the brightness substitution and the convert function which basically maps the value to a new range. These are included in the final version of the code below.

## Final thoughts

Raspberry Pi Pico kit by GeeekPi (AmazonUK, AmazonUS) is for anyone familiar with programming in C++/Microphyton who would like to learn more about interfacing with sensors and modules. Total beginners will feel lost without separate lessons on programming. The advanced kit makes it easy to try modules out and have the basics covered. If you are looking to experiment with Raspberry Pi Pico, then the GeeekPi kit could be for you. Let me know if you have any questions in this Reddit thread.

ðŸ†“ðŸ“ˆ – See the transparency note for details.