I slightly modified the example right out of the examples that reads the sensor and prints it to the screen. After making some number of reads, it stops responding and how long that takes is somewhat random. I tried changing the wait time from 0.5 second to 15 seconds, and really the results is about the same both ways.
I tried adding a catch-all clause to the except section in case there is an exception that I’m not calling out specifically, but that branch never prints out.
It prints out the correct temperature from 8 to 36 times, then stops printing. Ctrl-C cleanly terminates and is caught by the exeception block.
I need this to run forever with no hangs. Any ideas?
Here is the code.
#!/usr/bin/env python
GrovePi Example for using the Grove Temperature Sensor (http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor)
The GrovePi connects the Raspberry Pi and Grove sensors. You can learn more about GrovePi here: http://www.dexterindustries.com/GrovePi
Have a question about this example? Ask on the forums here: http://forum.dexterindustries.com/c/grovepi
‘’’
License
The MIT License (MIT)
GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi.
Copyright © 2017 Dexter Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
‘’’
NOTE:
The sensor uses a thermistor to detect ambient temperature.
The resistance of a thermistor will increase when the ambient temperature decreases.
There are 3 revisions 1.0, 1.1 and 1.2, each using a different model thermistor.
Each thermistor datasheet specifies a unique Nominal B-Constant which is used in the calculation forumla.
The second argument in the grovepi.temp() method defines which board version you have connected.
Defaults to ‘1.0’. eg.
temp = grovepi.temp(sensor) # B value = 3975
temp = grovepi.temp(sensor,‘1.1’) # B value = 4250
temp = grovepi.temp(sensor,‘1.2’) # B value = 4250
import time
import grovepi
Connect the Grove Temperature Sensor to analog port A0
SIG,NC,VCC,GND
sensor = 0
while True:
try:
temp = grovepi.temp(sensor,‘1.2’)
except KeyboardInterrupt:
break
except IOError:
print (“Error”)
except:
print(“Exception reading sensor…what do we do?”)
ftemp=(temp*9/5) + 32
now=time.strftime("%H:%M:%S")
print(‘Time = %s Celsius = %.2f Fahrenheit %0.2f’ %(now,temp,ftemp))
time.sleep(15)
print("")
print("^C hit")
stime=time.strftime("%H:%M:%S")
print(“Done at:”,stime)
Here is the log from running the troubleshooting scripts.
Check space left
Filesystem Size Used Avail Use% Mounted on
/dev/root 59G 3.5G 53G 7% /
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.9G 16K 1.9G 1% /dev/shm
tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 52M 202M 21% /boot
tmpfs 386M 0 386M 0% /run/user/1000
Check for dependencies
python 2.7.16-1 install ok installed
python-pip 18.1-5+rpt1 install ok installed
git 1:2.20.1-2+deb10u3 install ok installed
libi2c-dev 4.1-1 install ok installed
python-serial 3.4-4 install ok installed
python-rpi.gpio 0.7.0-0.1~bpo10+1 install ok installed
i2c-tools 4.1-1 install ok installed
python-smbus 4.1-1 install ok installed
dpkg-query: no packages found matching arduino
dpkg-query: no packages found matching minicom
scratch 1.4.0.6~dfsg1-6 install ok installed
find: ‘/run/user/1000/gvfs’: Permission denied
wiringPi Not Found (ERR)
find: ‘/run/user/1000/gvfs’: Permission denied
I2C still in blacklist (ERR)
SPI still in blacklist (ERR)
Check for addition in /modules
I2C-dev already there
i2c-bcm2708 already there
spi-dev already there
Hardware revision
gpio version: 2.50
Copyright © 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty
Raspberry Pi Details:
Type: Unknown17, Revision: 02, Memory: 0MB, Maker: Sony
- Device tree is enabled.
*–> Raspberry Pi 4 Model B Rev 1.2 - This Raspberry Pi supports user-level GPIO access.
Check the /dev folder
i2c-1
ttyAMA0
USB device status
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 003: ID 04ca:003a Lite-On Technology Corp.
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 1: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 4: Dev 4, If 1, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 4: Dev 4, If 2, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 4: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 12M
Raspbian for Robots Version
cat: /home/pi/di_update/Raspbian_For_Robots/Version: No such file or directory
Hostname
pi-4
Checking for Atmega chip
avrdude: Version 5.10, compiled on Jun 18 2012 at 12:38:29
Copyright © 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright © 2007-2009 Joerg Wunsch
System wide configuration file is "/etc/avrdude.conf"
User configuration file is "/home/pi/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : unknown
Using Programmer : gpio
AVR Part : ATMEGA328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 5 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : GPIO
Description : Use sysfs interface to bitbang GPIO lines
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK
avrdude done. Thank you.
Checking I2C bus for devices
Checking I2C bus 0
Error: Could not open file /dev/i2c-0' or
/dev/i2c/0’: No such file or directory
Checking I2C bus 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – 04 – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --
Checking for firmware version
GrovePi has firmware version: 1.4.0