The Raspberry Pi

Introduction

The Raspberry Pi is a British made, low cost but powerful single-board computer (SBC) that is about the size of a credit card and was released in early 2012. The main goal of the Raspberry Pi is to introduce people, in particular children, into programming by providing a cheap but capable computer, however, the Raspberry Pi has become very popular among people of all ages in many different environments, across the world Of particular appeal is the ease of connecting your own circuits to the Raspberry Pi, something that is much more difficult to do on other modern computers.

The Raspberry Pi was influenced by the BBC microcomputer (see Microcomputers page) which had similar aims back in the 1980's. Like the BBC microcomputer, the Raspberry Pi has a number of versions such as the model A, B and B+. Interestingly, the Raspberry Pi uses an ARM 32-bit RISC processor (64-bit in later models) which was created by the company ARM Holdings, formed with Acorn computers, who created the BBC microcomputer.

Such great is the influence of the Raspberry Pi that there has been since many 'clones' offering different features at different costs, but often with some kind of Raspberry Pi compatibility. It is the Raspberry Pi community that is the most dominant of the SBC's, however, meaning that often the best software and technical support can be found for the Raspberry Pi.

Since its release in 2012, many versions of the Raspberry Pi have been made available, which you can read about on this page. There is also general information about how to use a Raspberry Pi and get the most out of it. You may want to first read about the various Raspberry Pi models and then other sections, such as software, networking, etc.

Please note that any stated prices in GBP (£) where converted from USD ($) at the time of writing the associated section.

Raspberry Pi 1

There are two main models of the original Raspberry Pi which are called model A and model B; model B was released first, on 24/2/12. Model A costs about £16 ($25) and the model B costs about £25 ($35). Both models have a micro USB socket for powering the Raspberry Pi, HDMI connector for HD A/V, RCA socket for SD video, stereo socket for audio and an SD card socket. Model A has just one USB 2.0 socket whereas model B has two USB 2.0 sockets. Model A has no ethernet socket but the model B has a 10/100 ethernet connection. Both models have an ARM11 CPU running at 700MHz and a VideoCore IV GPU capable of HD playback at 1080p. The model A has 256MB of RAM and so does the original model B but the model B revision 2 has 512MB RAM. There is now a model B+ (priced the same as Model B) which has a number of improvements on the model B including having four USB 2.0 ports but yet the system board uses less power.

To keep down the cost, the Raspberry Pi ships without a case and it is expected that the buyer already has their own peripherals, although some sellers offer SD cards, the power supply and the like. As well as cutting down on the cost by not including a case it also encourages people to make their own cases, whether using traditional methods (such as by cutting plastic) or more recent techniques (by using a 3D printer, for example). You can use a wired or wireless USB keyboard and mouse with the Raspberry Pi but with the model A you will need to use a USB hub to be able to use both a keyboard and mouse. Even with the model B it's likely you'll need to use a hub if you plan to also connect a flash drive, for example; powered USB hubs are best used with the Raspberry Pi.

A big problem with many modern computers is that it can be difficult for hobbyists to interface their own circuits (switches, lights and so on) to a computer. The parallel port was a popular choice but many current computers don't have one and those that do are blocked by the operating system (although there are workarounds). So it's a blessing that the Raspberry Pi has it's own on-board header providing a number of I/O connections that can be programmed, known as GPIO (General Purpose Input/Output). These consist of both general purpose and, specialist type (I2C, for example) connections.

Below you can see a photo of my Raspberry Pi (original model B) inside a case I bought separately. The two halves of the case clip together and there are slots for accessing the on-board ports, such as the GPIO's. You would have to be careful with this case that screws and other little items don't drop through the holes.

Wisely, the power supply connection for the Raspberry Pi is a micro USB connector, so there will be no worry of getting the connector in the wrong way and many people have a spare USB power supply form a previous phone. The model B Raspberry Pi needs at least 700mA up to a maximum of about 1A depending on what devices are connected to the Raspberry Pi. Fortunately, there are already a good number of USB power supplies for sale but be sure to shop around for a good deal, just not too cheap. It's better to pay out a bit more for a reliable power supply that will keep you safe and protect the Raspberry Pi from harm.

As well as powering the Raspberry Pi from a mains USB plug you could also use a rechargeable battery bank which, along with a Wi-fi adapter, allows for a truly portable Raspberry Pi with Internet access. I bought a 6000mAh portable power bank (code N48LK) from Maplin for £30 and it had no problem powering the Raspberry Pi which had a Wi-fi dongle and Keyboard/mouse adapter connected to a USB port each. The power bank charges using a USB plug and has LED's that show how much power is left.

The model B Raspberry Pi has an ethernet connector allowing for networking to a router or computer using a patch cable or cross-over cable. Note that if you do network the Raspberry Pi with a Windows computer it will not show up under the Network view (or certainly it didn't for me) but you can ping the Raspberry Pi using it's IP address or test by opening a browser using the Raspberry Pi. The Raspberry Pi can also use a USB wireless dongle although that may require a driver.

For connecting the Raspberry Pi to a monitor or TV, there are provided both a composite video connector and a HDMI connector. Composite is a lot lower quality and lower resolution than HDMI ( composite is Standard Definition and HDMI is High Definition) and only carries the video signal whereas HDMI contains both video and audio signals. Composite is not really suitable for computers that are able to output HD visuals such as the Raspberry Pi and reading text using composite can be difficult. A VGA connector would have made sense since there are many monitors and TV's that feature such a connector and VGA can carry HD signals. However, a VGA connector would have taken up considerable space on the Raspberry Pi and it seems would have entailed other complications. There are HDMI to VGA converters but some can damage the Raspberry Pi so it would be best to stay away from them.

Model B+

While there has been a number of revisions to the Model B these have been quite minor unlike the Model B+ which has addressed and fixed a 

number of major issues but costs the same as the Model B. Below you will find a photo of the B+:

The B+ has 4 USB 2.0 ports instead of 2, more GPIO (the header is compatible with model A and B) and yet the board uses less power by using switching regulators instead of linear ones. Another welcome change is the B+ uses a micro SD card which you push to lock in place as opposed to the full size SD card needed on the model A and B (unless an adapter is used).

There is now prevention against damage from powered USB hub backfeeding (the power connected to the USB hub goes into the Raspberry Pi and causes it to shut down). In addition the audio sounds better and the composite video has been moved to a 4-pole connector that also carries the sound. Many of the connectors have been moved and no longer stick out as much as on the older models and there are four mounting holes.

On the older models, there were five LED's on model B and two on model A that indicate if there is power, SD card access, and network status (on model B only). On the B+ there are now only two LED's on the board for power and SD card access with two network status LED's on the ethernet connector (as you will find on many laptop and desktop computers).

One complaint is that the RAM amount wasn't increased as the B+ has 512MB whereas people would have liked at least 1GB. It could be that adding more RAM may have upped the cost but it seems to be a limitation of the main chip. We most likely will see an upgrade of the RAM in an entirely new version of the Raspberry Pi but for now we have models A, B and B+ to play with.

Raspberry Pi 2

Released in February 2015, the Raspberry Pi 2 model B uses a quad core processor (the first Raspberry Pi is single core) and has 1GB of RAM (double or quadruple that of the older Raspberry Pi models), so the overall performance is much better, as much as 6x. The Raspberry Pi 2 model B looks almost the same as a Raspberry Pi 1 model B+ and should be thought of as a B+ because of carrying forward the improvements of the B+. Note that because the Raspberry Pi 2 uses a different processor you must use a Raspberry Pi O/S that was released in January 2015 or later otherwise the Pi won't boot.

Raspberry Pi 3

The Raspberry Pi 3, made available from February 2016, may look very similar to the Raspberry Pi 2 model B but has a key upgrade that Raspberry Pi fans have longed for: built-in Wi-fi and Bluetooth. The Raspberry Pi 3 not only has built-in Wi-fi but Bluetooth also, eliminating the need for Wi-fi and Bluetooth adapters which frees up the USB ports. With the same form factor as the second Rasp Pi, the Rasp Pi 3 also has the same connectors but it has been claimed that the Rasp Pi 3 is as much as 50% faster than the Rasp Pi 2. The Rasp Pi 3 features a Broadcom BCM2837 SoC containing a 64bit ARMv8 quad core Cortex A53 processor running at 1.2GHz and a dual core VideoCore IV GPU at 400 MHz. Compare that to the Rasp Pi 2 which uses a Broadcom BCM2836 SoC containing a 900 MHz 32-bit quad-core ARM Cortex A7 and a Broadcom VideoCore IV running at 250 MHz. Even though the Rasp Pi 3 CPU is 64-bit currently the available operating systems are only 32-bit, at least for now. Switching the code to 64-bit could actually make things worse and with only 1GB of on-board memory we may not see 64-bit software for a while. 

You can buy a Rasp Pi 3 for about £30 ($40) and there are a number of kits that include everything you need to get started.

The Raspberry Pi 3 model B+ was released in March 2018 and improves on model B by using the BCM2837B0 SoC that has a slightly faster CPU (Cortex-A53 running at 1.4GHz), gigabit Ethernet (connected over USB on-board which limits the maximum speed to 300Mbps), Power-over-Ethernet (by use of a specialist HAT that takes advantage of the new 4 pin PoE connector), and better performance of both Wi-fi (which is now dual-band 2.4/5GHz) and Bluetooth.

Pimoroni Raspberry Pi 3B+ starter kit


I picked up for cheap the Pimoroni Raspberry Pi 3B+ starter kit, model PIM337 (barcode 0606034876996), which is a good introduction to using the Raspbery Pi and a nice starting point for programming the computer in Python involving the use of lights connected to the GPIO pins.


The official product page was:


pimoroni.com/starterkit


But that (at the time of writing this article) has now been replaced with a Rasp Pi 4 kit instead and the original page is no longer available. However a similar page can be found at:


https://www.mouser.co.uk/ProductDetail/Pimoroni/PIM337?qs=lc2O%252BfHJPVb%2F9J40WUgfWQ%3D%3D


Where it retails at £72 ($96 USD).


This is what the boxed kit looks like:

The kit is designed for those age 8+ and contains almost everything you need to get started with the Pi:

Rasp Pi 3B+

Keyboard & mouse

Pibow case

Raspbian OS

HDMI cable

Rainbow light

Heat sink

Power supply

User guide

Stickers


The projects that are included in the user guide are:

Getting started with Raspbian

Minecraft

Python

Rainbow light coding


The mouse (see below, with keyboard) is just a generic wired black mouse, with 3 buttons and a scroll wheel, no manufacturer indicated anywhere on the device. Likewise, the keyboard is a generic wired black keyboard with no numpad but unlike the mouse there is a label on the underside, which says ‘Mini keyboard’. Interestingly, there is a faint outline for a battery compartment cover cut out, so perhaps the plastic enclosure is used for multiple keyboard models. The keyboard has two lights, the first for num lock and the other for caps lock, and oddly a Windows key considering likely you’ll be running Linux on the Pi, but it was probably cheaper to include a 'standard' Windows keyboard. I found the keyboard on the Pimoroni website, which they sell for £8.10 ($10.81 USD), which seems expensive for what it appears to be a cheap attempt at a keyboard. I found a similar mouse on the Pimoroni site that sells for £7.20 ($9.61 USD) but I didn't even bother to use the one that came with the kit, swapping it instead with the official Pi mouse that I already had.

The power supply comes in a box with code 909-8126, from RS components Ltd., as written on the power supply and is an official Pi  micro USB supply, rated +5.1VDC 2.5A and includes a number of different heads with the UK one already fitted.


In the photo that follows you can see the power supply, HDMI cable and packet containing heat sink, rainbow light and micro SD card adapter with micro SD card already fitted. The SD card is SanDisk EDGE A1 16GB. The rainbow light consists of 8 RGB LEDs that connect to the Pi’s GPIO pins.

The getting started guide has 24 pages and starts by walking you through setting up the Pi, putting together the case, attaching the heat sink, installing the rainbow light, and connecting everything else. Then it moves on to powering on the Pi and going over a number of features of Raspbian, playing Minecraft, and using the rainbow light, which is actually called Blinkt!


Here is the getting started guide and sticker sheet:

The getting started guide is very easy to follow and features a mixture of text and pictures/screenshots.


You get a boxed Rasp Pi 3 Model B+ from RS, model 137-3331 which (of course) includes the Pi, quick start guide and safety instruction manual. The Pibow Coupé red case is boxed, model PIM341 and comes in a number of pieces, which you must assemble (as outlined in the getting started guide and on the box the case came in).


Here is the Pi and case:

The pieces of the case are numbered and the top piece has the ports and GPIO pinout labelled, a very handy feature. I found that layer 3 is slightly different in the diagram in the getting started guide to the what it actually is but in a very minor way. There are 4 plastic bolts and nuts that hold the pieces together and the nuts can be tightened using the supplied spanner (if you can even call it that). One extra nut was supplied in case 1 is lost, which is just as well as the nuts are quite fiddly.


The Blinkt! rainbow light must be connected to the GPIO the correct way round but the guide makes it clear which way, with the ‘B’ of ‘BLINKT!’ sitting top-left of the Rasp Pi and here it is fitted to the Pi:

Lastly, the keyboard, mouse, power, HDMI, SD card, and optionally ethernet can be connected to the Pi and then the power supply plugged in so you can start using the computer. The O/S has already been written to the SD card and is Raspbian Stretch but upon power on the Pi it will need to finish setting up and once you get into the desktop you will be asked for a few settings (country, time zone, Wi-Fi, set system password) and given the option to update the Pi. Unfortunately, that failed for me, perhaps because it was trying to do the update over Wi-Fi even though there was an Internet connection through ethernet. But we can do it manually from the terminal:


sudo apt update

sudo apt full-upgrade


This can take a while (35 minutes for me) but is best to do before doing anything else in order to make sure everything runs smoothly.


The getting started guide says to set your keyboard layout to United States/English (US) under preferences and this is likely because the supplied keyboard is a US keyboard: the ‘#’ is where the ‘£’ sign should be on the ‘3’ key. However, I left the keyboard setting to the default of UK, and that works fine, since I touch type, although some of the characters are mapped to different keys to what I'm used to. For example, on a standard UK keyboard the pipe (vertical bar) symbol can be generated by pressing shift and '\' but with the kit's included keyboard to produce the pipe symbol you use right alt and the '`' (the key to the left of '1'); this means the right alt key is likely actually alt gr. If you want to stick with UK layout there are shortcuts to generate the 'missing' characters as well as utilities to produce any character you need or you can just copy and paste from a web site (i.e. Google 'pipe').


I had a look under preferences->Mouse and Keyboard Settings->Keyboard->Keyboard Layout and saw that the keyboard is identified as ‘Generic 105-key (Intl) PC’, just as a matter of interest.


Now that I was in Raspbian I ran through the Blinkt! examples in the getting started guide, which includes installing example code and basic coding to use the rainbow lights. There is also an online tutorial at:


https://learn.pimoroni.com/tutorial/sandyi/getting-started-with-blinkt


Which goes into more detail of how to use Blinkt! than in the getting started guide. You can also check out the Pimoroni's video in which they find different ways to use Blinkt!:

There is lots of example code under /home/pi/Pimoroni/blinkt/examples and extra_examples provided you have installed the software as outlined in the getting started guide.


Unfortunately the Pi edition of Minecraft hasn't been updated since 2015 and unlikely to be updated hence why it's in alpha, however, there is still plenty of fun to have with it and we can take advantage of the included programming interface to Minecraft via Python:


https://projects.raspberrypi.org/en/projects/getting-started-with-minecraft-pi


For reference here is the link to the Minecraft Pi Edition API:

https://pimylifeup.com/minecraft-pi-edition-api-reference/


While the kit is great for anyone getting into using a Raspberry Pi and has a good introduction of a practical form of interfacing - the Blinkt! rainbow light - the question remains whether the kit is worth the money. I found prices for each of the included items (but not the getting started guide and stickers), getting as close to the actual items as possible and from the Pimoroni site where possible, and calculated the total cost to be £88.26. So, assuming the original retail price was indeed £72 the kit is good value for money especially as the only thing you need to supply yourself is a TV/monitor and Internet connection.

Raspberry Pi 4

Introduction

The Raspberry Pi 4 was originally scheduled for 2020 but was released earlier, on 24/6/19, in model B form. It addresses many issues that customers have had with previous versions of the single board computer by adding different RAM options (choice of either 1GB - no longer available from official retailers since the 8GB version was released, 2GB or 4GB), full-throughput Gigabit Ethernet (an on-board USB adapter is no longer used), and 2 USB 3 ports (in addition to 2 USB 2 ports). The price for the 1GB model is $35, 2GB $45 and 3GB $55, and in the UK the current pricing is £34 for 1GB, £44 for 2GB, and £54 for 4GB.

A typo in the Raspberry Pi 4 manual back in 2019 mentioned an 8GB version but due to a suitable memory chip not being available in 2019 the 8GB model was not for sale at that time. However, on 28/5/20 the 8GB Rasp Pi 4 was released, selling for $75 (£74), which has in addition to the memory increase, a few minor component changes have been made to the board, but all existing Rasp Pi 4 cases will fit the 8GB version. The 8GB model will only be of interest to those running a lot of applications or programs that deal with a lot of data.

Instead of powering the Rasp Pi using USB micro as with previous generations, the new Pi requires power to be fed through a USB-C connector so that more power can be delivered to the computer. It is recommended that a 15W USB-C power supply is used, however, you could use a USB micro-B to USB-C adapter to make use of a power supply lacking a USB-C connection, provided it's rated adequately. If you see a lightning bolt symbol in the top left hand corner when you boot the Rasp Pi then that may be an indication that you need to use a more powerful power supply.

At the heart of the Rasp Pi 4 is a 64-bit ARM Cortex-A72 CPU (quad core) running at 1.5GHz, which should give around 3 times better performance than the Raspberry Pi 3. Wireless options are dual-band 802.11ac Wi-fi and Bluetooth 5.0 but quite surprising, the single full-size HDMI port has been replaced with 2 micro HDMI ports, allowing for a dual monitor setup with up to 4K @ 30Hz support. If using a single display connected to HDMI0 (the port next to the USB-C power connector) the Pi can manage up to 4K @ 60Hz (which, be aware, will make the Pi run hotter). Getting the Pi to output at 4Kp60, however, can be an issue, which you can read about under the following section '4K 60Hz woes'.

Everything else about the Raspberry Pi 4 is basically the same and there should be no backward compatibility issues with software or hardware except new cases have been released for the Rasp Pi 4 due to the new port connectors. On the downside the Rasp Pi 4 still uses an SD card for its main storage even though there has been demand for a Rasp Pi with on board flash memory for the O/S. A version of Debian 10 Buster has been designed for the Rasp Pi 4 and is recommended to be used.

I bought the 4GB model of the Rasp Pi 4 and tested it by using the latest Raspbian release (10/7/19) 'Buster' with recommended software included which required an 8GB micro SD card.  Note that since the release of the 8GB Rasp Pi, 'Raspbian' is now named 'Raspberry Pi OS' but details in this section were written when it was still called Raspbian.

The OS includes Chromium, Scratch, Sonic Pi, Thonny Python (beginner-friendly Python IDE), SmartSim (digital logic circuit design and simulation), VLC media player and Minecraft Pi. As with any new installation of Raspbian be sure to update it by issuing the following commands from the terminal:

sudo apt-get update

sudo apt-get dist-upgrade

Then reboot the Pi so that the changes have an effect.

I found that the Pi happily ran on both a Google pixel 5V/3A power supply as well as a 5V/2A Samsung S8 charger although 3A is the minimum that is supposed to be used. For display output I connected my TV to the Rasp's HDMI 0 connector and upon first boot the file system was automatically expanded and then into the desktop a 'Welcome to Raspberry Pi' window invites the changing of some basics settings such as time zone and password. Rebooting the Pi from the desktop it took 26 seconds to return to the desktop. After shutting down the computer, removing and plugging the power supply back in 20 seconds passed to get to the desktop.

As with past versions of Raspbian connecting a Bluetooth device is as easy as clicking the appropriate icon on the taskbar and Wi-fi connection is just as straightforward although I had to first select my country before I could connect to a Wi-fi network. Since I wanted to easily monitor the CPU temperature I added the temperature display: to do this right-click the taskbar and select Add/Remove Panel Items. Click on the Panel Applets section if not already selected and click the Add button. Choose the CPU temperature monitor from the list and click Add; the CPU temperature will appear in the taskbar. 

The Pi is very responsive and playing Minecraft Pi is a smooth experience and YouTube videos (using  Chromium) play well even in HD at 60 fps but at times when full screen the video was choppy. High CPU temperature has been a big concern for the new Pi and from my findings my Pi was reporting (without a case, heatsink or fan) 39 °C which quickly rose to 45 °C without doing much and then to 72 °C after a few minutes of playing a HD video on YouTube. There is a planned firmware update that claims to lower the CPU temperature by as much as 5 °C but it's safe to say at least a heatsink on the SoC should be used with a fan also if using the Pi for intensive tasks. Please see the 'Heat concerns' section for more information.

From within Raspbian you can use the Screen Configuration option to set the resolution, refresh rate and orientation of each connected screen and if you have 2 connected screens you can drag the two screens (represented by HDMI1 and HDMI 2 boxes for HDMI0 and HDMI1 respectively) to determine how the displays mirror or extend one another. To access the Screen Configuration utility click the Raspberry icon in the task bar, then choose Preferences->Screen Configuration. To change the display properties click Configure->Screens->HDMI1 (or HDMI2) and then a property (e.g. resolution) which will bring up the available options to choose from. After making changes you must either select Configure->Apply or click the 'tick' icon for the display(s) to update. Note that in older versions of Raspbian Buster, resolution and refresh rate were bundled together but after updating they are now separate options.

You may wonder how you can identify how much RAM a Pi 4 has say if you intend to buy one second hand or you see a listing online and wanted to make sure of the RAM size. Firstly you can look at the RAM chip (the rectangular chip located next to the SoC, which is the square silver chip) and check it against these part numbers:

D9ZCL(Micron) 8GB.

D9WHV (Micron) 4GB.

D9WHZ (Micron) 2GB.

4HBMGCJ (Samsung) 1GB.

The other way to check requires you actually have the board though: from within Linux open the terminal and use either:

grep MemTotal /proc/meminfo

Or:

free -h

For me the first option reported 3999788 kB which is correct as the value is basically 4GB (64 MB is used by the GPU). The second option showed the memory to be 3.8Gi which again, is basically 4GB.

4K 60Hz woes

I have a Samsung 4K TV which will happily accept 4K @ 60Hz from my PC and Xbox One X yet so far I have not had the same success with my Raspberry Pi 4 which I cannot get to output any higher than 4K @ 30Hz. I have tried 3 different micro HDMI cables and even my AV.io 4K capture card (which I know supports 4K @ 60Hz) but still the Pi is stuck at 30Hz. It seems the issue is that the Pi is convinced that my TV/capture card do not support 4K @ 60Hz and even by editing config.txt using numerous combinations of commands to try to force 4K @ 60Hz the most I can get is 30Hz.

To enable 4K @ 60Hz you have to enable which can be done by adding the following command to config.txt:

hdmi_enable_4kp60=1

Or you can use the configuration utility by running from the terminal:

sudo raspi-config

Check this link out for the necessary steps:

https://imgur.com/a/W9fTcl2

None of these options worked for me and I will continue to look for a solution.

Heat concerns

The Raspberry Pi 4 runs a lot hotter than previous models even when idle and should the SoC get to 176 deg F (80 deg C) the system will be throttled. It is recommended that you keep the Raspberry Pi and O/S updated, which will help somewhat with thermal issues but is no substitute for using a suitable case and fan (more on that coming up).

I did a number of tests by running LibreELEC on a Raspberry Pi 4, which is excellent for video playback and was what I happened to have on the SD card I was using with the Rasp Pi. For the first test I ran the Rasp Pi without a case, heatsink or fan and monitored the temperature, which can be found under Settings->System Information->Hardware: CPU temperature. It reported the temperature as 126 deg F (52 deg C) and rising, which is pretty hot for a computer idling at a screen. I played an HD video streaming from YouTube and after 1 minute I checked the temperature and it had climbed to 131 deg F (55 deg C) and after another 1 minute of video playback the temperature had risen to 133 deg F (56 deg C).

The next test was carried out after placing a heatsink on the SoC and already I saw a promising improvement: back in LibreELEC the temperature was showing as 115 deg F (46 deg C) although it did quickly increase to 122 deg F (50 deg C) when idle. After 1 minute of playing an HD video the temperature had jumped to 129 deg F (54 deg C) and after another minute of the video the temperature showed no change until after a few minutes when it dropped to 127 deg F (53 deg C). So it's clear that with a heatsink on the SoC the Raspberry Pi 4 will run 2 degrees or so cooler.

To keep the Rasp Pi 4 a lot cooler a fan is required which needs to be used in conjunction with a case - 3D printing a case is a good idea and you should be able to find various design that accommodate different size fans, such as on thingiverse.com. The only suitable small fan I could find was a NMB 1204KL-04W-B40 rated for 12VDC @ 0.1A but fortunately will run happily on 5V. Not ideal and a DC to DC converter could be used to boost the voltage but for the test I simply fitted the fan's connector to the 5V and GND GPIO pins and glued the fan in place to the case. Note that the fan was placed label facing downward which causes it to blow cool air on to the heatsink.

Booting the Rasp Pi once more with LibreELEC it showed the CPU temperature to be 84 deg F (29 deg C), quite the drop in temperature even from when using just a heatsink. After playing a video for a minute the temperature had rose to 90 deg F (32 deg C) and it stayed at that temperature even after another minute of video playing. Thus using a fan and a heatsink on the SoC, as well as a case, is very much a requirement to keep the Rasp Pi running a a cool temperature even when working hard.

With the fan directly connected to the Rasp Pi's GPIO power pins the fan will always spin as long as the board is powered which is not ideal (fortunately the fan is very quiet). An improvement would be to add a transistor as a switch and use a GPIO pin to turn the fan on only when the SoC gets too hot and then switch it off should the SoC get cooler, or the fan could even be speed controlled using PWM via a GPIO pin. A script would need to be written that runs when the O/S loads to monitor the temperature and control the fan.

Raspberry Pi Pico

On 21st January 2021 the $4 (~£3) Raspberry Pi Pico was announced and released, a departure from the previous Rasp computers in that the Pico is based around a microcontroller designed by the Raspberry Pi Foundation, the RP2040, rather than an existing system on a chip. The Raspberry Pi Foundation could have used an existing microcontroller but by using their own design they can tailor it exactly to their needs and have control over who gets to use the chip in their own boards. While being based around a microcontroller means the Pico has a lot less processing power than the other Pi computers that came before it, on the plus side the Pico uses less power, has analogue inputs, is better suited for real-time tasks and starts up much quicker, running user code straight away. But as it lacks 'proper' USB, ethernet, video, audio and SD card interfaces you have to weigh up if another Raspberry Pi, such as the Zero, is a better choice should you need those interfaces.

Here is a link to the original announcement of the Pico:

https://www.raspberrypi.org/blog/raspberry-pi-silicon-pico-now-on-sale/

For a good introduction to the Pico and microcontrollers in general please see:

As to be expected from the Raspberry Pi Foundation, plenty of documentation and tutorials have been provided from day one with good availability of the product in the UK at least, and production of the Pico is expected to continue until at least January 2028. As with the Raspberry Pi Zero which was given away free with the MagPi magazine, the Pico was available bundled with the January issue of the HackSpace magazine, and subscribing to The MagPi Raspberry Pi magazine will get you a Pico.

The RP2040 chip runs at 133MHz and features a Dual-core Arm Cortex-M0+ processor, 264KB on-chip SRAM as six independent banks of RAM, DMA controller, support for up to 16MB of off-chip Flash memory (via QSPI bus), and interpolator and integer divider peripherals. As the Cortex-M0+ lacks a floating-point unit the RP2040 features floating-point libraries on-chip in its ROM.

Because of the powerful processor and the large amount of RAM (for a microcontroller based board) one type application especially suited for Pico is machine learning.

If you are wondering where the name 'RP2040' comes from then wonder no longer:

RP=Raspberry Pi.

2=number of cores.

0=type of core (M0+).

4=floor(log2(ram / 16k)).

0=floor(log2(non-volatile / 16k))  or 0 if no onboard non-volatile storage.

Since the Raspberry Pi Foundation have gone to the trouble of thinking up their own naming scheme it's safe to say that there will be more custom Rasp chips on their way soon.

The Pico is essential the breakout board for the RP2040 (see the RP2040 Board Variations section for other boards) and measures 21 mm × 51 mm x 1 mm, making it much smaller than a Raspberry Pi Zero. It has 2MB of on-board flash memory which can be upgraded to 16MB but the 2MB chip must be desoldered and replaced with a 16MB chip soldered in its place but perhaps future versions of the Pico will include more flash memory as standard.

In total, 26 GPIO of the 30 GPIO provided by the RP2040 are routed to the Pico board, three of which are analogue inputs; these I/O pins support 3.3V only with no tolerance for signals above 3.3V. As with Arduino type boards that typically have an on-board LED connected to D13, which is useful for testing or indicating status, the Pico has a 'user LED' on the PCB connected to GP25 (WL_GPIO0 on the Pico W). There is no power LED.

The I/O and power pins are provided via 40 2.5mm pitch pads, arranged either side of the Pico with 20 connections one side and the other 20 on the other side of the board and the purpose of each connection is labelled on the underside of the board. Pin headers or wires can be soldered to the connections or the Pico can be soldered directly to  a carrier board thanks to its castellations. The Pico H, released 30/6/22, comes with pre-populated headers and costs $5 (~£4).

The Pico has 2 × UART, 2 × SPI controllers, 2 × I2C controllers, 16 × PWM channels, 1x Timer with 4x alarms, RTC (Real Time Counter), and 2 × Programmable IO (PIO) blocks, with 8 state machines total for custom peripheral support (emulate SD Card, VGA, etc.). Also featured is an accurate on-chip clock as well as low-power sleep and dormant modes, making it suitable for battery operation. Networking in the form of Ethernet and Wi-Fi is not present on the standard Pico but is on the Pico W - please see the Pico W section for more information. The Raspberry Pi Zero W, which costs only slightly more than the Pico, does have Wi-Fi and Bluetooth on-board.

For a complete overview of the available I/O and the layout of the pins please see:

https://datasheets.raspberrypi.org/pico/Pico-R3-A4-Pinout.pdf

On board the Pico is a USB 1.1 controller with host and device support and a micro USB socket for powering the Pico with a voltage range of 1.8–5.5V DC and because of the Pico's low power consumption the board is especially suitable to be powered off batteries. The micro USB socket is also for data transfer by holding the Pico's BOOTSEL button while plugging the board into a PC and the Pico will show up as mass storage device to which you can drag and drop a UF2 file. Programs for the Pico can be written in MicroPython (Python 3 for microcontrollers), CircuitPython, C/C++ and assembly language. Generally, most people will be comfortable with using MicroPython or C/C++, assembly language is a lot more difficult but useful for very tight timing.

Opening up the Pico drive will present you with a getting started guide (index.htm) which takes you to:

https://www.raspberrypi.org/documentation/pico/getting-started/

Other connections on the Pico are three debug connections toward the bottom of the board, SWCLK, GND and SWDIO (see image linked above for their locations), which form the ARM Serial Wire Debug (SWD) port, which can be used to program the Pico and to interactively debug code. On the backside of the Pico are six test pads, TP1 to TP6, which are as follows:

TP1 Ground (close coupled ground for differential USB signals).

TP2 USB DM.

TP3 USB DP.

TP4 GPIO23/SMPS PS pin (do not use).

TP5 GPIO25/LED (not recommended to be used since it's tied to the LED which limits its use for anything else).

TP6 BOOTSEL (use instead of the BOOTSEL button by shorting TP6 to GND at power-up).

TP1 to TP3 effectively allows access to the Pico's USB functionality without using the micro USB socket.

Here is a video showing how to run MicroPython on the Pico with example code:

There is also an accompanying site in case you'd rather follow that instead:

https://core-electronics.com.au/tutorials/how-to-setup-a-raspberry-pi-pico-and-code-with-thonny.html

We can see that it's fairly straightforward to get MicroPython running on the Pico but using C/C++ is a lot harder currently as the following video shows (which also covers MicroPython):

For much more information about the Pico, including first steps and tutorials, please see:

https://www.raspberrypi.org/documentation/pico/getting-started/

There is also an FAQ at:

https://forums.raspberrypi.com/viewtopic.php?f=144&t=299523

You may be interested to know that the BBC Micro has been emulated on the Pico:

The Pico is capable of generating a VGA signal and the following video shows a very impressive selection of demos powered by a Pico, producing both audio and video:

Another example of driving video using the Pico, but one that is only possible by overclocking the RP2040 and with a custom board, is driving a HDMI display, which you can read about at:

https://github.com/Wren6991/picodvi

Doom has been ported to the Pico, which is quite a feat considering Doom's requirements compared to what the Pico offers:

RP2040 Board Variations

Here is a list of just some of the other boards that make use of the RP2040 chip:

Adafruit Feather RP2040

https://adafruit.com/feather2040

Adafruit ItsyBitsy RP2040

https://adafruit.com/itsybitsy2040

Arduino Nano RP2040 Connect

https://blog.arduino.cc/2021/01/20/welcome-raspberry-pi-to-the-world-of-microcontrollers/

Pimoroni PicoSystem

https://pimoroni.com/picosystem

Raspberry Pi Pico W

The Pico W was released on 30/6/22, costs $6 (~£5) and improves on the original Pico by adding 2.4 GHz 802.11n Wi-Fi 4 (WPA3) wireless networking, provided by the Infineon CYW43439 wireless chip. Although Bluetooth wasn't initially supported when the Pico was first released, it became available on 14/06/23 when Bluetooth support was added in the new MicroPython builds and C SDKs, unlocking the Pico's Bluetooth 5.2 (Bluetooth Classic and Bluetooth Low Energy) functionality. The Pico has an on-board, single antenna shared between Wi-Fi and Bluetooth, and the wireless interface is connected via SPI to the RP2040 microcontroller. The Pico WH, a Pico W with pre-populated headers, was later released, for $7 (~£6).

Adding wireless connectively makes the Pico an even more versatile device and truly an IoT board for very little cost. Here is the link to the official announcement of the Pico W:

https://www.raspberrypi.com/news/raspberry-pi-pico-w-your-6-iot-platform/

Official announcement video:

Here is a Pico W overview video:

Whereas on the original Pico the on-board LED was connected to GPIO Pin 25, on the Pico W it's connected to WL_GPIO0, a GPIO pin on the wireless chip. This was likely done not only to free the on-board LED from the other, main GPIO but also for people needing a debug/test LED for wireless projects. However, you can simply use the LED symbol as a shorthand to access the LED, as seen in the simple MicroPython example which blinks the on-board LED:

from machine import Pin

from time import sleep

led=Pin("LED", Pin.OUT)

while True:

    led.toggle()

    sleep(0.5)

Here is a video showing a basic example of using the Pico W's wireless features to control the onboard LED from a webpage hosted by the Pico:

Be sure also to check out the 'Connecting to the internet with Raspberry Pi Pico W' ebook:

https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf

As an example of using the Pico's Bluetooth here is a video that uses the microcontroller board as a remote:

Technical

The official RP2040 datasheet:

https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf

The official Raspberry Pi Pico datasheet:

https://datasheets.raspberrypi.org/pico/pico_datasheet.pdf

Note that the Pico schematic can be found on page 24.

Pico W pinout and design files:

https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#raspberry-pi-pico-w

PicoMiteVGA

Many of us remember using microcomputers, such as the Commodore 64 and the BBC Micro, which provided an introduction to computers, and programming via BASIC. Over the years there have been many tricks and hacks to squeeze out more processing power from those old computers and while very impressive, it would be super if we could have that environment on more powerful hardware without using a modern PC. Thanks to the Raspberry Pi Pico and the PicoMiteVGA project, that is a reality and at low cost, allowing the Pico to instantly (well, about 12 seconds) boot into a powerful form of BASIC. As well as behaving like an 80's computer with boosts attached, the PicoMiteVGA can also be used as the basis for a retro style video game console.

The main page for the PicoMiteVGA project can be found at:

https://geoffg.net/picomitevga.html

You may also like to check out ExplainingComputers’ video as an introduction:

The project can be put together on breadboard or some other type of prototype board; the neat thing is that if you are building yourself you can add exactly what 'bells and whistles' you desire or keep it as simple as possible as a lot of the hard work on the software side has been done for you. Alternatively, you can purchase a kit, which cost around £30, but at the time of writing this article there doesn't appear to be that many sellers. I opted to use an original (non-wireless) Pico and go down the breadboard route to give the PicoMiteVGA a try with the intention to later solder everything up and put in a 3D printed case.

Firstly, I downloaded the PicoMite firmware V5.07.07, which includes the manual, from the geoffg.net site previously linked to. It's worth checking the 'Known bugs and issues' download link also. Additionally, I downloaded the PicoMite VGA Construction Pack, which contains four designs which includes files for making your own PCBs or sending off to be built. Design 1 is for a basic PCB version, #2 has more features, #3 is for a mini PCB version, and #4 is a games machine design. I used the Design #1 schematic for breadboarding and started with transferring the firmware, using ExplainingComputers video as a guide. You can see how to transfer the firmware to the Pico at 11:05 in the video, which involves copying the firmware file (PicoMiteVGAV5.07.07.uf2 in my case) to the Pico, which appears as a drive in your O/S. Note that after transferring the firmware the Pico will be detected it as 'Pico' (instead of the usual 'RPI-RP2') and will no longer appear as a drive, which is normal behaviour (since the on-board Bootsel button allows you to copy new firmware to the Pico).

If you have been following along, you should see the Pico's on-board LED flashing, an indication that the firmware's running (the blinking is called the 'heartbeat' - see the Tips section for more information). Before even connecting a VGA monitor to the Pico we can further test that the firmware is working by accessing it's serial port and interacting with it (thus the Pico will still need to be connected to the PC). We can see this process at 11:35 in the ExplainingComputers video. We can now interact with the Pico by giving it BASIC commands without even hooking up a VGA monitor although the output won't be as fully featured as the VGA output.

Depending on when you open up the serial connection you may not see the boot copyright message and the '>' prompt but you can type a command and after you press return the prompt will appear or you can press return to make the prompt appear. Note that BASIC commands can be entered in any case, and where there is a difference in spelling between countries, such as COLOUR, the keyword can be entered in British or US spelling.

I used PuTTY to interface with the Pico but I found the backspace key didn't work, however, the solution is hinted at in the PicoMiteVGA manual: after opening PuTTY, go to Terminal->Keyboard and where it says 'The Backspace Key', click the 'Control-H' option, and then open up a serial connection to the Pico.

If you try to enter a program by preceding a command with a line number as you would on a microcomputer the command will be executed immediately, as if the line number was ignored. This is because you use the EDIT command to edit programs, giving access to the built-in editor for writing BASIC programs, which doesn't require line numbers. The arrow keys navigate the various lines and the F1 key exits the editor, saving the program to flash memory, which can then be run using RUN. Note that LIST when used outside of EDIT will list a program but you can only create or modify a program using the EDIT command.

When not in the BASIC editor the arrow key up/down cycles through previously entered commands, unless you press a key but you can press return and then arrow key up/down will allow you cycle through again.

As well as interfacing with the Pico through the USB port and running BASIC code, we can also connect a VGA capable monitor or TV (or use a VGA to HDMI converter) and get the full experience of Pico BASIC; colour and graphics. There are a number of ways we can connect a VGA screen to the Pico, which can be seen in the various designs in the Construction Pack, but the simplest approach is shown in the manual on page 6. The Pico's output can be seen on both the serial terminal software and a VGA screen simultaneously with no apparent delay but of course the output from the serial port does not show graphics.

Because the Pico's I/O operates on 3.3V we must use level converters when interfacing with 5V devices, such as a PS/2 keyboard, which can be done either with individual FETs or level converter modules, as seen in the user manual and the Construction Pack designs. However, as pointed out in the user manual, you may be able to avoid using a level converter by running the keyboard off 3.3V and indeed, I found that both a Compaq PC keyboard and a Sega Pico keyboard (quite appropriate considering the name) I used happily ran off the lower voltage. When typing on an attached PS/2 keyboard the characters that you enter appear both on an attached VGA screen and in the serial terminal software in 'real time'.

As for sound, as explained in the manual, page 32, a low pass filter circuit must be used to interface an amplifier to the Pico. The example circuit in the manual uses resistors, capacitors and inductors but as I didn't have the required inductors I looked around online for an alternate filter circuit and found one as part of PiPicoMite01, which is built on top of the PicoMiteVGA reference design. The filter uses just resistors and capacitors, and can be found as part of the PiPicoMite01 schematic:

http://land-boards.com/PiPicoMite01/PiPicoMite01_Rev1_Schematic.pdf

The ciruit won't produce the best results but it was simple and without inductors so that's why I went with it. Once you have the filter connected to the Pico and an amplifier connected to the filter you need to tell the Pico what GPIO pins to use, e.g.:

OPTION AUDIO GP0, GP1

Is the example given in the manual, but whatever option you choose will be saved to flash memory. Audio files or basic sounds can then be played, see the user manual from page 32 for the various commands.

Depending on what additional devices you connect to the Pico you will likely have some spare I/O left over that can be used for future expansion or general experimentation. In my case, I wired up an expansion port, consisting of a 10 x 2 IDC connector, carrying GND and the spare GPIO not used by VGA, keyboard and audio. Let's go over how we can use the spare GPIO but please see the manual for further details.

To set a pin as a digital output use SETPIN and DOUT. For example, to set GP2 as a digital output:

SETPIN GP2, DOUT

If we had an LED with its cathode connected to GND and anode to GP2 via a 330R resistor we can light the LED by making GP2 high:

PIN(GP2)=1

And switch it off with:

PIN(GP2)=0

To set a pin as a digital input use DIN, so for GP2 we would do this:

SETPIN GP2, DIN

We can optionally enable a pull up or pull down resistor using PULLUP or PULLDOWN respectively. For example, to enable pullup on GP2 as an input:

SETPIN GP2, DIN, PULLUP

If we then did:

PRINT PIN(GP2)

We would get a '1' if GP2 was left floating or connected to 3.3V, or '0' if GP2 was connected to GND.

Tips

Blinking on-board 'heartbeat LED'

To turn the blinking off use:

SETPIN GP25, OFF

To turn back on:

SETPIN GP25, HEARTBEAT

If you want to be able to control the on-board LED for yourself as a digital output:

SETPIN GP25, DOUT

Troubleshooting and tips

MicroPython firmware installation

Thonny can be used to install the MicroPython firmware to an original (non-wireless) Pico but you can also download the firmware from:

https://micropython.org/download/rp2-pico/rp2-pico-latest.uf2

The downloaded file can then be copied to the Pico's drive when connected to a computer while holding the Bootsel button.

The firmware for the Pico W can be downloaded from:

https://micropython.org/download/rp2-pico-w/rp2-pico-w-latest.uf2

It cannot be installed from Thonny (or at least not on V3.3.13, which is what I used).

MicroPython program doesn't automatically run.

For a MicroPython program to automatically run when you apply power to the Pico it must be named main.py.

Pico not recognised

If your PC does not recognise the Pico when plugged into a PC try a different micro USB cable; some cables only provide power but the Pico needs a data cable.

The Pico and Pico W use different MicroPython versions, so trying to use Thonny to install the firmware to a Pico W will likely fail. You can download the Pico W firmware from:

https://micropython.org/download/rp2-pico-w/rp2-pico-w-latest.uf2

Pico shows up as unknown device

If you are trying to use MicroPython on a Pico but it shows up as an unknown device in device manager in Windows, this is because you need to install MicroPython on the Pico using Thonny; it will prompt you to install it when you select the interpreter as Raspberry Pi Pico and once installed the Pico will show as a Com port in device manager. You can download the Pico W firmware from:

https://micropython.org/download/rp2-pico-w/rp2-pico-w-latest.uf2

Save scripts to Pico

You can save scripts to the Pico:

In Thonny: File->Save. Select 'Raspberry Pi Pico', enter a file name and click OK. To open a script from Pico: File->Open, choose 'Raspberry Pi Pico', select the script and click OK.

Raspberry Pi Zero

The Raspberry Pi has always been about fitting a lot of power in a small space and at as low cost as possible. With the release of the Raspberry Pi Zero in November 2015 we now have an even more diminutive (65 mm x 30 mm x 5 mm which is more than half as small as the previous models) but still powerful computer, one that will set you back just £4 ($5). However, at the time of writing this article, the Raspberry Pi Zero has sold out at the official distributors and from the likes of ebay you could end up paying as much as one of the older model Raspberry Pi's. In fact, the Rasp Pi Zero was given away free in the December issue of The MagPi (priced at £5.99) which resulted in the magazine ending up on ebay for as much as £50! Fortunately, I subscribed to The MagPi and not only received the magazine and computer but also a mini HDMI adapter and USB OTG cable (read more about the Zero's ports below).

For comparison, you can see below a 10p coin beside my Rasp Pi Zero:

The Raspberry Pi Zero has about the same power as the second revision of the first Raspberry Pi as it has the same processor running at the same speed along with 512MB RAM. As with the Raspberry Pi 2 the main storage option is micro SD (middle right in photo above - the slot is not spring loaded) but there is a single micro USB (middle top) for USB devices (you could use an OTG flash drive, for example). Power is provided to the Zero using a second micro USB socket (top left) and there is a mini HDMI socket too (top right). For some, not having composite video may be a big let down but you can solder to the 'TV' connections (bottom left) on the board if you need SD output. Sound, however, is only available from the HDMI socket but it is possible to use a couple of GPIO pins (along the bottom) to generate sound. While speaking about GPIO, you are free to either solder wires or connectors as needed to the GPIO pads on the board. There is no provision for ethernet so if that is a requirement you will need to use a USB adapter or connect an ethernet chip to some GPIO pins.

There is only a single 'ACT' LED (middle left) on the board which doubles up as both a power LED and an access LED. Also of interest is the two 'RUN' connections (bottom left) which are for soldering a reset switch. There is an unpopulated J5 connector on the underside which is for JTAG and there are also a fair number of 'PP' pads which were used for testing.

Because of the Rasp Pi Zero's very small size it can fit in even smaller places than the older versions could. For example, you could put a Zero into a controller and use the controller buttons to play games running on the Zero. The Zero is also more suitable for projects that need to be carried with someone which will need to be powered by a battery. However, if you end up adding a lot to the Zero, such as a USB hub, ethernet controller, and so on then you may have to consider if it will be cheaper and take up less room by using one of the bigger Rasp Pi's.

There have been a number of updates to the Raspberry Pi Zero starting with V1.3 released in May 2016 which is basically the same as the original but has a camera connector on one end. A more bigger update is seen on the Raspberry Pi Zero W, made available in February 2017, which has built-in Wi-fi and Bluetooth

GPIO (non-Pico models)

The General Purpose Input/Output (GPIO) pins are the means to which the Raspberry Pi can communicate with your own circuits.  Depending on the particular Rasp Pi, there may be 17 GPIO pins (some aren't actually general purpose and instead carry special features, such as SPI) which each can be configured as an input or an output. This allows you to sense button presses, turn lights on or off, display data on an LCD, and much more, all under the control of your own programs running on the Raspberry Pi.

The GPIO pins are located on the P1 connector on the board and are arranged in 2x13 format as a set of male pins. Provided along with the GPIO pins are 5V (at least 300mA; depends on model and power supply used) and 3.3V (50mA max) power connections, along with GND pins. To be on the safe side I would recommend not powering your circuits off the GPIO 5V or 3.3V connections unless you connect only very low current components (such as an LED) but it may be best to avoid  even that to lower the risk of damaging the Raspberry Pi.

One thing you have to be careful with the GPIO is that they work at 3.3V logic level NOT 5V. This means that if you plan to interface the Raspberry Pi with 5V logic devices they will need to be converted to work at 3.3V logic otherwise the Raspberry Pi will be damaged.

Add-on boards have been released to interface with the Raspberry Pi to provide convenient and protected interfacing with the Raspberry Pi's GPIO. Some of these boards extend the GPIO by adding more I/O connections and others include analogue inputs and a real-time clock. If however, you wish to do the connections yourself, you will need a suitable connector. One option is to use a PC 25-pin D-type serial port to IDC connector which were commonly used to connect a serial port connector to a motherboard. These typically have only 25 wires, however, but that will probably be enough for your needs. If you need to make just a few connections to the GPIO header then you could use some leads that have a female connector one end and a male connector the other end (useful for plugging into breadboard, for example). Either way be very careful to not bend or touch the GPIO pins. It's always best to connect to the GPIO when the Raspberry Pi is off and unplugged at the mains.

You will find on this page various projects involving the use of the Raspberry Pi and its GPIO.

Alternatives

The Raspberry Pi has helped spark a revolution in programming and electronics projects and a number of other single board computers have emerged, some of which will be mentioned in this section. Please also see the 'Arduino Vs. Raspberry Pi' section as the Arduino may also be suitable for your needs.

Asus Tinker Board

Released in 2017, the Asus Tinker Board has some compatibility with the Raspberry Pi and is more powerful than the Raspberry Pi 3:

https://sites.google.com/site/jamesskingdom/Home/computers-exposed/the-asus-tinker-board 

Intel Galileo

Available in 2013, the Intel Galileo is a hybrid Arduino/Linux computer:

https://sites.google.com/site/jamesskingdom/Home/computers-exposed/the-intel-galileo 

NVIDIA Jetson Nano

A powerful computer that made its appearance in 2019 and is particularly suitable for AI, vision recognition, and such:

https://sites.google.com/site/jamesskingdom/Home/computers-exposed/nvidia-jetson-nano 

Arduino Vs. Raspberry Pi

You may have heard of the Arduino, which is a microcontroller development board that is very popular and not just with electronics and programming enthusiasts, appealing also to those not normally involved with programming or wiring electronics. Because of the Raspberry Pi's ability to more easily be interfaced with user created circuits than many other computers, the  Raspberry Pi is in some ways similar to the Arduino; they are also similar in price. In fact, if interfacing is what you are really into, the Raspberry Pi makes for a more smooth transition from the Arduino than diving head-first into programming the Raspberry Pi (the Arduino uses a programming language like C++ and the Raspberry Pi can be programmed using C++ so that is a bonus).

While the Arduino is in some ways like the Raspberry Pi it is still quite different. The Arduino uses a microcontroller which is a simple computer on a chip. On the other hand, the Raspberry Pi contains a System On a Chip (SoC) which is much more advanced than a microcontroller and is able to run a complex operating system such as Linux. So, although both the Arduino and the Raspberry Pi are types of computers and can be used for interfacing, the Arduino is better used for much simpler tasks and is better for time critical tasks. Whereas on an Arduino you can guarantee, for example, that an output changes state at a certain time it's a lot more difficult to do that with most operating systems that run on the Raspberry Pi in which you are at the mercy of the O/S for timing. The exception is the Raspberry Pi Pico, which is more closer to an Arduino since it's a microcontroller based board; please see the Raspberry Pi Pico section for more information.

I've found that when it comes to networking, such as pulling values from online, the Raspberry Pi is a much better choice certainly than the more basic Arduino boards. Most of the Raspberry Pi boards have network connectivity but to network the simpler Arduino boards you need to use an ethernet shield, which actually has more processing power than the Arduino itself!

If quick boot time is important to you then the Arduino (or Raspberry Pi Pico) is likely a better choice since it does not run an O/S and almost immediately runs your code when powered on. A non-Pico Raspberry Pi, however, must load its O/S and when that has loaded then it can hand control over to your program, although there are ways to speed up the process, such as by using a streamlined O/S.

A big advantage that a non-Pico Raspberry Pi has over an Arduino is that you can develop and test code on the Raspberry Pi itself, although that was not such a comfortable experience on the older, slower, versions of the Raspberry Pi. Typically with an Arduino you must write code on a PC (even a Raspberry Pi), download it to the Arduino, test it, make changes on the PC, download it again, etc, which is a much slower process.

Another thing to keep in mind is that the Raspberry Pi (with the exception of the Raspberry Pi Pico) has no analogue inputs but the Arduino does so with the Raspberry Pi you would either have to use an analogue-to-digital converter (ADC) or swap the analogue device for a digital one (there are temperature sensors, for example, that use a digital connection whereas traditionally they had analogue outputs). You could even connect the Arduino to the Raspberry Pi and have the Arduino handle certain inputs.

There are alternatives to the Raspberry Pi that are closer to the Raspberry Pi than the Arduino is, in that they are designed for interfacing but are actual computers as opposed to microcontroller systems. One particular example is the BeagleBoard, and the cut-down version, the BeagleBone, which have some more advanced features compared to the Raspberry Pi but at a higher cost. You will need to look at what is best for your needs at a price that you are comfortable with.

Networking

There are two main ways you can set-up networking on a Raspberry Pi and that is by either an ethernet (model B/B+ only) connection or by using a Wi-fi USB dongle (if there is no on-board wireless). While a wireless connection is generally preferred, ethernet has its advantages. For starters, it uses its own dedicated connection on-board (although internally the Raspberry Pi uses a USB to ethernet device on some boards), freeing up a USB port. Also, a wired connection such as ethernet should be more reliable and be easier to set up-as easy as plugging one end of a network cable into the ethernet port and the other into your router.

Unfortunately I had a lot of trouble getting my Raspberry Pi online both by connecting the Raspberry Pi to my laptop (which networked OK but had no Internet access on the Raspberry Pi) and straight to the router (which would only work if I restarted the router). I had better luck with using a Wi-fi adapter on the Raspberry Pi but it would not connect to the Internet at start-up and it frequently dropped the connection. What also didn't help was the conflict between the Wi-fi adapter and the keyboard and mouse. I had to have the keyboard and mouse connected to a hub and the Wi-fi adapter plugged into the other USB socket of the Raspberry Pi.

After trying so many different things I found the following website which had the solution:

http://raspberrypi.stackexchange.com/questions/13558/how-to-get-wi-fi-to-connect-on-boot

It turns out that Raspbian-the Linux O/S I had been using-doesn't automatically connect to Wi-fi or ethernet at start-up or when the Wi-fi dongle/ethernet cable is plugged in. After making the changes as described in the link above I found that my Raspberry Pi connected to the Internet automatically at boot if a Wi-fi adapter or ethernet cable was plugged in or if either of them were removed and connected again. Of course with Wi-fi it has to be first set up so it knows what network to connect to-Raspbian has a utility to help with that.

Not all Wi-fi adapters work out the Raspberry Pi so be sure to check out this page first:

http://elinux.org/RPi_USB_Wi-Fi_Adapters

Unfortunately I had a lot of trouble networking my Raspberry Pi to my desktop PC through the ethernet connection and in the end bought a TP-Link Wi-Fi extender, model TL-WA860RE. The extender has an ethernet port and once set up the Raspberry Pi was online, effectively converting the wireless signal from my router to a wired one. As well as not having to mess around with trying to network my Raspberry Pi to my PC it means I can have my Raspberry Pi online even when my PC is off.

As well as getting your Raspberry Pi online to view websites and update the computer, networking also provides a way to access your Raspberry Pi in what is known as a 'headless setup'. In this scenario you can use another computer, or a smartphone or tablet to access the Raspberry Pi remotely either with a command line or graphical interface. This means that no monitor, keyboard or mouse needs to be connected to the Raspberry Pi aside from the initial set-up. This is useful for situations where it isn't practical to have devices (keyboard and mouse) connected to the Raspberry Pi and it also saves power by having less connected to the computer. You could, for example, set up the Raspberry Pi to monitor something and have it stored away in a location that isn't easy to access but through networking you would still be able to view the information the Raspberry Pi is gathering and do any necessary updates to the system. The only downside is that you won't be able to remotely access the Raspberry Pi should it lose the network connection,

I put together a networked LED message board using a Raspberry Pi, which you can read about in the Raspberry Pi Networked LED Message Board section.

Networked LED

I had been long working on a networked message board using an Arduino but found it very time consuming to keep making little changes and then transfer the code to the Arduino so I thought about using a Raspberry Pi to make things easier. The most logical next step was to do a test in which I could turn a GPIO controlled LED on/off through a browser. While I did eventually get it to work I hit a number of stumbling blocks although they did help me better understand how Linux and web servers work. I will not be going into too much detail about all the steps as you should be able to find the information online but you can always email me if you need help.

The first thing to do is to install Apache on your Raspberry Pi which will turn it into a web server. The following site will guide you:

http://readwrite.com/2014/06/27/raspberry-pi-web-server-website-hosting

From the Linux terminal you will then need to restart Apache:

sudo service apache2 restart

If you then go to the Rasp Pi's ip address in a browser either on the Rasp Pi or another computer you will be taken to the default Apache webpage that says 'It works!'. You can find out the Rasp Pi's ip address by entering 'ifconfig' into the terminal. Note that some browsers require that you enter 'http://' before the ip address.

When you go to the Rasp Pi's ip address using a browser you are viewing the results of the index.html web page which is located in the /var/www/ folder. You can modify the page, refresh the browser and then you should see the changes.

When using the Rasp Pi as a web server it's a good idea to use a static ip address so that you will always know the address and not have to look it up.

By default the Apache service doesn't start at boot until you set it to, which you can read about at the following site:

http://httpd.apache.org/docs/2.2/invoking.html

Basically, you need to edit rc.local so at the terminal enter:

sudo nano /etc/rc.local

Add following line before the 'exit 0':

sudo service apache2 start &

Then save and exit, then reboot and check the Apache is running. Note the '&' at the end-this is to ensure that the Pi boots correctly.

That's a big step sorted and now what we want to do is have two buttons on a web page; one to turn the LED on and the other to turn the LED off. We can use the HTML's form action tag to run a Python script-one to turn the LED on and another to turn the LED off (or you can have the HTML pass a control value to a single Python script to turn the LED on/off). For the server to be able to run Python scripts you can follow the instructions at this site:

http://www.linux.com/community/blogs/129-servers/757148-configuring-apache2-to-run-python-scripts

You will also need to use the following command in the terminal otherwise the scripts won't run:

sudo a2enmod cgi

Then restart Apache again and you should be able to run Python scripts from the browser. Note that the script runs on the server (the Rasp Pi) but output from the script can be displayed in the browser.

For more information about writing scripts using Python to be run from a browser see the site linked below:

http://raspberrywebserver.com/cgiscripting/writing-cgi-scripts-in-python.html

Note the importance of making the Python script executable. You do this by running the following command:

chmod +x file.py

Where file.py is the Python script to make executable.

There is a folder at /var/www/cgi-bin/ where you can place your scripts. As well as accessing the scripts indirectly through a HTML page you can also go direct to the script using the browser. For e.g.:

http://169.254.0.2/cgi-bin/hello.py

Where 'http://169.254.0.2/' is the (private) ip address of my Rasp Pi web server and 'hello.py' is a Python script located in the /var/www/cgi-bin/ folder.

Now we run into big problems since GPIO needs Sudo permissions which the web server doesn't have and it's not a good idea to give the web server full access to the system as that would be a security risk, especially if the Rasp Pi server was accessible from the Internet (that needs to be set up as currently the server can only be accessed from the same network the server is connected to).

The way I got it to work was by make use of a file I created called LED_state.dat, which holds the current state of the LED; 'Y' for on and 'N' (or anything else) for off. I then had a Python script run at boot using cron (which gives the script sudo permissions) and this script checks LED_state.dat every 5 seconds and turns the LED on/off accordingly. Then, the HTML page runs a Python script when a button is pressed to write either a 'Y' or 'N' to LED_state.dat. However, you must set LED_state.dat (or whatever file you use) for the server to have write permission to the file:

sudo chmod 666 led_state.dat

The above command gives all users read and write permission to just that file, thus the server is still limited in what it can do, lowering the chance of security issues. It would probably of been better to create a new group and add the server to that group and then allow that group read/write access to the file.

The result is that it works although not in the most ideal way; clicking a button in the browser either turns the LED on/off. There is a slight delay as the LED_state.dat file is only checked every 5 seconds. In addition we have seen how we can bridge the gap between the web and an output device (an LED) running on a computer.

When working on such a project it's a very good idea to check Apache's log when things don't work. One way to view it is to run the following command from the terminal:

nano /var/log/apache2/error.log

A word about Python scripts: it's vital that at the start of a python script you have the following to determine what interpreter to use:

#! /usr/bin/env python

Do not put anything else on that line not even a comment otherwise you'll get a 'no such file or directory' error when you try to run the python script from the web.

A mentioned earlier you can use a simple Python script which has a value passed to it from the HTML web page that causes the Python script to do something based on the value it receives. In the following example we will pass text from a text input box on a HTML web page and display it in the browser.

The code for the HTML web page is as follows:

<form action="/cgi-bin/html_ip_request.py" method="POST">

<textarea name="inTextBox" cols="50" rows="5">

Enter message...

</textarea>

<input type="submit"/>

</form>

In the Python script 'html_ip_request.py' we have:

import cgi

print "Content-Type: text/html;charet=utf-8"

print

print ("<h2>Args</h2>")

form=cgi.FieldStorage() #Determine type of request to be processed

arg1=form.getvalue('inTextBox')

print ("Param1: "+arg1)

The result is that when you click the submit button whatever you typed into the text box is displayed.

Networked LED Message Board

The idea behind this project was to make use of an LED dot matrix display (Sure 0832) which would display the time, date, messages and even allow playing of a simple game. It started life as an Arduino project and because of the display being made up of LED dots I referred to it as project Dotty. However, I found it very time consuming to have to keep making small changes and then transfer the updated code to the Arduino. This was a shame as I had got far with the project, having had added the game mode which was a maze type game.

Then the Raspberry Pi came along and seeing how I could develop the code and see the output much quicker I started to port the programming to the Rasp Pi. I also did the test as described in the section 'Networked LED' section above as I wanted a way to control the message board through my network as I had planned to back when using an Arduino and ethernet shield.

To summarise the features of the message board:

*Switch between displaying the current time and date

*Messages are displayed when a certain time and date are reached

*A simple game can be played for one player

*Settings can be viewed and changed through a web browser

*Headless access to Rasp Pi to debug and update

Note that the message board is designed to be connected to a local network only although it could be Internet accessible but there would be greater security risks.

For the project I am using a Raspberry Pi model B+ although there should be no problem using other Rasp Pi's as long as they have an ethernet port (i.e. B/B+). You could use Wi-fi but by using ethernet the message board will have a more reliable network connection and we can both power the Rasp Pi and put it on the network by using a single ethernet connection by using Power over Ethernet (PoE). This is especially useful if you wanted to locate the message board a distance from a power outlet. As the Rasp Pi I chose to use doesn't directly support PoE we have to use adapters, such as the ones visible in the photo below:

What you see are two D-Link DWL-P200 PoE adapter units which, when used together, combine power with data at one end and at the other, separate the power and data; they are connected by a single ethernet cable. The bottom unit is the base unit which accepts the ethernet and power inputs and combines them together. The input voltage is 48VDC at 500mA (the standard for PoE) but I was able to get the units working with a 40VDC power supply.

The top unit is the terminal unit and has ethernet and power output; the voltage can be switched between 12V and 5VDC (use the 5V setting for the Rasp). The spec sheet lists the 5V output as 2.5A and the 12V as 1A; 2.5A is more than enough to power the Raspberry Pi. Both units have an LED so you can at least see that they are receiving power.

The terminal unit should be located inside the message board housing but because it's not possible to fix the PoE unit directly to whatever contains the message board you will need a lead with an ethernet socket on one end and an ethernet plug on the other. The ethernet socket will be  accessible on the outside of the message board and will be what the user plugs their network cable in; the ethernet plug will go into the PoE terminal unit.

At boot, the Rasp runs the Python script 'msg_board_main.py'. To add this entry to cron, issue this command at the terminal:

sudo crontab -e

Then add:

@reboot python3 /home/pi/msg_board_main.py

Don't forget to change the path if you store the script somewhere else.

The script 'msg_board_main.py' is the main script but makes use of 'Sure_0832_mod.py' which handles the low level access to the display. At start up the display is initialised and cleared before entering a loop to check whether to change the current mode and then the display is updated based on the current mode. To know which mode to use the file 'msg_board.dat' is checked which is updated by an HTML web page, 'index.html', which is the interface to the network message board. The file acts as a means for the web page to communicate with the Python script but it is not an ideal solution as the file is continually checked.

The web page 'index.html' provides the interface to the user and calls the Python script 'msg_board_update.py' with a key and value to tell the script what to do. If key is 'mode' and value is '1' then the mode becomes 'Show time' and a '1' is written to 'msg_board.dat'. But if the value is '2' the mode is changed to 'Show date' and a '2' is written to 'msg_board.dat'. It is 'index.html' which actually passes the key and the value to the 'msg_board_update.py' script.

When everything is set up, plug an ethernet cable and power lead into the base unit and switch on; after a short while you should see the display lit and after a bit more waiting the time should adjust to the correct value. As the Rasp doesn't have a built in clock the time won't be correct until it connects to the Internet. At this point you can remotely access the Rasp if it has been set up for remote access or enter the following URL into your browser to access the network message board settings page:

http://raspberrypi.default

On thus page you can click the Show date button to show the date in format dd/mm; you need to click your browser's back button to return to the settings page. To show the time again all you need to do is click the Show time button.

Programming

Once you have your Raspberry Pi set up with a bootable SD card, there are a number of programming languages you can use to write your own programs. These include Python, C/C++ and a version of BBC BASIC (that was available on the BBC microcomputer). If you have never programmed before or only a bit, then Python and BASIC are a great place to start. For children, there is the Scratch programming language which uses dragging and dropping conditions with the mouse to control a number of sprites. For more advanced users, there is C/C++.

For someone like me who is used to using Windows the Raspberry Pi is a good excuse to become familiar with Linux. It is also a good opportunity to learn OpenGL which the Raspberry Pi supports (OpenGL ES 2.0).

Software

The Raspberry Pi doesn't come with a built-in operating system (O/S) but boots off an SD card; the computer is able to run Linux as well as other operating systems such as Android and RISC OS. RISC OS is particularly interesting from a nostalgic point of view because it was created by the team that invented the original ARM processor. If your Raspberry Pi didn't come with an SD card already containing an O/S you will need to use another computer to download a compatible operating system which then needs to be written to an SD card (be sure to check what physical size your Raspberry Pi uses). You can download an SD image containing an O/S for use with the Raspberry Pi by visiting the following website:

http://www.raspberrypi.org/downloads/

Raspbian (now called Raspberry Pi O/S) is a version of Linux designed for the Raspberry Pi and is a safe choice to get you started although if you are not familiar with Linux  it may take some time getting used to but then it's a good opportunity to learn.

When you have the O/S downloaded you will then need to write the image to an SD card ready for the Raspberry Pi to use; I use Win32DiskImager (runs on Windows). Then it's a simple matter of putting the SD card into the Raspberry Pi, connect it to a mouse, keyboard and TV or monitor and then apply power. Once you get into the desktop you can expand the system so you get the full space of the SD card so there is plenty of space for your own files. Learn how to do it here:

https://geek-university.com/raspberry-pi/expand-raspbian-filesystem/ 

It's important to keep the Raspberry Pi O/S updated so that you get the best experience and to help keep your computer protected from security threats. You can read more about the update process at:

https://www.raspberrypi.org/documentation/raspbian/updating.md 

It's important to remember that the first Raspberry Pi models have a 32-bit CPU and even when Rasp Pis were introduced with 64-bit CPUs the O/S remained 32-bit for some while. The advantage of a 32-bit O/S is it will run on all Rasp Pis although it won't take full advantage of the power of a 64-bit CPU, with one downside of a 32-bit O/S being that a process is limited to being able to access no more than 3GB of RAM.

On 28th May 2020 a beta version of 'Buster' Raspberry Pi O/S became available, which can be downloaded from this site:

https://www.raspberrypi.org/forums/viewtopic.php?t=275370 

Note that it will only work on a Rasp Pi 3 and Rasp Pi 4 and as it's in beta there are likely stability issues.

By using the 64-bit version of the O/S for the Rasp Pi, a process can access up to 8GB (on the 8GB model, of course) and much larger integer values can be processed but as that's not always necessary, often the 32-bit O/S is the best choice for most people.

Adafruit PiOLED

The PiOLED from Adafruit is a tiny 1" diagonal OLED monochrome (white) display designed to fit directly on to a non-Pico Raspberry Pi GPIO header and pairs especially nicely with the diminutive Raspberry Pi Zero. Measuring only 35.0x20.0x10.5mm, and weighing just 3.5g, the PiOLED has a resolution of 128x32 pixels and uses the common SSD1306 I2C display controller IC.

You can find the PiOLED product page at:

https://www.adafruit.com/product/3527

The site has links for instructions, software, etc.; going to the end of the instructions you will find the schematic and download links.

Rather than test on a Raspberry Pi I used an STM32 Discovery Kit IoT node as I had been using the board to test another, similar OLED display. If you want to use the Discovery, or another Arduino compatible board, it's best to run the display off no more than 3.3V and only and use 3.3V signals, to adhere to the SSD1306 requirements.

In the Arduino IDE install the Adafruit SSD1306 library, after installing there will be a number of examples under File->Examples->Adafruit SSD1306. We can use the ssd1306_128x32_i2c example sketch, which will go through a number of demos. I connected the OLED to the Discovery in the following manner, using the Raspberry Pi GPIO connector pin numbering for the OLED:

OLED Discovery
1 3.3V 4 (CN2) 3V3
3 SDA 9 (CN1) D14
5 SCL 10 (CN1) D15
6 GND 6 (CN2) GND

Here is a video from YouTuber JetsonHacks showing how to use the display on the Jetson Nano:

Pimoroni Enviro pHAT

The Enviro pHAT from Pimoroni measures 65.0x30.0x2.6mm, weighs 6.8g, and provides the means to obtain temperature, pressure, light, colour, motion, and analog sensor readings, and is compatible with any Raspberry Pi with a 40-pin GPIO connector. When bought new you need to solder a 2x20 pin GPIO header to the board but as I got my Enviro second hand as part of an eBay job lot a header had already been soldered but with long pins, likely so another HAT could also be plugged into the Pi (indeed, there was a PiOLED in the job lot). The Enviro came with an optional 6-way header that could be soldered if you wanted to take advantage of the analog inputs (a big bonus considering the non-Pico Pi has no native analog inputs).

We can read more information about the Enviro at:

https://www.adafruit.com/product/3194

In summary the board has the following:

BMP280 temperature/pressure sensor
TCS3472 light and RBG colour sensor
Two LEDs for illumination
LSM303D accelerometer/magnetometer sensor
ADS1015 4-channel 3.3V, analog to digital sensor (ADC)

Unfortunately I couldn't find a schematic for the board but that's not critical for using it.

More information can be found at:

https://pinout.xyz/pinout/enviro_phat

As well as a GitHub entry at:

https://github.com/pimoroni/enviro-phat

With an in depth look at the Enviro at:

https://blog.pimoroni.com/enviro-phat/

To test the Enviro, first I updated my Raspberry Pi in the usual way and then followed the tutorial at:

https://learn.pimoroni.com/article/getting-started-with-enviro-phat

As specified, I installed the software using:

curl https://get.pimoroni.com/envirophat | bash

After it finished I shutdown the Pi and then plugged the Enviro pHAT into the Pi's GPIO, the board should face inward. When powering on the Pi 2 LEDs (white) on the Enviro were illuminated. I then continued the tutorial but after entering python and issuing 'from envirophat import light' I got No such file or directory error. Amongst the error information was:

from .i2c_bus import bus

Which was a clue as to the issue, as it suggests I2C is disabled. To enable:

sudo raspi-config

Select Interfacing Options with arrow key down, press enter, select I2C with arrow key down, press enter. When prompted 'Would you like the ARM I2C interface to be enabled' select Yes with arrow key left and press enter. You will be informed 'The ARM I2C interface is enabled', press enter on OK. Then press Esc to exit config. Now when I entered python again and tried importing 'light' there was no error. But when I tried:

print light.light()

I got a syntax error. I realised this is because in Python 3 you use print() so the following works:

print(light.light())

Oddly, in the tutorial they use the correct version from the weather section onward.

I was successfully able to read the RGB values, holding various objects near the light/colour sensor and checking the RGB values. I continued, trying out the weather example - note that to check the pressure value is correct you can look at online weather reports for your area, the value should be similar even if indoors. All other tests worked and I had previously soldered the analog header, helpfully the analog connections for soldering a header are slightly staggered, which holds the header with a tight fit while soldering.

Even though the analog inputs are limited to 3.3V max, a 5V connection has been provided but the reasoning may have been to provide compatiblity with certain sensors. The tutorial recommends using three resistors to obtain 3.3V but we can take 3.3V from the Pi's GPIO pin 1 (if the Enviro GPIO header has long pins). Then, for testing, we can connect a potentiometer with its opposite pins to 3.3V and GND, and its wiper to an analog input to the Enviro. I used a simple while loop in Python to continually display the analog value (which is in volts) without delay (see the tutorial for the commands to use) and noticed it takes a few seconds before the displayed reading updates due to changing resistance values,  likely an issue with the slowness of Python. When I used a delay of 0.5ms the values displayed updated immediately, giving an idea of the delay as a consequence of using Python.

If you want to look further into the board you can find complete documentation for the Enviro Python library at:

http://docs.pimoroni.com/envirophat/

ST25P16 2MB Flash Memory

I had won an eBay auction in which, amongst other components, there were 48 ST25P16 flash memory chips. Each chip holds 2MB and uses a standard SPI interface, supporting modes 0 and 3. The chips themselves are SMD (SOIC) and although they have 16 pins only 8 of them are used (the rest are not internally connected). The first challenge was to actually make connections to the chip so that it could be tested since it would not fit on breadboard. For my first attempt I soldered wires to the chip's pins but for the second try I bent the outer 8 pins so that they could be soldered to prototype board along with some header pins.

The ST25P16 is similar to to the W25P16 which you can read about below:

http://datasheet.octopart.com/W25P80VSSIG-Winbond-datasheet-22205.pdf

For testing I used the datasheet linked above while also referencing the ST25P16 datasheet, which I could only find in Chinese:

http://www.datasheet.hk/search.php?part=st25p16&stype=part

It is, of course, possible to translate the PDF using an online service but nonetheless the ST25P16 does differ to the W25P16 in that, for example, it has less instructions - there is no support for the parameter page. But as the above PDF has less information, such as timing values, I had to go by the W25P16 PDF.

I tried to interface the ST25P16 to an Arduino Uno using 10K resistors to convert the Arduino's 5V logic levels to the 3.3V logic levels that the flash chip uses and powering the chip off the Arduino's 3.3V power connection. Using the Arduino's SPI library, which I reduced to a low speed for the SPI communication because of using resistors and breadboard, I could only get zeroes back when using commands to get manufacturer and ID. What I did notice from connecting my logic analyser was that at times chip select would go high when it shouldn't even though in my Arduino code I hadn't change the CS line at that point.

Wanting to simplify things I moved on to using the Raspberry Pi which uses 3.3V logic so there would be no need for the conversion resistors which are far from ideal. However, I had the same problem of not getting back the correct values even after trying a second chip, which suggested to me I was overlooking something simple.

The ST25P16 has a power down and power up command so I took advantage of them by connecting my multimeter to measure the current draw and found that the current dropped from 17uA to 6uA when powered down, and back up to 17uA when powered back up, and when issuing other commands the current briefly spiked, To me this was evidence that the chip was indeed recognising and executing instructions.

What I found was that as with using the Arduino, the problem was the CS line going high when it shouldn't and in the case of the Raspberry Pi my mistake was using separate xfer2 functions to send and receive data. By calling xfer2 once with the data to send I was able to get back the correct values such as the manufacturer value. Then I was able to read a memory location which returned 0xFF, as to be expected since the chip was unused, that is, it was ready to be programmed. I successfully changed the same byte to a different value and also read and modified a second byte. Because with flash memory you only actually writes zeroes to memory to change a memory location, you have to erase the section which contains the memory locations, which set those locations to all ones. If you try to change the same byte without erasing it the value becomes zero (for other flash memory you may get other results-you should only be able to change a bit to 0).

This is how I connected the ST25P16 to my Raspberry Pi:

HOLD (1), VCC (2) and WP (9) to Rasp 3.3V (1)

CS (7) to Rasp CE0 (24)

DO (8) to Rasp MISO (21)

GND (10) to Rasp GND (6)

DI (15) to Rasp MOSI (19)

CLK (16) to Rasp SCLK (23)

The code I wrote is called 'SPI_test.py' and can be found for download at the bottom of this page. The code contains some core routines which are called from the main program. First a sector is erased (by calling sector_erase()) and then the first two bytes are read in and displayed (by calling read_data()); you should get 0xFF for both bytes. Then the first byte is programmed as 0xCE and the second byte as 0x92 (by calling page_program()) which are both read in and displayed as the values they were (hopefully) just set to.

To do any type of memory modification - programming - you must first enable writing which is done by calling the write_enable() function. Rather than having to keep checking the busy flag (by reading the status register) I wait the maximum time for an operation to complete as stated in the datasheet; for a sector erase the wait time is 1.5 seconds and for modifying a byte the time is 8ms. It would be a good idea to check the busy flag even after waiting, especially if writing multiple bytes in succession.

In the main program some function calls are commented out which you can easily un-comment to use them:

power_down()     Lowers power consumption.

power_up_get_ID()    Turns the chip back on and then displays the ID value (should be 0x14).

get_man_dev_ID()     Displays the manufacturer and device ID (0x20 for manufacturer, 0x20 for memory type, and 0x15 for memory capacity).

read_status()        Outputs status register values (various status bits).

Tips & Tricks

Accessing a Rasp Pi SD card on a PC

On a Windows PC it is no trouble to access the boot partition of the SD card by putting it in your computer (Windows may say it needs fixing-cancel the dialog box). This is handy to change the configuration (by editing the config file) to force HDMI output, for example.

If you are using Windows and want to access the files that are not in the boot partition you can use a program such as DiskInternals Linux Reader which lets your save files to your computer. You can also use a program (e.g. Win32 Disk Imager) to backup the whole SD card rather than having to copy individual files. Then, should you have problems with the SD card later on you can at least use the SD card backup to restore the SD card.

Alternatives to HDMI for HD output

Sometimes it's the case that you want to connect a Raspberry Pi to a monitor that does not have HDMI input so you may look at how to convert HDMI to some other HD signal. Unfortunately you cannot use DisplayPort even if you buy an HDMI to DisplayPort adapter or lead as the Raspberry Pi doesn't support DisplayPort. As for VGA, some adapters from HDMI to VGA work but some adapters have been known to damage the Raspberry PI so I would avoid them. What does work, however, is an HDMI to DVI-D lead or adapter, which is useful as DVI is very common on monitors.

Minecraft Pi


Please note that the information presented here refers to the default preinstalled version of Minecraft Pi that's usually included in Raspbian.

Basics


As of 2021, the Pi edition of Minecraft hasn't been updated since 2015 and unlikely to be updated hence why it's in alpha, but that still could change in the future.


For some reason the game world is rendered slightly offset from the Minecraft window, so to move the game around the screen or to close it you must interact with the window not the game screen (it can be quite difficult to grab the window by its title bar so keep trying). You can resize the window by dragging the corners which resizes the game world.


Use the tab key to regain control of the mouse pointer or press esc to pause the game, which will also give control back of the mouse pointer.


The game mode is creative only, there are no mobs and the world has a maximum size of 256 x 256 x 128 blocks.


Full screen


While the application does have a maximize button and it does make the window bigger it doesn't trigger full screen mode.


It is possible to enter full screen with instructions I found at:

https://forums.raspberrypi.com/viewtopic.php?f=62&t=229620


Go into a world, make sure the window is focused, hit escape to bring up the pause menu, and press ALT+fn+F11. I found that I had to press the key combination a couple of times for it to work but note that the game won't cover the entire screen (as is the case if you enlarge the window using the maximize button). You can press the key combination again to return to windowed mode.

Sound

There is no sound in Minecraft Pi even though the pause screen has the option to turn sound on/off. 

Remote Shutdown and restart

To shutdown the Rasp from the terminal use:

sudo shutdown -h now

To restart the Rasp from the terminal use:

sudo shutdown -r now

Note that if you remote access a Rasp you can't restart it from the usual place but you can do so using the above command in the terminal.

Remote copy and paste

When remote accessing a Raspberry Pi it can helpful to be able to transfer files between computers but unfortunately the free version of TightVNC doesn't support file transfer and that also seems to be the case with RealVNC. You can, however, copy and paste text between computers which at least allows for backing up text files. To do so, you need to install autocutsel on the Rasp Pi and then modify VNC's startup script, which is explained on the following site:

http://raspberrypi.stackexchange.com/questions/4474/tightvnc-copy-paste-between-local-os-and-raspberry-pi

Remote access IP address

Although it is best to use a static IP address for accessing a Rasp Pi remotely you can use 'raspberrypi.default' which represents the Rasp's IP address. If you do need to know the IP address of a Rasp Pi or other computer on your network you can use a program called Advanced IP Scanner which can be downloaded from:

http://www.advanced-ip-scanner.com/

Troubleshooting

No HDMI output

Being a single board computer the Raspberry Pi should have less problems than a more complex computer such as a typical PC but there are a number of things that can slip people up. For starters, I had the situation where I had previously used my Raspberry Pi 2 but when I returned to it I got no output on my TV, which was the same TV I had used before. As I had the Rasp connected to my TV via HDMI I tried a different HDMI cable but there was still nothing on the screen. I could at least see that the Rasp appeared to be booting because of the status LED's. A suggestion about checking the config file (which can be accessed by putting the Rasp's SD card into a PC) led to the solution. Basically, you need to force the Rasp to use HDMI:

http://blog.mivia.dk/solved-hdmi-working-raspberry-pi/

After forcing HDMI output I was then getting output on my TV but the resolution was low so I followed the instructions in the following link to set the resolution:

https://www.raspberrypi.org/documentation/configuration/config-txt.md

This doesn't explain why the Rasp had worked previously and then stopped working but the fix got the output on the screen again. Note that you must have your TV/monitor plugged into the Rasp and turned on before turning the computer on otherwise that can stop the Rasp outputting to the TV/monitor.

For more helpful HDMI info please see:

https://www.raspberrypi.org/documentation/configuration/hdmi-config.md

GDBus error

After setting up remote access on my Rasp Pi 2 and then starting it up I saw a GDBus error. The following site has a solution:

http://raspberrypi.stackexchange.com/questions/27542/raspberry-pi-2-gdbus-error-on-start-up

Cannot clone SD card

When you have your Raspberry Pi's SD card set up how you want it it's a very good idea to back it up in case the SD card becomes corrupted (due to power failure, for example). On Windows you can use Win32DiskImager, which can also be used to create the SD card image in the first place. When it came to backing up my SD card I got a redundancy check error. It turns out the USB SD card adapter was at fault; when I used my computer's built-in SD card reader I was able to back up the SD card without any problems.

Flashing cursor at start-up; does not boot into GUI.

This happened to me after installing Chromium and then rebooting. The fix is to boot the Rasp and when you get to the flashing cursor and press CTRL+ALT+F1 which will allow you access the terminal. Type sudo raspi-config and press enter, expand the file system and reboot the computer, which should now start as normal. The reason why this worked was because I hadn't previously expanded the file system and after installing Chromium it reported that it had run out of space.

Lightning bolt on desktop

If you see a yellow lightning bolt in the upper right corner at boot time or while at the desktop then the Raspberry Pi is warning you that the power supply you are using isn't providing a high enough voltage. Switch to using a different power supply and that should fix the problem; the official Ras Pi power supply is recommended. With the Rasp Pi 3 B+ the lightning bolt at boot can also be an indication that the software on the SD card needs to be a newer version.

Links

Official site:

https://www.raspberrypi.org/ 

Downloads page (O/S images):

https://www.raspberrypi.org/downloads/ 

Official YouTube channel:

https://www.youtube.com/channel/UCFIjVWFZ__KhtTXHDJ7vgng 

Guides for getting started with the Raspberry Pi:

https://projects.raspberrypi.org/en/pathways/getting-started-with-raspberry-pi 

A short guide to Linux on the Raspberry Pi:

https://www.raspberrypi.org/documentation/linux/ 

All content of this and related pages is copyright (c) James S. 2012-2024