Search

Using HATs with the Original Raspberry Pi - Tom's Hardware

mixdes.blogspot.com

Do you remember what you did 10 years ago? I remember. February 29 2012 at 6:50am an alarm sounded, but I had been awake for a while. I’d heard about the Raspberry Pi from British media and decided that I had to have one.

So I opened my laptop and joined virtual queues for RS Components and Element 14, both of which were the official resellers for the Raspberry Pi. Along with tens of thousands of other people, I slowly DDOSed both sites as I hit F5 to wait for the sale to begin. I was lucky, but many weren’t. I got a Raspberry Pi, but I still had to wait a long time for my first board to arrive.

(Image credit: Tom's Hardware)

When the board arrived, we had a $35 Linux computer with 256MB of RAM (yes the very first Pis had very little RAM) and a single 700 MHz ARM1176JZF-S CPU and VideoCore IV GPU which made up the BCM2835 SoC. I loaded Raspbian (now known as Raspberry Pi OS) and marvelled at what could be achieved with such low power hardware. I learned the GPIO, Python, Node-RED and Scratch using this board. As new boards were announced I was there, ready and waiting for the next iteration, better CPUs, more RAM, Wi-Fi, Bluetooth and even more GPIO pins.

The Raspberry Pi B+, released in 2014 was a complete redesign of the Raspberry Pi. It introduced the 40 pin GPIO, a new add-on board standard called HATs (Hardware Attached on Top) and a board layout which remained largely the same until the Raspberry Pi 4.
The new GPIO introduced 14 more GPIO pins, increasing the total to 40, and two of those pins (physical pins 27 and 28) were configured to work with EEPROMs on compatible boards. This was largely unused but the HAT standard also created a physical standard which used M2.5 screw mounts on the Raspberry Pi to secure HATs.  

(Image credit: Tom's Hardware)

The very first Raspberry Pi had a short, but eventful life. But now it resides in a box, along with my collection of 50+ Raspberry Pi boards. As we come together to celebrate a decade of Raspberry Pi, I thought it would be fun to put the old Raspberry Pi through its paces. Could I use it 10 years after I bought it? What can we do with it? Can we use a HAT? To learn this, and more we need to brush off the cobwebs and fire up the classic Raspberry Pi 1 for another adventure.

Can we use it as a desktop machine?

The short answer is no. The 256MB Raspberry Pi 1 hasn’t got the CPU performance to push a desktop OS. A 512MB model is possible but the odds are stacked against you. The desktop will be slow and you can forget about browsing the web. An OS such as Tiny Core Linux could inject a little life, but it isn’t a miracle worker. 

Can we use the GPIO?

 The standard 26 pin GPIO has plenty of pins at our disposal. For basic GPIO work using digital, PWM and I2C, SPI we don’t need a powerful CPU and Gigabytes of RAM. We tested the traditional RPi.GPIO and GPIO Zero Python libraries and everything was great, no issues whatsoever. If you want to get the kids interested in electronics, or just fancy learning a new skill, then the Raspberry Pi 1 is more than up to the task but we recommend using the Pi headless.

Can we use a HAT? 

(Image credit: Tom's Hardware)

This is where our adventure truly kicks off and it is also where we do a light bit of hacking to make the 26 GPIO pin more compatible with the 40 pin add-ons. HATs were designed for the 40 pin models of Pi and as such they are largely incompatible with the 26 pin GPIO. But as always there is a way to hack it.

Before we start making any hardware / software changes we need to check that our HAT is compatible with the older Raspberry Pi and for that we need to do a little research.

Pinout.xyz, created by Phil Howard, of Pimoroni fame, is an essential tool for GPIO hackers. With the site we can check what each pin of a Raspberry Pi is capable of, alternative numbering schemes and most importantly what boards work with the Pi. Under the boards, HATs and pHATs section we can search a long list of boards and learn what GPIO pins they use, and how to work with them. This is where we started our research and for our how-to. We chose the Scroll pHAT HD, a simple board that controls a matrix of LEDs, because it’s ideal to quickly and easily debug any issues.

The workflow to check that a HAT works with the original Raspberry Pi is

1. In a browser go to pinout.xyz

2. Scroll through the list of boards, click on your board. Here we scroll down to Scroll pHAT HD. 

(Image credit: Tom's Hardware)

3. Check that your board does not use any pins after pins 25 and 26. Pins 25 (GND) and 26 (GPIO7) are the original GPIO pin limit. Any pins after this are only present on the Raspberry Pi B+ onwards.

(Image credit: Tom's Hardware)

If your HAT is compatible now is the time to attach it to the Raspberry Pi. But, we can’t just place the HAT on the Raspberry Pi 1. The first 26 pins are identical, but the older Pi has an RCA composite jack in the way. So to attach a HAT we need to create a hack.

1. With the Raspberry Pi turned off, place a 40 pin female to male GPIO header extension on the 26 pins of the Raspberry Pi. The first 14 pins of the header will hang over the edge of Pi, nearest the SD card slot.

(Image credit: Tom's Hardware)

2. Place your HAT on to the GPIO, ignoring the first 14 pins ( 2 columns of 7 pins) which hang over the Pi. Only connect to pins that are connected to the Pi's GPIO.

(Image credit: Tom's Hardware)

3. Before powering on, double check your GPIO connections. If you get this wrong you may damage the HAT, or worse still damage the vintage Raspberry Pi 1.

As the original Raspberry Pi is rather slow we’re going to use a lighter version of the 32-bit Raspberry Pi OS. This has no desktop environment, affording us more precious RAM that we can use in our projects. To install the OS we shall use the latest version of Raspberry Pi Imager (v1.7.1 at the time of writing).

1. Open the Raspberry Pi Imager and select CHOOSE OS.

(Image credit: Tom's Hardware)

2. Click on Other. This will show alternative versions of Raspberry Pi OS.

(Image credit: Tom's Hardware)

3. Click on Raspberry Pi OS Lite (32-bit). This lightweight version of Raspberry Pi OS is ideal for embedded projects such as robots and machine learning. It is also ideal for the rather elderly Raspberry Pi 1.

(Image credit: Tom's Hardware)

4. Insert an SD card into your computer, then click on CHOOSE STORAGE.

(Image credit: Tom's Hardware)

5. Select the SD card from the list.

(Image credit: Tom's Hardware)

6. Click on the Settings cog in the bottom right of the screen. This new feature was introduced in v 1.7.1 and it replaces a secret advanced menu that was only accessible by pressing SHIFT+ CTRL + X.

(Image credit: Tom's Hardware)

7. Scroll down and enable SSH and set a new password. You can reuse “raspberry” but now is the ideal opportunity to quickly change it. Should you need to update your password it can be done via the Terminal.

(Image credit: Tom's Hardware)

8. Scroll down and setup your Wi-Fi connection details, also update your Wi-Fi country. You will need to type in the details for the SSID as it cannot scan for APs.

(Image credit: Tom's Hardware)

9. Scroll down and set your locale details before pressing SAVE. These details will set our keyboard and timezone settings.

(Image credit: Tom's Hardware)

10. Click on WRITE to download, copy and configure the OS to our SD card.

(Image credit: Tom's Hardware)

11. When complete, eject the SD card and insert it into your Raspberry Pi along with a USB Wi-Fi dongle. We tried three USB Wi-Fi dongles. One popular third party, another from a named brand, and a random adaptor found in a drawer. Every single one worked with no issues, a credit to the improved support that Raspberry Pi OS now provides. But as ever, your mileage may vary.

12. Power up the Raspberry Pi.

Booting the Raspberry Pi 1 will take some time, remember this is a single core 700 MHz  PU with 256 / 512MB of DDR2 RAM. For the first boot it is best to wait a few minutes before trying to login.

We’ll remotely connect to the Raspberry Pi using SSH. For Windows users you will need to download and install a copy of PuTTY. Linux and Mac users can access SSH via the terminal.

1. Open PuTTY and enter the hostname as raspberrypi.local, ensure that port 22 is selected and that the connection type is SSH. On some networks, the name may be raspberrypi (without local). 

(Image credit: Tom's Hardware)

2. Under Saved Sessions give the session the name Raspberry Pi 1, then click Save. This step means that we never have to remember the session details. 

(Image credit: Tom's Hardware)

3. From the list, click on Raspberry Pi 1 and then Open. This will create an SSH connection between our Windows machine and the Raspberry Pi 1.

(Image credit: Tom's Hardware)

4. Enter your username and password then press Enter. You may see a security prompt, this is normal and can be trusted. Your password will not be printed (echoed) to the screen to prevent “shoulder surfing”.

(Image credit: Tom's Hardware)

5. Update the software on your Raspberry Pi 1 using these two commands. Press Enter after each command. This will take some time, but it is good practice to keep your Raspberry Pi up-to-date.

sudo apt update
sudo apt upgrade -y

What boards did we test?

Image 1 of 4

Using HATs with the Original Raspberry Pi

(Image credit: Tom's Hardware)
Image 2 of 4

Using HATs with the Original Raspberry Pi

(Image credit: Tom's Hardware)
Image 3 of 4

Using HATs with the Original Raspberry Pi

(Image credit: Tom's Hardware)
Image 4 of 4

Using HATs with the Original Raspberry Pi

(Image credit: Tom's Hardware)

We tested a handful of boards from our box of bits. The first was Raspberry Pi’s own Sense HAT, and despite the 8 x 8 LED matrix showing a rainbow (the default state) we couldn’t get any text to display, nor could we change the colors on the matrix. Another failure was Pimoroni’s Explorer HAT Pro, one of the best Raspberry Pi HATs overall, and Explorer pHAT. These two boards have some pins only accessible to 40 pin GPIOs, but the analog inputs are within the 26 pins of the Raspberry Pi 1. Everything installed correctly but sadly the Python code crashed when trying to read the analog pins.

So what worked?

Board Working? Connection Notes
Pimoroni Blinkt Yes Simplified SPI (Data and Clock) Runs slowly, but it works
Unicorn HAT Yes PWM Works by default
Scroll pHAT HD Yes I2C I2C config needs a tweak, see the main text.
Breakout Garden Yes I2C I2C config needs a tweak, see the main text.
BME680 Yes I2C I2C config needs a tweak, see the main text.
Pimoroni Breakout Garden 1.12 inch OLED Yes I2C Standard installation I2C config needs a tweak, see the main text.

Any boards that just use I2C or SPI will work, as will any boards that use simple digital / PWM GPIO pins.

I2C Tweaks

The original Raspberry Pi’s I2C channels were on bus 0, but for future boards this was changed to 1. Since there are so many more models of 40 pin GPIO Raspberry Pi most scripts and libraries will use the latter. This caused us a few headaches when installing and using software libraries.

See more

The Scroll pHAT HD uses a 17 x 7 LED matrix which uses an IS31FL3731 LED matrix driver chip to control the LEDs. This chip connects over I2C and by default the Python library looks to I2C bus 1, so this hack is rather simple to achieve. After installing the software we need to edit a file.

1. Open the is31fl3731.py in the nano text editor using sudo.

sudo nano /usr/lib/python3/dist-packages/scrollphathd/is31fl3731.py

2. Scroll down to line 43 (there are no line numbers) and change the 1 to a 0.

(Image credit: Tom's Hardware)

3. Press CTRL + X, then Y and Enter to save and exit.

The code will now run cleanly with no errors.

Breakout Garden

The installer process uses a Python file, autodetect.py which is inside the breakout-garden-master directory.

1. Open the autodetect.py file in nano.

(Image credit: Tom's Hardware)

2. On line 5 there is a variable for the I2C bus. Change this from 1 to 0.

(Image credit: Tom's Hardware)

3. Press CTRL + X, then Y and Enter to save and exit.

4. Retry the installer and it will now work and detect any connected Breakout Garden components.

BME680

(Image credit: Tom's Hardware)

Our Breakout Garden BME680 air quality / temperature / humidity sensor installed with no issues but once we tested out a simple script to read all the sensors we hit an error. On line 43 is where the error originates and we can see self._i2c = smbus.SMBus(1). SMBus is a Python library to access the I2C bus and so we have found our issue.

1. Open the file using nano with sudo.

sudo nano /usr/local/lib/python3.9/dist-packages/bme680/__init__.py

2. Scroll down to line 43 (there are no line numbers) and change the 1 to a 0.

(Image credit: Tom's Hardware)

3. Press CTRL + X, then Y and Enter to save and exit.

The code will now run cleanly with no errors.

Breakout Garden 1.12 inch OLED

Follow the standard installation instructions but when using the maze demo we need to change the command as follows.

The installation instructions tell us to use this command.

python3 maze.py --display sh1106 --height 128 --rotate 2 --interface i2c

Append –i2c-port 0 to the command so that it looks like this.

python3 maze.py --display sh1106 --height 128 --rotate 2 --interface i2c --i2c-port 0

So the lesson learned from this exercise is that I2C is most likely going to fail, but as the GPIO locations are mostly the same, all we need to do is locate the config file for our chosen board and tweak the I2C settings and we will be running the latest boards on the oldest of Raspberry Pi.

Adblock test (Why?)



"original" - Google News
February 27, 2022 at 10:00PM
https://ift.tt/awz6I2e

Using HATs with the Original Raspberry Pi - Tom's Hardware
"original" - Google News
https://ift.tt/fZu9V8e
https://ift.tt/0pPRUHr

Bagikan Berita Ini

0 Response to "Using HATs with the Original Raspberry Pi - Tom's Hardware"

Post a Comment


Powered by Blogger.