Connect geiger counter with USB FTDI to an OpenWRT router, print data on I2C LCD and send data to radmon.org

#1

I've just wrote a How-To about connectiong a Geiger counter to an OpenWRT router, display current radiation value on an I2C LDC display and optionally send the data to radmon.org

see here the entire story:

ADDON:

this is my python script modificated to add the radiaton value (pulse per minute) on the I2C LCD display (see my previous posts about how to connect an I2C LCD and DHT temperature/humidity sensor to OpenWrt)

prerequisites: read the link indicated above

import smbus
import I2C_LCD_driver
import time
import sys
import commands
import locale

from subprocess import check_output
from shlex import split
locale.setlocale(locale.LC_ALL, "us_US")
mylcd = I2C_LCD_driver.lcd()

mylcd.lcd_clear()

while True:
 DEVICE     = 0x5C #device address
 bus = smbus.SMBus(0)  # Rev 2 Pi uses 1

 def readdata(addr=DEVICE):

  #read 5 bytes of data from the device address (0x05C) starting from an offset of zero
  data = bus.read_i2c_block_data(addr,0x00, 5)

  umid=("Humidity: " + str(data[0]) + "." + str(data[1]) + "%")
  temp= ("Temperature: " + str(data[2]) + "." + str(data[3]) + "C")
 
  #print (umid)
  #print (temp)
 
  #if (data[0] + data[1] + data[2] + data[3] ==  data[4]):
  #  print "checksum is correct"
  #else:
  #  print "checksum is incorrect, data error"

  in_file = open("/tmp/cpm.txt", "rt") # open file cpm.txt for reading text data
  contents = in_file.read()            # read the entire file into a string variable
  in_file.close()                      # close the file
  #print(contents)
  radiation = ("Gamma CPM: " + contents.rstrip("\n"))
  
  mylcd.lcd_display_string(temp, 1)
  mylcd.lcd_display_string(umid, 2)
  mylcd.lcd_display_string(radiation, 3)
  mylcd.lcd_display_string("%s" %time.strftime("%a %H:%M" " " "%d/%m/%Y"), 4)
 
  time.sleep(15)

 if __name__=="__main__":
    readdata()
0 Likes

#2

To get uSv/h value from CPM file (last reading data):

sed 's/$/ * .0057/' /tmp/cpm.txt | bc | awk '{printf("%.2f\n", $1)}'

note: 0.0057 is the conversion factor (CPM to uSv/h) for the SBM-20 Geiger tube I'm using, uSv/h value is rounded to the second decimal place.

so, to generate uSv/h value for LCD display printing:

/bin/sed 's/$/ * .0057/' /tmp/cpm.txt | /usr/bin/bc | /usr/bin/awk '{printf("%.2f\n", $1)}' > /tmp/usvh.txt

0 Likes