Raspberry Pi PICO and the pico display

I confess, I wasn't going to do this.

I wasn't going to go down this rabbit-hole.

I wasn't going to write any Python (Micro or otherwise).

I wasn't going to stay up until 1am, 2am, 3am on several different nights, including Dec 25th... "just figuring out this last one bit".

I wasn't.

But, I did......

and in a way, I am kind of glad that I did.  It won't help me very much, but it might help some genuine youngsters out there who are wanting to cut their teeth on some code and want to build on something that actually exists & works (I'll come back to that later).

As mentioned previously, I re-kindled an amusement of fun with an old Atari 800 XL and the sheer fact that you used to be able to just turn it on and get a blue screen (not THAT type of blue screen) with the word:

READY

[_]

with a flashing (or sometimes not) cursor, you were the artist.  You were the creative one.  You had the freedom to turn a blank (blue) canvas into something that you created.  Obviously, you didn't throw paint at the computer, you started to write BASIC code directly onto the screen and then when you'd finished you typed LIST to see it all scroll up the screen and then you saved it (you did save it first, didn't you?! I know professional people who still fall fowl of not saving their work regularly!) and then you typed RUN.

After you dealt with the 'syntax_error on line xx' debugging exercises, the program executed and you could see the many hours of work "doing stuff".....and you'd find those, "I didn't expect it to do that" bugs that you made a note of, pressed BREAK, fixed the code and re-ran it all again... you inventor / creator you!

Yes... I have a lot of very old memories of doing that - in fact, that is how it started in around 1985 and pretty much hasn't changed since!  The tools, the language, the syntax, the platform, the complexity  may have changed, but in essence the same tasks are still performed. I actually enjoy it.  As you shall see!

Introduction

Right, what has this got to do with a Raspberry Pi Pico and a Pico display? First of all, what the hell is a Pico?

I could explain, but others have done a better job - I'll let them give the details.  Summary: It's a cheap microprocessor board (that is the size of a small Arduino) that allows you to run low-level C-code (like an Arduino does), but it also allows you to run MicroPython too....

I won't beat around the bush - I'm not a fan of Python. In fact, I dislike it....a lot.  However, everything, including wasps, have a purpose of some kind - you just have to find it.  Python programming is a bit like those early MicroComputer BASIC days, without the GOTO commands (but just as bad in a lot of other ways), it doesn't belong in the Enterprise environment, it's place is to teach children the concepts of a programming language and how to have fun doing it.  They sholdn't have to get their heads around how to handle malloc() and pointers, well, not until they are at least old enough to drive a car :-)


This PICO device allows you to use an IDE of your choice (sorry, you can't have a READY prompt anymore), so, use a tool like Thonny IDE (easiest one I've found to use).  Connect to the device, drop the .uf2 file that has all the libraries installed onto it for you to execute the MicroPython libraries etc... and then write you own Python code.

One drawback is that the Pico is a small microprocessor board with a load of GPIO pins available (including WiFi - we'll come to that much later - yes, I do have one setup as a web-server) and a single micro-USB port to do data transfer and power... it does not have a screen output.

As mentioned it does have a ton of GPIO pins.... and it actually isn't that much effort to make use of a bunch of the top-left pins to handle a VGA output (if you don't mind a soldering iron and have a few resistors going spare) - most people however, will look for a ready-made display.

Now....there are a TON of small LCD/TFT screens out there.  I actually found a box that contained a bunch I previously bought for a project - turns out they were from 2013! (yes, nearly 10years ago!) whilst they were perfectly fine and technically could be used, the drivers for them no longer worked with modern equipment.... yeah, I have e-waste and I hate that too.

Pico display

This nice company called PIMORONI make a PICO DISPLAY that can be clicked onto the back of the RPi PICO itself or onto an expansion board.

This is a really good design choice and is a total no-brainer.  Especially at £15....

An added bonus is that it comes with 4-buttons that you can access / use in code - that'll come in useful later on, I'm sure.

The very nice web-page even provide a link to a graphics library that you can use to interact with the display: https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/picographics

They provide a nice link to some example:

https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/examples/pico_display

You get the demo's working and watch the balls bouncing around the screen and are dead impressed.

...and that's where the next section starts...

Problems

The link to the graphics library is essential, so bookmark it (twice):

https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/picographics

As you'll be referencing it a lot and scratching your head a lot, maybe.  It's a nice page, however, it does appear to do a lot of explanations about screens that you are not that familiar with and you scroll down a bit more and then you see what you think you need to see.

References to how to draw things onto the screen, circles, rectangles, triangles, lines and Text.... sounds ideal.....that'll come back and bite you later on, trust me.

Then you think, quite rightly to yourself - "I know what, someone has obviously done a lot of this before, I'll just search online for any usage of the 'picographics' library and find me some examples".

And that is where you problems begin.  You will find out, like I did, that there was a library called "picographics" and it is NOT the same as the one above named "picoGraphics".  It was a much earlier driver that was a lot lower-level, where you had to interact at the framebuffer layer (see distraction section later on, for how I got distracted by this low-level stuff a few hours/days)

Now...I found some great articles and even a YouTube video or two, I'll mentioned a few here - however, I did just end up deleting a lot of open-tabs due to frustration.

This chap looked promising, he ported an existing RPi Zero game over to the PICO:

http://www.penguintutor.com/projects/pico-spacegame

But, as he states on his site (para-phrasing): if you want to do this properly, you should look into using C-code

https://github.com/penguintutor/pico-spacegame

I'll save you the time - it uses the old picographices library that you cannot get hold of anymore, so of no use :-(

Then I found loads of references to this video (in various places):

..and I confess I found this whilst doing the "distracted research" (see later on), hence it is not directly related to the pico display.
Again, he was using a low-level graphics driver and was doing bytearray buffer images / sprites - and the new picoGraphics library just doesn't offer that.

I even got so distracted I was searching for ANY reference to the word PICO!



...The above then gave me a pause for thought.

Let me roll back to what I was doing & why I was doing it.

If I were a kid (cough cough yes, I know it is sometime questionable whether I actually ever grew up - but that's a debate for another day and to ask the question, "why" and what does "grew up" actually really mean?) and for xmas I just received a PICO and a PICO Display (yes, I gifted one to myself, naturally) then I would be sitting there on xmas day thinking... I wonder what I could do with this.... apart from watching a bunch of balls, bouncing around the screen.


I'd want to WRITE a GAME and PLAY a GAME that I WROTE, on it.

Solutions!

Now, I'll give full kudos credit to this chap, he actually did migrate / upgrade his code to use the new library, as he explains here: http://www.penguintutor.com/projects/pico-tankgame

https://github.com/penguintutor/tankgame

However, before I found that I went around a few more houses, blocks, council-estates (ah, the xmas memories) and I thought to myself.  I'll port the SPACE INVADERS game from the YouTube video above to use the PICO DISPLAY.

Yeah, that's what I'll do... it won't take me very long.  I'm a grown up.  I've been coding for lots of years... it'll be a breeze...

Well, the good news is that I DID DO IT.  I am sharing the content for it, in as many places as I can think / find to place it - in the small hope that it actually helps someone / somewhere in the future.

What is hard to see is the usage of colours on the screen!  It is really vibrant Magenta / Yellow / Cyan / White - but for some reason the camera phone cannot capture them properly and the video just lloks mono-chrome!



Here is the "workings" page:

As you can see I have a vision to add some extra "1980s" gradient lines in the background to give it that extra "pop" - we'll see.


This has also brought to light that I might embark on extending that "new" picoGraphics library myself, in my own time - I know I want to do more things with it and they are not available, and I'm not the sort of person to totally rely on "other people doing all the work", I'm happy to get stuck in.

However, as the wise Penguin chap said earlier, I may just end up dropping down in the C-code layer and then I can framebuffer to my hearts content and do all sorts of wonderful stuff - I suppose the question becomes, "why am I doing this again?".

If it were to seriously write a C-game of Space Invaders that has all the bells & whistles on it, then sure, I'd fire up Arduino IDE and get cracking...however this was meant to be an introduction experience like that old Atari 800 XL... it was meant to be a start for a youngster, today, getting to "computers" and I don't mean just being a "user" or knowing how to pay apps on a phone or a whizz around Excel or knowing how to setup your WiFi password or sort out your printer - but to get a youngster interested in the engineering side of things, what time / effort / planning / thought and hard-work goes into making something.

So, here you go - I made a "pico-vaders" game that kind of works okay - of course there is an improvements list and the collision-detection isn't 100% perfect, but I'm hoping that someone else will take it further and resolve that for me... and then extend and make their own version, or even extend it into something totally different.  we'll see.


It's a shame you cannot see the vibrant colours - but hey-ho, run the code yourself and see!  You'll also see that I added in the ButtonA press to change the missile speed - just to see how it would work:


Get the code HERE: https://github.com/YnotZer0/invaders/blob/main/main.py



I got distracted

okay, so yes, I got distracted.  I have quite a few PICO microprocessor boards - well, why wouldn't you when they are between £4-£6 each, cheaper without the WiFi and you don't always need WiFi believe it or not!

I purchased one of these LCD screens:

https://www.waveshare.com/wiki/Pico-ResTouch-LCD-2.8


They seemed to forget the Demo code/apps, or basically anything really.  I had to search and find the link above.  In essence it is an ST7789 LCD screen, which is quite common.  I originally thought, I know I'll get that working with a PICO and use that as an output.... hmmmm... nope.  The picoGraphics wasn't playing ball atll - now, that might have been a "me issue", as this was at the start of this journey and I have LEARNT a LOT about LCD / TFT / VGA graphics drivers and code since then!

I stumbled over Peter Hinch and his wonderful libraries:

https://github.com/peterhinch/micropython-nano-gui

https://github.com/peterhinch/micropython-micro-gui

You'll note there is a slight difference in the repo names, nano and micro.  The micro one allows interaction via buttons.

I openly confess that I got very distracted with this screen, this library and what was available - before I decided that what I should do is just go back to using the OOTB PICO DISPLAY and see what I can do with that.

This however was a nice distraction and something I will come back to at a later point in time.



I got distracted again

Yes, of course it happened.  I went back to the PICO DISPLAY.  I did a bit.  I got frustrated / annoyed and so I went off on a kind of related tangent and did something else, for a bit.  Apparently, that's "what I do".  Now, this one was rather an interesting journey and something I will follow up with at a later stage.

that's version 1.
and that is version 2 - same thing, just different form factor.

This got me to thinking about the Atari 800 XL from earlier..... oh what a rabbit-hole I found:



Long story short... I ended up visiting here:

https://github.com/Jean-MarcHarvengt/MCUME

downloading everything, getting the PICO-SDK, configuring and setting everything up to compile and build the C/C++ code

...and generate my own .uf2 output file to put onto the PICO microprocessor board.

Yes, I modified (it wasn't playing ball, so some mods were required beyond just configuration), I compiled, I made, I overcame a LOT of errors... and I deployed.

I'm pretty sure I had to modify the references for ZX81 libraries, something about a capital Z for the .h file or was it lowercase?...  anyway, pasting some config here in case I forget later on.


platform_config.h

#define PICOMPUTER     1
//#define PICOMPUTERMAX  1
//#define PICORETROVGA   1
//#define MCUME_REV1      1
//#define MCUME_REV2      1

#ifdef PICOMPUTER
//#define SWAP_ALT_DEL   1
#define USE_VGA         1
#define ST7789         1
#define LOHRES         1
#define FLIP_SCREEN    1
#define INVX           1
#define HAS_SND        1
#endif

CMakeLists.txt

# Initialize the Pico SDK
pico_sdk_init()
add_subdirectory(FatFs_SPI build)
include_directories(config)
#include_directories(vga_t4)
include_directories(picovga_t4) #was commented out
include_directories(tft_t)
include_directories(psram)

add_executable(mcume
${PICO81_SOURCES}
${PICO800_SOURCES}
${TESTIO_SOURCES}
# ${VGA_T4_SOURCES}
${PICOVGA_T4_SOURCES}
${TFT_T_SOURCES}
)
#pico_generate_pio_header(mcume ${CMAKE_CURRENT_LIST_DIR}/vga_t4/timing.pio)
#pico_generate_pio_header(mcume ${CMAKE_CURRENT_LIST_DIR}/vga_t4/scanvideo.pio)
pico_generate_pio_header(mcume ${CMAKE_CURRENT_LIST_DIR}/picovga_t4/picovga.pio)

target_link_libraries(mcume pico_multicore
    pico_stdlib
    FatFs_SPI
#     pico_scanvideo_dpi
    hardware_adc
    hardware_pio
        hardware_pwm     
)

pico800.cpp
#ifdef USE_VGA
#include "vga_t_dma.h"
#else
#include "tft_t_dma.h"
#endif

pico81.cpp
#ifdef USE_VGA
#include "vga_t_dma.h"
#else
#include "tft_t_dma.h"
#endif

emuapi.cpp
#if (defined(ILI9341) || defined(ST7789)) && defined(USE_VGA)
// Dual display config, initialize TFT
#include "tft_t_dma.h"
static TFT_T_DMA tft;
#else
// Non Dual display config
#ifdef USE_VGA
#include "vga_t_dma.h"
#else
#include "tft_t_dma.h"
#endif
extern TFT_T_DMA tft;
#endif


I did not however succeed.  I do not get any output on the LCD screen, in fact at most I get the backlight coming on... but nothing else, nada.... So I concluded that it was either to do with:

code looking for other hardware, such as keyboard; or it is actually outputting to the VGA output - and I'm not using a VGA... so, I ordered a VGA output board for the PICO!

yes, this journey will continue.

I am very intrigued about getting an Atari 800 XL emulator running from the PICO and using it instead of the real hardware - I have a ton of ROMs and I'll be stressing the 40+yr old hardware a lot less.  Also means I can write some code and test it in the PICO rather than the real hardware... and then any deploy tot he real hardware much later on... another digression.


Okay, learn from my bit of fun

You didn't think I wasn't going to share the code with you, did you?  I could cut & paste it here, but I think I'll do the "proper thing" and slap it into my personal github repo.


https://github.com/YnotZer0/invaders/blob/main/main.py






ENJOY MAKING!



This looked like an interesting idea: https://hackaday.io/project/188642-duel-pico-computer


Squint and it could be Pacman!


UPDATE:

ooooo now that would be complicated thing to do and probably not feasible with the picoGraphics library within MicroPython...

https://www.raspberrypi.com/news/coding-space-invaders-disintegrating-shields-wireframe-9/


and then, well... PICO as a Gameboy...

https://www.youmaketech.com/raspberry-pi-pico-gameboy/



 

Comments