Introduction: Portable Raspberry Pi Geiger Counter With Display
Mighty Ohm Geiger Counter is a stand-alone do-it-yourself kit. When the MightyOhm detects a particle it beeps. This is an integration project. Several sub-projects are need to complete this project. The end result is a Mighty Ohm Geiger Counter connected to a Raspberry Pi with a small display and portable power source.
Step 10 has an image of the completed project.
The Mighty Ohm Geiger Counter doesn't need an instructable. Mighty Ohm's documentation is great. The end result is impressive. This is a fairly complex project and requires soldering components. My soldering skills are poor. So, I was hesitant to take on this project until I found a great instructable on soldering.
The goals of this project are to:
- Build Mighty Ohm Geiger Counter
- Setup Raspberry Pi using PiTFT version of raspbian
- Add a 2.8 inch PiTFT display to Raspberry Pi
- Add portable rechargeable power source to Raspberry Pi
- Connect Raspberry Pi to Mighty Ohm
- Add display software to Raspberry Pi
I use a MacBook Pro to communicate with the Raspberry Pi, but any computer can be used.
My son teaches 7th through 12th grade science and wants to start a guest lecture series. He asked me to teach a one hour course. I was stumped on a subject until I ran across the Mighty Ohm. I am surprised by intelligent people who don't understand the difference between ionizing radiation, which can cause genetic mutations leading to cancer, and other types of radiation, such as, from the earth's magnetic field, your cell phone, or microwave oven that to date have not been shown to cause genetic mutation or cancer.
The slides are in PowerPoint and are stored here.
Notes:
- text enclosed in spades, like this ♣replace-this♣ should be replaced with an actual value
- I’ve attempted to credit every source used. My apologies for any omissions.
- $ indicates a command executed in a terminal window on the MacBook and usually is being executed on the Raspberry Pi
Attachments
Step 1: Gather Parts
I have found the parts below perform best in my applications. These parts are more expensive than contained in the usual starter kit.
This is one of my more expensive instructables. It is definitely cheaper to buy a Geiger Counter than to build one. But this was fun.
Get parts and tools (prices in USD):
- MacBook Pro (a PC can be used)
- Ethernet cable, router, wireless access point and internet connection
- Small hard steel scissors for clipping leads
- Raspberry Pi:
- Raspberry Pi 2 Model B Element14 $35
- Panda 300n WiFi Adapter Amazon $16.99
- 5.2V 2.1A USB Power Adapter from Amazon $5.99 - temporary
- Micro USB to USB cable 3ft from Amazon $4.69
- FTDI TTL-232R-RPI Serial to USB cable from Mouser $15
- SanDisk Ultra 16 GB microSDHC Class 10 with Adapter (SDSQUAN-016G-G4A) from Amazon $8.99
- PiTFT - Assembled 320x240 2.8" TFT+Touchscreen for Raspberry Pi Adafruit $34.95
- 20 pack tactile buttons Adafruit $4.95
- Mighty Ohm Geiger Counter:
- Mighty Ohm Geiger Counter Kit from MightyOhm $99.99
- Lead Free Silver Solder (21 gauge, 0.032" diam) from Fry's $4.69
- Weller WLC100 Solder Station from Fry's $45.00 (only need stand and iron - doesn't need to be variable)
- Deoxit Tip Tinner from Fry's $7.99
- "Swarf" Tip Cleaner from Fry's $9.79
- Two AAA Batteries from my battery drawer (4 from Fry's $3.99) - temporary
- bag of female-female jumper leads (less than $10)
- Mobile Phone Recharging battery 5v 1A 7,000mAh. I have one. On Amazon these are about $17.
- Case:
- Sheet of 3/16in plexiglass (22in by 20in) from Home Depot $22.00
- Measuring tape, needle nose pliers, small pliers, tin snips
- Exacto knife, Sharpie
- Drill with 1/2in and 1/8in drill bits (I use metal drill bits)
- Table saw (or jigsaw - again I use metal saws to cut plastic - they have smaller teeth and make a finer cut)
- #4-40 (or metric M3) machine screws and hex standoffs in various lengths. The thickness of the plexiglass and the standoffs add strength to the case. I don't think plastic offsets would work.
- Hand clamp
Step 2: Build Mighty Ohm Geiger Counter
I have a couple of challenges when it comes to electronics.
My soldering skills were terrible. So, I gave up trying to solder 20+ years ago. This instructable addressed all of my issues: How to solder - the secrets of good soldering. So, I thought I would give it another try.
The image above shows that I am still not great - a few burn marks, but I don't have blobs of solder and shorts that characterized my early work. Some of the soldering actually looks professional!
These tips were key to doing a better soldering job: use a tinning can to keep the tip shiny, bend the leads to keep the components in place and use swarf instead of a sponge to keep the tip shiny.
If I were to do this over again, I would get a small solder protoboard and a bag full of resistors and practice using the secrets of good soldering instructable as my guide. Once all my solder joints were good, then I would start on soldering the board.
My other challenge is I am color-blind. So, reading the color bands on resistors is always problematic. I had my wife sort them out for me.
The mighty ohm geiger counter kit instructions are here. The instructions are easy to follow.
I spent a few days playing with the geiger counter. I found it interesting the amount of radiation put off by my granite counter tops.
Step 3: Setup Raspberry Pi and Install PiTFT Display
Use this instructable to set up the Raspberry Pi and install the PiTFT display.
- Note: Updated Adafruit setup.
Step 4: PiTFT Jumper Block
The Raspberry Pi pins have pin numbers and GPIO numbers. Even numbered pins run along the edge of the Raspberry Pi board. Pins 1 and 2 are on the adjacent edge.
The PiTFT display uses the following Raspberry Pi pins:
- SCK (pin 23)
- MOSI (pin 19)
- MISO (pin21)
- CE0 (pin 24)
- CE1 (pin 26)
- GPIO #25 (pin 22)
- GPIO #24 (pin 18)
All other GPIO are unused. Some of these unused pins will connect the Raspberry Pi to the Mighty Ohm using a jumper block on the back of PiTFT display.
Using the image above, the pins on the PiTFT jumper are numbered the same as the pins on the Raspberry Pi.
This instructable is using Raspberry Pi 2, but the PiTFT uses the Raspberry Pi Model B++ pins. This isn't an issue, just an explanation why the number of pins don't match.
Step 5: Connect Mighty Ohm to Raspberry Pi
Remove Batteries from Mighty Ohm. Put the power switch in the off position.
Shutdown the Raspberry Pi and remove the power cord.
Gently remove PiTFT display from Raspberry Pi.
On the Mighty Ohm a black triangle indicates pin 1.
Using female jumper leads connect the PiTFT to the Mighty Ohm as follows:
Ground: Mighty Ohm Pulse pin 1 connects to PiTFT pin 14
3.3v: Mighty Ohm Pulse pin 3 connects to PiTFT pin 1
Ground: Mighty Ohm Serial pin 1 connects to PiTFT pin 6
TxData: Mighty Ohm Serial pin 4 connects to PiTFT pin 8
RxData: Mighty Ohm Serial pin 5 connects to PiTFT pin 10
Gently push the PiTFT display back in to the Raspberry Pi.
Ensure the batteries are removed from the mighty Ohm.
Plug in power to the Raspberry Pi.
Step 6: Pass Geiger Counter Data to Raspberry Pi
I like using python for my scripts. Install python3
$ sudo apt-get update $ sudo apt-get install python3
Login to Raspberry Pi. Open a terminal window on MacBook and run the command:
$ ssh pi♣geiger-counter-ip-address♣ $ sudo nano geiger.py
Create this python script in /home/pi. It basically writes the data to a file that can be used by gnuplot.
#!/usr/bin/python3 # geiger.py gets data from Mighty Ohm Geiger Counter and writes to a file on Raspberry Pi # edit crontab # $ sudo crontab -e # and add the following line at the end - this can also be done in init.d # @reboot sudo /usr/bin/python3 /home/pi/geiger.py 2>&1 # # Future: gnuplot requires a static file (so tail -100 or something to get rolling data) import time import datetime import string import signal import re import serial class Geiger: def __init__(self): # filler - I meant to (or may add more in init self.host = '192.168.1.92' def readLine(self, port): r = "" while True: byte = port.read() c = byte.decode("utf-8") if c=='\n' or c=='\r' or c=='': return r else: r += c if __name__ == '__main__': try: g = Geiger() c = 0 # on each use restart the file f = open("/home/pi/geiger.dat", "w") port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=1) # Don't need column headers # f.write("count CPS CPM uSv/hr\r\n") while True: r = g.readLine(port) if r != '': words = r.split(",") l = len(words) if l == 7: # data should come back in the form # CPS, n, CPM n, uSv/hr n, SPEED # for debug: # f.write('input = ' + r + '\r\n') f.write(str(c) + words[1] + words[3] + words[5] + '\r\n') f.flush() c += 1 except KeyboardInterrupt: f.close() print('closing script through ctrl-c')
On PiTFT display, start a terminal window
Start the geiger.py script running, but don't wait for it to finish (the "&" tells the command to start without waiting for it to finish)
$ python3 geiger.py & [1] 1010
If you need to stop the script use kill pid, or in the case above.
$ sudo kill 1010
You can run the following command to ensure data is being written to geiger.dat
$ cat geiger.dat
Step 7: Portable Power Supply
A Geiger Counter isn't very useful if it must be plugged in to an electrical outlet. You want to carry it around and take measurements.
I read several webpages and believed making the Raspberry Pi Geiger Counter use a portable power supply was going to be difficult. I estimated it would take 2-3 days depending on the approach. However, I simply over thought the problem.
I have a 7,000mAh (milli-Amperes per hour) cellphone recharging battery, which outputs 5v at 1A. So, it is perfect for driving the Raspberry Pi and Mighty Ohm.
Use a short USB to microUSB to connect the charger to the Raspberry Pi and everything works.
Easy-peasy.
Step 8: Display Data
Most commercial geiger counters show Counts per Second (CPS) or Count per Minute (CPM) and micro Sievert's per hour (uSv/hr). CPM seems to be the most intuitive plot. Since I added a PiTFT, I wanted to be able to plot the data overtime.
Install gnuplot
$ sudo apt-get install gnuplot-x11
Create a gnuplot script (gps extension) to display the data
$ sudo nano geiger.gps
The X-axis sin't really Time. Edit the file to look like:
# gnuplout script for geiger counter set terminal x11 1 noraise set title "Geiger Counter" set xlabel "Time" set ylabel "CPM" set size .95,.95 plot '/home/pi/geiger.dat' using 1:3 while (1) { replot pause 10 }
The gnuplot documentation is quite detailed. Play with different settings in gnuplot until they meet your needs.
Edit the LXterminal autostart so gnuplot starts on boot (source):
$ sudo nano ~/.config/lxsession/LXDE-pi/autostart
at the end of the file add the following line:
@/usr/bin/gnuplot /home/pi/geiger.gps
Step 9: Push Buttons
Push buttons make the Geiger Counter much easier to use.
Push buttons
Before installing the PiTFT, solder on four push buttons. #18 will be used for Power On and Off. There is no need to run wires to the GPIO pins, because the PiTFT board makes the connections.
On the Raspberry Pi 2, the pins for the two push buttons (#23 and #22) over the Ethernet jack touch the metal housing of the jack. I clipped a small piece of plastic from one of the offset or screw packages and slid it between the ethernet jack and the pins and then taped it in place.
#27 and #22 are not used, but may be used in the future.
Power Button
Normally, you turn off your Pi with:
$ sudo shutdown -h now
The kernel used in this instructable allows any GPIO to be a power button (toggle on and off).
Open a terminal window and login into Geiger Counter
$ ssh pi@♣geiger-counter-ip-address♣ $ sudo nano /etc/modules
Check if the following line is in the file, if not add it
rpi_power_switch
Save the file
CTRL-o ENTER CTRL-x
Edit the config file
$ sudo nano /etc/modprobe.d/adafruit.conf
and add the line
options rpi_power_switch gpio_pin=18 mode=0
Save the file
CTRL-o ENTER CTRL-x
To make the power button active
$ sudo reboot
Backlight Button
The backlight on the display draws 75mA. To conserve battery power, you may want to turn off the backlight. Open a terminal window and login into Geiger Counter
$ ssh pi@♣geiger-counter-ip-address♣ $ sudo nano buttons.py
Use either 508 or 252, depending on the version. The code below is adapted from the Average Man website.
GPIO18 could be added to the script below. #18 will shutdown the Raspberry Pi, but won't turn it back on. The kernel call above is needed for this.
Note: copying and pasting might cause issues with the greater than symbol, which is changed to "& gt ;" with no spaces. And, double quotes might change to italicized quotes.
#!/usr/bin/python import RPi.GPIO as GPIO import time import os # Set GPIO mode GPIO.setmode(GPIO.BCM) # Setup GPIO GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set up backlight GPIO os.system("sudo sh -c 'echo 508 > /sys/class/gpio/export'") # Give the system a quick break time.sleep(0.5) # Set the intitial counter to zero counter = 0 # var for the 'while' statement to keep it running var = 1 # Main program while var == 1: if (GPIO.input(23) == False): # Backlight control if (counter == 0): os.system("sudo sh -c 'echo 'out' > /sys/class/gpio/gpio508/direction'") counter = 1 print("counter now 1") time.sleep(0.5) elif (counter == 1) or (counter == 3): os.system("sudo sh -c 'echo '1' > /sys/class/gpio/gpio508/value'") counter = 2 print("counter now 2") time.sleep(0.5) elif (counter == 2): os.system("sudo sh -c 'echo '0' > /sys/class/gpio/gpio508/value'") counter = 3 print("counter now 3") time.sleep(0.5) if (GPIO.input(22) == False): os.system("/usr/bin/perl /home/pi/geiger.pl") time.sleep(0.5) if (GPIO.input(27) == False): print("27 working") time.sleep(0.5) GPIO.cleanup()
Save the file
CTRL-o ENTER CTRL-x
Start the script on boot by adding a crontab
$ sudo crontab -e
and add the button script and the geiger counter collection script
@reboot sudo /usr/bin/python3 /home/pi/buttons.py >/dev/null 2>&1 & @reboot /usr/bin/python3 /home/pi/geiger.py >/dev/null 2>&1
save the file
CTRL-o ENTER CTRL-x
Step 10: Create Plexiglass Case
This instructable shows how to build the best looking case for a Geiger Counter. However, I wanted a plexiglass case.
Make sure all the components are turned off and disconnected.
Using a table saw cut two or three sheets of plexiglass that are 11in by 3 1/4in. The cover sheet is optional.
Layout the components. I put
- Battery charger on bottom sheet, and
- Raspberry Pi and Mighty Ohm on middle sheet, and
- nothing on the top sheet (protective cover with hole for touch screen)
Each board has connecting holes. After laying out components, use Sharpie to mark holes on plexiglass.
Clamp plexiglass to a piece of scrap wood and drill through plexiglass into wood.
DANGER. I opened the battery recharger, by gently prying the plastic off the back side and then gently pushed the contents out of the aluminum case. The battery contains a lithium pack. I am not sure removing the battery from its case is a good idea and it may be dangerous. If you decide to do this be very careful.
The lithium is contained in a thin film. Do no puncture the film. I removed the tape holding the lithium pack. The battery and electronics are in a plastic base. I laid out the battery where I wanted it on the plexiglass, and then clamped it in place to the bottom sheet of plexiglass. I then gently lifted the battery and drilled two 1/8in holes holes in the batteries plastic holder and through the bottom sheet of plexiglass. I then put screws through the holes, put the battery back in places, and replaced the tape to hold the lithium pack in place.
An alternative to the above would be to use clips to hold the battery pack in place.
To get it right, I put the parts together and took them apart multiple times. Putting it together and taking it apart allowed me to get it right.
As part of putting the parts together, I laid out the components, and marked where the holes were to be drilled in the plexiglass. Since the components and holes span multiple levels, it is important to get it right. Once everything lined up, I drilled the holes.
I connected the parts with 1/4in and 1/2in hex nuts. I got the hex nuts at Fry's. It is probably best to buy the hex nuts on line, since the stock at Fry's is usually depleted and too expensive.
A heavy duty snipping tool comes in handy. I could not find #4-40 machine screws that were the right length. I ended up cutting them to the proper length with my tin snip.
Connect everything together and you are done!
Step 11: Appendix: References
Various explanations of how the geiger tube works
https://www.cooking-hacks.com/documentation/tutor...
http://www.explainthatstuff.com/how-geiger-counter...
https://en.wikipedia.org/wiki/Geiger_counter
References
https://www.instructables.com/id/Homemade-Geiger-Co...
How to teach radioactivity to children
Instructable: How to X-ray - excellent explanation of radiation
Mighty Ohm forum topic serial communication
Pigi https://apollo.open-resource.org/lab:pigi
PiTFT Tutorial - much of this can be skipped because this instructable uses the PiTFT dist
gnuplot homepage
Step 12: Appendix: Updates
14FEB2016
- Original version
19MAR2016
- Added push buttons for backlight and Raspberry Pi power toggle.
- Fixed instructable page that got corrupted (?).
- Updated code.
- Added gnuplot to automatically start on reboot using lxterminal.
- Added photo for CPM display.
- Added this page
- Created git repository with PowerPoint slides and added link