Nathan.Rivard
Posts: 37
Joined: Tue Sep 10, 2019 3:28 pm

Random Crashing with no Discernable Reason

Wed Oct 09, 2019 4:12 pm

I have a 3B+ that has multiple pin connections and I am attempting it to run a python file 24 hours a day 5 days a week. My issue is that after about 8 hours of logging data and writing that data onto a .csv file, the thing always crashes. The longest I have had without a crash was 10 hours and the shortest time was 30 min. I am using the official power supply and whenever I am checking my memory usage I am only using about 1/9th of the ram and the CPU usage maxes out at 12%. What's going on?

User avatar
rpiMike
Posts: 1308
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Random Crashing with no Discernable Reason

Wed Oct 09, 2019 4:15 pm

Post your code.

Nathan.Rivard
Posts: 37
Joined: Tue Sep 10, 2019 3:28 pm

Re: Random Crashing with no Discernable Reason

Wed Oct 09, 2019 6:09 pm

Code: Select all

import smbus
bus = smbus.SMBus()
#bus=smbus.SMBus(0)
import sys
sys.path.append('../')
#/home/pi/Desktop/pH_Files_and_Data/DFRobot_PH_Read.py
address=0x48
import time
ADS1115_REG_CONFIG_PGA_6_144V        = 0x00 # 6.144V range = Gain 2/3
ADS1115_REG_CONFIG_PGA_4_096V        = 0x02 # 4.096V range = Gain 1
ADS1115_REG_CONFIG_PGA_2_048V        = 0x04 # 2.048V range = Gain 2 (default)
ADS1115_REG_CONFIG_PGA_1_024V        = 0x06 # 1.024V range = Gain 4
ADS1115_REG_CONFIG_PGA_0_512V        = 0x08 # 0.512V range = Gain 8
ADS1115_REG_CONFIG_PGA_0_256V        = 0x0A # 0.256V range = Gain 16

from DFRobot_ADS1115 import ADS1115
from DFRobot_PH import DFRobot_PH

ads1115 = ADS1115()
ph      = DFRobot_PH()

ph.begin()
while True :
	#Read your temperature sensor to execute temperature compensation
    temperature = 25
	#Set the IIC address
    ads1115.setAddr_ADS1115(0x48)
	#Sets the gain and input voltage range.
    ads1115.setGain(ADS1115_REG_CONFIG_PGA_6_144V)
	#Get the Digital Value of Analog of selected channel
    adc0 = ads1115.readVoltage(0)
	#Convert voltage to PH with temperature compensation
    PH = ph.readPH(adc0['r'],temperature)

    VoltageArray = [4090, 3912, 3732, 3554, 3440, 3330, 3215]
    PHArray = [4, 5, 6, 7, 8, 9, 10]
    VoltageRead = adc0['r']
    xold = VoltageArray[0]

    for x in VoltageArray:
        xnew = x
        if(xold > VoltageRead > xnew):
            VoltageHigh = xold
            VoltageHighIndex = VoltageArray.index(VoltageHigh)

            VoltageLow = xnew
            VoltageLowIndex = VoltageArray.index(VoltageLow)

            break
        else:
            xold = x

    PHHigh = PHArray[VoltageHighIndex]
    PHLow = PHArray[VoltageLowIndex]
    phval = (((VoltageRead-VoltageLow)*(PHHigh-PHLow))/(VoltageHigh-VoltageLow))+PHLow

	#print "Temperature:%.1f ^C PH:%.2f" %(temperature,PH)
    #PH = abs(PH)
    #print("PH: " + str(PH))
    #print("A0:" + str(adc0['r']) + "mV")
    #print("phval: " + str(phval))
    #from os.path import join as pjoin
    #filename = "ph.csv"
    #path_to_file = pjoin("/media/pi/PHDATA/Ph_Data_Type/ph.csv" , "ph.csv")
    #File = open("/media/pi/PHDATA/Ph_Data_Type/ph.csv" , 'a')
    #File.write(str(time.asctime(time.localtime())) + "," + str(phval) + "," + str(adc0['r']) + "\n")
    #File.close()
    ph_file = open("ph.csv", 'a')
    ph_file.write(str(time.asctime(time.localtime())) + "," + str(phval) + "," + str(adc0['r']) + "\n")
    ph_file.close()

    time.sleep(60)

User avatar
rpiMike
Posts: 1308
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Random Crashing with no Discernable Reason

Wed Oct 09, 2019 6:18 pm

Do you get an error when it crashes? If so what error?

Nathan.Rivard
Posts: 37
Joined: Tue Sep 10, 2019 3:28 pm

Re: Random Crashing with no Discernable Reason

Wed Oct 09, 2019 7:47 pm

rpiMike wrote:
Wed Oct 09, 2019 6:18 pm
Do you get an error when it crashes? If so what error?
I was actually just writing a program on it, nothing running, and it crashed again

User avatar
rpiMike
Posts: 1308
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Random Crashing with no Discernable Reason

Wed Oct 09, 2019 8:09 pm

Doesn't sound like your program then. Do you have any loose connections? What temperature is your Pi reaching? What happens when it crashes?

Are you running the latest Raspbian Buster fully updated?

Nathan.Rivard
Posts: 37
Joined: Tue Sep 10, 2019 3:28 pm

Re: Random Crashing with no Discernable Reason

Thu Oct 10, 2019 3:11 pm

rpiMike wrote:
Wed Oct 09, 2019 8:09 pm
Doesn't sound like your program then. Do you have any loose connections? What temperature is your Pi reaching? What happens when it crashes?

Are you running the latest Raspbian Buster fully updated?
I am running the latest version of Raspbian as far as I know, should I go ahead and update and upgrade? Also, I have not checked the temp on it, is this something I need to measure physically or does the temp write to some log?

User avatar
rpiMike
Posts: 1308
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Random Crashing with no Discernable Reason

Thu Oct 10, 2019 3:17 pm

Yes, update and upgrade. Make sure code is backed up.

Code: Select all

sudo apt update
sudo apt upgrade -y
If your running the desktop you can add a temperature panel to the task bar.

Or from a command line:

Code: Select all

vcgencmd measure_temp

Return to “Troubleshooting”