clare_macrae
Posts: 6
Joined: Thu May 17, 2018 3:45 pm

How to detect what HAT is connected

Thu May 17, 2018 3:56 pm

How can I detect what HAT is connected, if any?

Background

I like to be able to detect what HAT is connected, to make a script that runs at start-up launch an appropriate demo script, to show off the hardware...

Some time ago I asked online, and found that the contents of /proc/device-tree/hat/ gave me the information I wanted:
https://raspberrypi.stackexchange.com/q ... 9174#39174

I wrote that info up in a script that allowed me to grab data from several different HATs, and then use that knowledge to detect the attached HAT:
https://github.com/claremacrae/raspi_hat_data

Fast forward to 2018-04-18-raspbian-stretch and that mechanism no longer works. Even when a working HAT is attached, there is no /proc/device-tree/hat/ directory.
https://github.com/claremacrae/raspi_hat_data/issues/1

I read this page, but am none the wiser:
https://github.com/raspberrypi/hats/blo ... /README.md

So where has that info gone now, please?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10924
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How to detect what HAT is connected

Thu May 17, 2018 4:02 pm

All HAT's have an EEPROM which is read, and used to configure the device tree automatically.
This mechanism was added to Raspbian with the launch of HAT's, and has never changed AFAIK.

I only found *this* issue: viewtopic.php?t=206944

A thread about the launch of stretch is here: viewtopic.php?f=63&t=191010 a quick scan though it gives no info about "HAT" or "device tree" issues.

clare_macrae
Posts: 6
Joined: Thu May 17, 2018 3:45 pm

Re: How to detect what HAT is connected

Thu May 17, 2018 4:14 pm

@mahjongg thank you.

I read the post viewtopic.php?t=206944 and it confirms that someone else is reading /proc/device-tree/hat/

Somehow I have a HAT which is connected and working, but not showing up in /proc/device-tree/hat/

I understand that hats have EEPROMS, but not how a user script, e.g. Python, might access data in the EEPROM, when /proc/device-tree/hat/ is absent.

I'd appreciate any pointers/translations of specs.

User avatar
DougieLawson
Posts: 33787
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to detect what HAT is connected

Thu May 17, 2018 4:18 pm

What "HAT" is it? Is it configured to the official RPF HAT specification. Go and ask the maker / vendor / developer.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10924
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How to detect what HAT is connected

Thu May 17, 2018 4:19 pm

The HAT's use a private I2C channel, not the main I2C channel, or the I2C channel used by HDMI.

I think that to read the EEPROM yourself it would require quite some software trickery.
I think the kernel now "owns" the I2C port used for reading the EEPROM in the HAT.

Sorry, I'm not familiar with how it works.

clare_macrae
Posts: 6
Joined: Thu May 17, 2018 3:45 pm

Re: How to detect what HAT is connected

Thu May 17, 2018 4:22 pm

It's Alex Eames' RasPiO Pro Hat.

Good point, I'll try some others that previously I know did put data in /proc/device-tree/hat - see the sub-directories in
https://github.com/claremacrae/raspi_hat_data

clare_macrae
Posts: 6
Joined: Thu May 17, 2018 3:45 pm

Re: How to detect what HAT is connected

Thu May 17, 2018 4:28 pm

Hooray - The Sense HAT works fine, so it may well be a problem with the RasPiO Pro HAT.

Thank you very much for the suggestions!

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10924
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How to detect what HAT is connected

Thu May 17, 2018 4:29 pm

Unfortunately not everything that is sold as a HAT is really a HAT.

For example I foresee a bit of an issue with the "POE HAT", which IMHO should not be designed to block all GPIO's, and should be able to do its job in a combination with a HAT, meaning they cannot both be HAT's.

User avatar
DougieLawson
Posts: 33787
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to detect what HAT is connected

Thu May 17, 2018 4:36 pm

clare_macrae wrote:
Thu May 17, 2018 4:22 pm
It's Alex Eames' RasPiO Pro Hat.

Good point, I'll try some others that previously I know did put data in /proc/device-tree/hat - see the sub-directories in
https://github.com/claremacrae/raspi_hat_data
http://rasp.io/prohat/
That's not a HAT. It's just a simple way to get a small breadboard connected to your RPi.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

clare_macrae
Posts: 6
Joined: Thu May 17, 2018 3:45 pm

Re: How to detect what HAT is connected

Thu May 17, 2018 4:39 pm

Thank you. I took the HAT in the name literally - sorry for the big red herring!

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2810
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: How to detect what HAT is connected

Fri May 18, 2018 3:57 pm

DougieLawson wrote:
Thu May 17, 2018 4:36 pm
clare_macrae wrote:
Thu May 17, 2018 4:22 pm
It's Alex Eames' RasPiO Pro Hat.

Good point, I'll try some others that previously I know did put data in /proc/device-tree/hat - see the sub-directories in
https://github.com/claremacrae/raspi_hat_data
http://rasp.io/prohat/
That's not a HAT. It's just a simple way to get a small breadboard connected to your RPi.
Actually it IS a HAT and would fully meet the HAT spec if the EEPROM was programmed. :oops:
Alex Eames RasPi.TV, RasP.iO

User avatar
DougieLawson
Posts: 33787
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to detect what HAT is connected

Fri May 18, 2018 4:02 pm

alexeames wrote:
Fri May 18, 2018 3:57 pm
Actually it IS a HAT and would fully meet the HAT spec if the EEPROM was programmed. :oops:
So it's an out-of-spec HAT.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2810
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: How to detect what HAT is connected

Sat May 19, 2018 8:39 am

DougieLawson wrote:
Fri May 18, 2018 4:02 pm
So it's an out-of-spec HAT.
Indeed, but only in software. It can easily be brought into spec. by pulling GPIO26 LOW and flashing the EEPROM.

In fact many popular HATs are 'out of spec'. One very large and popular company does a prototyping HAT with 'optional EEPROM'.
Another very, very popular company routinely uses headers that are much lower profile than the 8mm minimum specified.
They are out of spec in hardware.

But the bottom line is that very few people think it matters (proven by the fact that only 2 people have ever asked me about it - including this thread). With a board as simple as the Pro Hat there is little gained by programming the EEPROM as no pre-configuration is necessary, since it's a completely blank canvas.
Alex Eames RasPi.TV, RasP.iO

User avatar
DougieLawson
Posts: 33787
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to detect what HAT is connected

Sat May 19, 2018 10:06 am

alexeames wrote:
Sat May 19, 2018 8:39 am
But the bottom line is that very few people think it matters (proven by the fact that only 2 people have ever asked me about it - including this thread). With a board as simple as the Pro Hat there is little gained by programming the EEPROM as no pre-configuration is necessary, since it's a completely blank canvas.
And that is the answer for the OP. Because it needs no special device tree configuration you simply can't tell that it is connected because the eeprom is an unwritten lump.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

hippy
Posts: 3771
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How to detect what HAT is connected

Sat May 19, 2018 10:50 am

alexeames wrote:
Sat May 19, 2018 8:39 am
With a board as simple as the Pro Hat there is little gained by programming the EEPROM as no pre-configuration is necessary, since it's a completely blank canvas.
I would suggest the EEPROM should be programmed with default data which identifies it as a HAT which doesn't configure any GPIO.

That accurately reflects what the HAT is (as delivered), identifies what it is and that it is fitted (when it is), and what configuration it does (none).

I guess it depends on whether one thinks the HAT ID mechanism is purely intended to configure GPIO or also a means to identify the HAT fitted.

I suspect in this case it had not been appreciated that there is something to be gained for some from being able to identify which HAT is fitted even if it requires no GPIO configuration.

The HAT spec is just for convenience and a useful means of providing for the Device Tree mechanism. It has no legal authority, is not enforceable, compliance with it cannot be enforced and non-conformance cannot be punished, compliance is only voluntary.

For the good of everyone it helps if people do stick to the specification but they don't have to.

I haven't seen any evidence that the Foundation's POE HAT meets the HAT spec or does not but, if it doesn't, I think it is a very poor way to lead by example. I believe it should either be made HAT compliant, given some other name, or the HAT spec must be updated.

clare_macrae
Posts: 6
Joined: Thu May 17, 2018 3:45 pm

Re: How to detect what HAT is connected

Wed May 23, 2018 9:58 pm

Thank you for the replies everybody. I learned a lot.

Return to “Add-ons”

Who is online

Users browsing this forum: No registered users and 2 guests