Explorer pHat - name not defined


Fairly sure i’m doing something stupid here, but i’m a beginner so pls forgive etc.

I’ve recently bought a pi zero, explorer pHat and explorer hat parts kit. I tried to get a motor running, which didn’t work, so I decided to follow one of your tutorials to check if it was my code or something else which was wrong.
I decided to try the minecraft thermometer (https://learn.pimoroni.com/tutorial/explorer-hat/making-a-minecraft-thermometer).

When I open idle and try to import explorer hat and read from analog one i get this:

>>> import explorerhat
>>> explorerhat.analog.one.read()

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
NameError: name 'explorerhat' is not defined

I have installed the python library using

curl -sS https://get.pimoroni.com/explorerhat | bash

and I have enabled i2c in raspi-config

Do you have any ideas what I could be doing wrong/not doing?


This sounds like the import step in IDLE is failing silently.

Try opening up Terminal, running python and typing import explorerhat straight into the Python REPL it gives you.

Or running: python -c "import explorerhat"

And let me know if you see any sort of error/warning output.

Thanks for the response.

I tried both of those and got:

Warning, could not find Analog or Touch...
Please check your i2c settings!

both times. I’ve double checked that i have i2c enabled in raspi-config.

Could you post a pic of your soldering job both on the zero and phat?

I’m not allowed more than one image in a post as I’m a new user, I hope imgur links are fine? let me know if you want the pictures some other way.

Here are pictures of the (rather shitty) soldering. I know the pi looks like a graveyard, but I have lit an led from every power/output and to every ground pin, so I don’t think that’s an issue.
I also know that soldered the pins the wrong way around, and so the pHat won’t sit over the board, but I am plugging it in the right way so the pins match up.
I did put the pHat on the wrong way around the first time (pins 1 and 2 into 40 and 39 respectively and so on) - is it possible that I damaged it?

Thanks for your help.

I’d expect it not to find the Touch on the pHAT but not the Analog?

For future reference, I’ve upgraded your user account so you can post images ;) (I think)

There’re definitely a couple of suspect joints on the Zero’s header pins. I’m curious as to how you’re connecting this up as the header pins seem a bit backwards?

You should definitely go over each solder joint again. Don’t add any more solder just yet, but heat the joint gently until the solder thats there melts and flows into the hole and covers as much of the little copper ring around each pin as possible.

Solder joints should be little cones, with the backside of the pin poking up.

This is the video that taught me to solder: https://www.youtube.com/watch?v=K5zrgEDsxSQ

Yes. I didn’t learn until 2012 :D

yeah they are backwards, that will teach me to rush stuff :(
and er… yes …
I put the pins in the wrong way, and thought it would be ok because I turned it over… but now I think about it its not ok.
I’m going to try and redo all the soldering on the pHat - hopefully it will work then.

Thanks for everyone’s help! - much appreciated.

Edit: Thanks for the video Gagetoid - ill certainly give that a watch.

note that it’s physically impossible for pins to match in the current state, no matter how you stack the phat and zero.

You could use (male to female) jumper wires however, to link all the desired pins… i2c, power and ground at the minimum, see: http://pinout.xyz/pinout/explorer_phat

Yeah I came to that realization as i read major_tomm’s post - I just hadn’t thought it through as I was doing it. I was going to try and remove the solder - but decided the time I would spend doing it badly wasn’t worth it and ordered a new pHat. Maybe one day when i’m more competent i’ll rescue this one - but i thought it would be best to get it working properly and neatly the first time.

A solder-sucker will make the job a lot easier, then maybe use some solder wick to tidy up after.


Got my new phat and everything works great - thanks to everyone for suggestions, but it was just me being stupid in the end.
I managed to unsolder(?) the other one using some solder wick as well - the board looks a bit messy but it works :)

not sure if you “close” or “solve” threads on these forums or just leave them? I cant see an option but feel free to close it if that’s wagwan.

1 Like