Skip to content

Instantly share code, notes, and snippets.

@fwhigh
Last active September 23, 2023 04:29
Show Gist options
  • Save fwhigh/92a985dd8c494949a36433641c14e2e6 to your computer and use it in GitHub Desktop.
Save fwhigh/92a985dd8c494949a36433641c14e2e6 to your computer and use it in GitHub Desktop.
Raspberry Pi 4 ssh config
# based on https://www.instructables.com/Portable-Raspberry-Pi-Geiger-Counter-With-Display/
# geiger.py gets data from Mighty Ohm Geiger Counter and writes to a file geiger.dat on Raspberry Pi
import time
import datetime
import string
import signal
import re
import serial
import os
class Geiger:
def __init__(self):
pass
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
f = open(f"{os.environ['HOME']}/geiger.dat", "w")
# ttyS0 for rpi4
# ttyAMA0 for Pi1, Pi2, Pi0
# See https://pimylifeup.com/raspberry-pi-serial/
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)
# 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')
Host <rpi-hostname>.local
HostName <rpi-hostname>.local
User <username>
IdentityFile ~/.ssh/<rpi-ssh-secret-file>
Host *
AddKeysToAgent yes
UseKeychain yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment