Autonomous driving object detection on the Raspberry Pi using OpenCV, TensorFlow Lite and deep learning

Ethan Dell is a full-time computer vision engineer who enjoys developing and experimenting with the Raspberry Pi. He has documented a great method of using the Pi (in this case, a Raspberry Pi 4) to do object detection when driving at speed. He has accomplished this by using OpenCV, so-called “deep learning” and TensorFlow Lite together with Python to take pictures from a Camera Module and identify road traffic objects while driving along. Just to keep things real, he’s attached everything to an empty tissue box, proving you don’t need a complicated case for it to go in. The results are outstanding and you can see how the detection gets better the closer the objects get to the driver.

You can read a tutorial on how to do it on GitHub here, view a deeper look at the “learning” methodology here and you can also learn about the project and see the results by watching the video below.

Look out for more from Ethan in the future over on his blog, which he’s just started up and which will grow as his experiments with the Pi expand.

Getting set-up with the Pimoroni Pico Explorer and using it to get the demo running

When products first come out, and the inevitable add-on boards appear, one of the things that you pray for are clear, concise instructions that take you through, step-by-step how to do something basic. The Raspberry Pi Pico is incredibly “new and exciting”, but I found myself struggling this afternoon trying to get an add-on board going in a basic fashion – the Pico Explorer from Pimoroni. This board, which comes in at £22.50, is programmed using MicroPython, more specifically a version of MicroPython especially written to interface with their products. It would be nice, of course, if you could just install the MP library for their products into a basic MicroPython install (in a similar way that you drop library files onto a Pico running CircuitPython. However, this will do “for now”, so I thought I’d let you know how I faired and how to do it yourself.

The picture above is a demo picture from Pimoroni – I did not manage to get anything like as complicated as that running!

Beware! Windows user ahead

Please note, I’m using Windows (shock, horror), but as this is still the number one Operating System in the world, and it’s what I’ve got at the moment (my desk space is set-up for work as a home office), I don’t think that’s a bad thing, exactly.

Instructions

Step 1: Install the MicroPython firmware

Go to this page on GitHub and download the latest version of MicroPython from Pimoroni (NOT the normal MicroPython firmware). You want the .uf2 file (which we’ll refer to as UF2) listed nearest the top. It’s an “alpha” but don’t let that put you off too much. Unplug your Pico, hold down the BOOTSEL button and plug it back in again. You will get a drive called RPI-RP2 on your computer. Drop the UF2 file onto that drive.

The Pico will reboot and then you will be told that another device is being set-up on Windows. Another drive does not appear – this isn’t CircuitPython, this is MicroPython. It works differently.

Step 2: Install Thonny

Download the latest release of the Thonny editor from their website. This lets you interact with the Pico in the right way. Thonny’s pretty good (a favourite amongst the Raspberry Pi engineers) but it would be nice if the more user-friendly Mu was an option. That will probably come in time.

Anyway, once you’ve got it installed, run it and then immediately go to the bottom-right of the window. Change the interpreter to MicroPython (Raspberry Pi Pico). This lets you use the REPL of the Pico, if you want to. This is an interactive prompt (which appears at the bottom of Thonny) where you can run code directly on the Pico. To be honest, it’s just as easy to create a file and save it to the Pico rather than mess around with the REPL interpreter.

More importantly, it lets you save MicroPython files direct to the Pico and run them interactively.

Step 3: Get the demo sketch up-and-running

Visit this page on GitHub and copy the code from there.

In the main editor area of Thonny, paste in this code. Do Ctrl-S to save and choose to save it to the Raspberry Pi Pico. Save it as main.py on the Pico (the name is important as it specifies that, once it’s uploaded, the code should run automatically).

At the moment, all it will do is display some text on the LCD.

Step 4: Make some noise

As it says on the screen, if you plug in a Male-to-Male jumper to GP0 and then the other end into ‘AUDIO’, this should make a very 8-bit-type sound.

What next?

To go further, you’ll need a pinout diagram (thanks to Pimoroni):

This tells you what is connected to what pin. I then suggest taking a look at the Raspberry Pi MicroPython tutorial which will tell you how to define inputs and outputs.

For instance, to use one of the buttons that border the LCD, you’ll want to do something like:

button = Pin(16, Pin.IN, Pin.PULL_DOWN)

This should, although I haven’t tried it, give you a button object to query to see if value() is True or False.

Apart from that, there’s a lot of things you can do with the Explorer.

  • You can use the mini breadboard to do your own electronics (such as that pictured at the top of the screen). I plugged in an LED, resistor and button and created a button-activated lamp. That’s a small thing, but it’s a good first step.
  • You can use the Breakout slots to try interfacing with the Breakout Garden set of products (but I’m not sure how well supported they’ll be yet).
  • You can use the buttons bordering the LCD, as I mentioned above, to get inputs to do things.
  • You can use the DRV8833 chip on the bottom to activate motors, the pins for which are broken out on top.
  • You can read analog inputs (these are also broken out) – be careful here as you can only use 3v3 analog sensors with the Pico (without lots of messing about with level converters!)

What did I think of the Pico Explorer?

I think it’s a great product to get you going – there’s lots of in-built functionality, the breadboard area is great as it means you can do your “Hello World” LED lighting and button inputs. However, the documentation is a bit “all over the place” and, as far as I can tell, the MicroPython functions aren’t quite fully documented yet – you have to infer them from the demo code that you cut-and-pasted in step 3. That’s fine, but some additional documentation and a “bringing it all together” needs to be done if Pimoroni expect beginners not to get lost, bewildered and dispirited by the experience. I was just about okay, but a beginner may not be.

Use Adafruit’s CircuitPython on the Raspberry Pi Pico

At the start of the Raspberry Pi Pico launch, it was only possible to program it in either C/C++ or MicroPython. A few languages are beginning to make an appearance now, including the quite exciting prospect of Rust running on the board. Today, I’m highlighting Adafruit’s CircuitPython. It is similar, though not identical, to MicroPython but seems to have many more libraries available. The folks over at Adafruit have taken the examples from the Getting Started with MicroPython book and adapted them to CircuitPython. They have then put together a great, comprehensive Getting Started with Raspberry Pi Pico and CircuitPython guide, including how to install it and how to use the available resources on the Pico.

This is a great move by Adafruit – i.e. getting the language working on the Pico – and in some ways it’s much easier to use CircuitPython than MicroPython due to the way you upload your code. It’s certainly easier than the somewhat “uneven” experience of working with C/C++ in various environments, most notably Windows.

Of course, you might prefer to stick with MicroPython, it being Raspberry Pi’s preferred language, but CircuitPython gives you a slightly bigger world in which to work. There are still advantages to MicroPython, as Adafruit themselves point out:

  1. Advanced APIs such as interrupts and threading.
  2. Complete PIO API (CircuitPython’s support is incomplete)
  3. Using existing MicroPython code

Romilly Cocking has pointed out, in the comments, the following:

CircuitPython is a fork of MicroPython. Damien George (creator of MicroPython) is comfortable with it. He regards the two versions like Linux Distros: the same core code packaged differently for different audiences.

Another great advantage of CircuitPython is that you can use Adafruit Blinka which lets you run a huge range of CircuitPython libraries on the Raspberry Pi or Jetson Nano.

It’s entirely up to you – give it a go, see what you can make!

Find out how to get started with your Raspberry Pi Pico with Core Electronics video tutorials

Hi everyone. If, like me, you’re just starting out on your Raspberry Pi Pico journey, you’ll likely be looking for some resources to help you. This is a microcontroller, not a microcomputer, so you have to do things a bit differently.

You’ve probably found the Getting Started guide over on raspberrypi.org which has all your documentation and get-up-and-going stuff. You might also (if you’ve managed to navigate the website, which is by no means easy) have found the Get Started with MicroPython on the Raspberry Pi Pico book (which is free to download). However, sometimes you just need someone to take you through things in a friendly, clear way, almost one-to-one.

I came across some of the best tutorial videos I’ve ever seen on YouTube from an Australian company called Core Electronics. They’re actually an authorised, official reseller of the Raspberry Pi, but this was the first time I’ve met them (virtually).

Fortunately, Michael, who is the one presenting the videos, is using Windows – this is what I use, so it’s good to have that common experience of the little pitfalls you might come across. He is also, thankfully, an excellent presenter and speaker and lacks the more… annoying “YouTube-ness” that you sometimes find! 🙂

The first video I found is an introduction to programming the Pico over a USB serial link using the MicroPython “REPL” interpreter. This reads MicroPython instructions directly over the cable and runs them immediately. (This isn’t how you should work, of course, but it does replicate the Python command-line interpreter that people are used to as their first steps on the Raspberry Pi).

The second video is a much better workflow for programming and covers how to get set-up and started using the Thonny Python editor.

Finally, because everyone loves blinkies, they’ve also done a video on connecting WS2812B LEDs to the Pico and getting them all lighting up.

Going further into their YouTube Channel, it appears they’ve been doing videos for quite some time, so I’ve subscribed in the hope that I can learn more… stuff!

Definitely worth a look if you need help, and definitely worth a look if you find the whole Pico “thing” a bit mind-boggling!

I didn’t get paid to say nice things about Core Electronics! I just came across them on YouTube!

Controlling the Euro Truck Simulator game from a physical dashboard with a Raspberry Pi and an Adafruit Clue

Spencer Organ is, as he puts it, “a big fan of both Euro Truck Simulator 2 and American Truck simulator”. He found out about an API that comes with ETS2 that allows you to tap into the game and both control the trucks and get live telemetry from them.

He has built a desktop-sized control panel with buttons and switches to control trucks in the simulator and then get the telemetry read-outs on both a 7-segment display board and an Adafruit Clue. The controller is tied together with a Raspberry Pi Zero and uses almost all of the GPIOs of both the Pi and the Clue to make it work, read button presses and display lots of indicator lights!

He’s covered the whole thing in felt so that it feels like a proper dashboard installation and there’s an even a key-switch to enable the whole thing. It’s a lovely build, complete with labels, and you can read more about it over on his blog, The Maker Cupboard. There’s even a video on there that shows it in action! Nice job, Spencer!

Create a weather station with your Raspberry Pi and an Inky wHAT

Rainer Bunger on Twitter has taken a Raspberry Pi Zero W and a Pimoroni Inky wHAT e-ink display and created a lovely weather station that displays the next 7 days of forecasts.Using various fonts for the text and the icons and programming in Python 3, the e-ink display is a great idea as it will not need to update very quickly. You can see how he did it, and download the files necessary to reproduce it yourself, on GitHub.