1

I am very new to Pi, Python, and this kind of programming, as a whole.

I am building a data logger. Once completed, it will be deployed in areas with no internet connectivity. So I chose to create the build based on Widgetlords Real Time Clock Interface, Analog Input Interface and Digital Input Interface. There is an issue with the real time clock (I am working with VP Process to resolve it), therefore; I am having to enter the date and time manually. Once deployed, I want to ensure that the time and date are set before starting to collect data, so I added an input at the beginning of the script to ask for the date and time, and then set the time based on that.

#Set System Time and Date
Real_Date = input('Please enter date (ex. 10/15/2018)')
Real_Time = input('Please enter time (ex. 09:57:00)')

os.system("sudo date -s '%s %s'" % (Real_Date, Real_Time))

This portion of the script works properly. When I execute the script, it asks for the date. Once entered, it asks for the time. Once entered, you can see the time and date adjust to what was input.

However, after executing this part of the script, it does not move on to the rest of the code. It just stops there.

Here is a little more of the code so you can see the context.

import os
from time import sleep
import time
from widgetlords.pi_spi_din import *
from widgetlords import *

#Set System Time and Date
Real_Date = input('Please enter date (ex. 10/15/2018)')
Real_Time = input('Please enter time (ex. 09:57:00)')

os.system("sudo date -s '%s %s'" % (Real_Date, Real_Time))

init()
inputs = Mod8AI(ChipEnable.CE1)
inputs = Mod8DI(ChipEnable.CE2)

while True:

    #Time - ts = Timestamp, rt = Real Time
    ts = time.time()
    rt = time.ctime(ts)

    #Data Logging Files - Amp_File (Current Transducer Log), Pressure_File     (Pressure Tranducer Log)
    Amp_File = open("/home/pi/Documents/Amp_File.txt", "a")
    Pressure_File = open("/home/pi/Documents/Pressure_File.txt", "a")

What am I missing that is not allowing the code to continue to execute after the command line sequence has completed?

Here is the entire revised code so far I added a couple of print lines just to see if the script was hanging up before or after the init() statement. FYI....before.

import os
from time import sleep
import time
from widgetlords.pi_spi_din import *
from widgetlords import *

#Set System Time and Date
Real_Date = input('Please enter date (ex. 10/15/2018)')
Real_Time = input('Please enter time (ex. 09:57:00)')

os.system('sudo date -s "%s %s"' % (Real_Date, Real_Time))

print("")
print('Real Date is %s' % (Real_Date))
print('Real Time is %s' % (Real_Time))
print("")

init()
Analog_inputs = Mod8AI(ChipEnable.CE1)
Digital_inputs = Mod8DI(ChipEnable.CE2)

while True:

    #Time - ts = Timestamp, rt = Real Time
    ts = time.time()
    rt = time.ctime(ts)

    #Data Logging Files - Amp_File (Current Transducer Log), Pressure_File     (Pressure Tranducer Log)
    Amp_File = open("/home/pi/Documents/Amp_File.txt", "a")
    Pressure_File = open("/home/pi/Documents/Pressure_File.txt", "a")

    #Read Analog Inputs From Pi-SPi-DIN-8AI
    A1 = Analog_inputs.read_single(0)
    A2 = Analog_inputs.read_single(1)
    A3 = Analog_inputs.read_single(2)
    #A4 = Analog_inputs.read_single(3)
    #A5 = Analog_inputs.read_single(4)
    A6 = Analog_inputs.read_single(5)
    A7 = Analog_inputs.read_single(6)
    A8 = Analog_inputs.read_single(7)

    #Read Digital Inputs From Pi-SPi-DIN-8DI
    D1 = Digital_inputs.read_single(0)
    D2 = Digital_inputs.read_single(1)
    D3 = Digital_inputs.read_single(2)
    D4 = Digital_inputs.read_single(3)
    D5 = Digital_inputs.read_single(4)
    D6 = Digital_inputs.read_single(5)
    D7 = Digital_inputs.read_single(6)
    D8 = Digital_inputs.read_single(7)

    #Analog Input A1 - Pressure Transducer 1 - 0-200 psia
    #C1 - Reading in 4-20 mA
    #C1_AB - Reading in PSI Absolute
    #C1_GA - Reading in PSI Gauge (Vacuum in negative PSI, not inHg)
    C1 = counts_to_value(A1, 745, 3723, 4, 20)
    C1_AB = (((C1-4)/16)*200)+.5
    C1_GA = (C1_AB)-14.7

    #Analog Input A2 - Pressure Transducer 2 - 0-200 psia
    #C2 - Reading in 4-20 mA
    #C2_AB - Reading in PSI Absolute
    #C2_GA - Reading in PSI Gauge (Vacuum in negative PSI, not inHg)
    C2 = counts_to_value(A2, 745, 3723, 4, 20)
    C2_AB = (((C2-4)/16)*200)+.5
    C2_GA = (C2_AB)-14.7

    #Analog Input A3 - Pressure Transducer 3 - 0-200 psia
    #C3 - Reading in 4-20 mA
    #C3_AB - Reading in PSI Absolute
    #C3_GA - Reading in PSI Gauge (Vacuum in negative PSI, not inHg)    
    C3 = counts_to_value(A3, 745, 3723, 4, 20)
    C3_AB = (((C3-4)/16)*200)+.5
    C3_GA = (C3_AB)-14.7

    #Analog Input A6 - Current Transducer 1 - 0-1000 Amps
    #C6 - Reading in 4-20 mA
    #C6_VDC - Reading in DC Volts
    #C6_Amps - Reading in Amps    
    C6 = counts_to_value(A6, 745, 3723, 4, 20)
    C6_VDC = (((C6-4)/16)*2.5)
    C6_Amps = (((C6-4)/16)*2.5)*1000

    #Analog Input A7 - Current Transducer 1 - 0-1000 Amps
    #C7 - Reading in 4-20 mA
    #C7_VDC - Reading in DC Volts
    #C7_Amps - Reading in Amps    
    C7 = counts_to_value(A7, 745, 3723, 4, 20)
    C7_VDC = (((C7-4)/16)*2.5)
    C7_Amps = (((C7-4)/16)*2.5)*1000

    #Analog Input A8 - Current Transducer 1 - 0-1000 Amps
    #C8 - Reading in 4-20 mA
    #C8_VDC - Reading in DC Volts
    #C8_Amps - Reading in Amps    
    C8 = counts_to_value(A8, 745, 3723, 4, 20)
    C8_VDC = (((C8-4)/16)*2.5)
    C8_Amps = (((C8-4)/16)*2.5)*1000

    #Print Pressure Transducer Readings to Screen
    print ("%f, %s, Input 1 = %d, %f, %f, %f" % (ts, rt, A1, C1, C1_AB, C1_GA))
    print ("%f, %s, Input 2 = %d, %f, %f, %f" % (ts, rt, A2, C2, C2_AB, C2_GA))
    print ("%f, %s, Input 3 = %d, %f, %f, %f" % (ts, rt, A3, C3, C3_AB, C3_GA))

    #Print Current Transducer Reading to Screen
    print ("%f, %s, Input 6 = %d, %f, %f, %f" % (ts, rt, A6, C6, C6_VDC, C6_Amps))
    print ("%f, %s, Input 7 = %d, %f, %f, %f" % (ts, rt, A7, C7, C7_VDC, C7_Amps))
    print ("%f, %s, Input 8 = %d, %f, %f, %f" % (ts, rt, A8, C8, C8_VDC, C8_Amps))

    #Write Pressure Readings to File "Pressure_File.txt"
    Pressure_File.write("%f, %s, Input 1, %d, %f, %f, %f\n" % (ts, rt, A1, C1, C1_AB, C1_GA))
    Pressure_File.write("%f, %s, Input 2, %d, %f, %f, %f\n" % (ts, rt, A2, C2, C2_AB, C2_GA))
    Pressure_File.write("%f, %s, Input 3, %d, %f, %f, %f\n" % (ts, rt, A3, C3, C3_AB, C3_GA))

    #Write Current Readings to File "Amp_File.txt"
    Amp_File.write("%f, %s, Input 6, %d, %f, %f, %f\n" % (ts, rt, A6, C6, C6_VDC, C6_Amps))
    Amp_File.write("%f, %s, Input 7, %d, %f, %f, %f\n" % (ts, rt, A7, C7,     C7_VDC, C7_Amps))
    Amp_File.write("%f, %s, Input 8, %d, %f, %f, %f\n" % (ts, rt, A8, C8,     C8_VDC, C8_Amps))

    print(D1)
    print(D2)
    print(D3)
    print(D4)
    print(D5)
    print(D6)
    print(D7)
    print(D8)

    print("")
    sleep(1.0)
  • How do you know it's not continuing? The while loop opens two files on every cycle, but you don't seem to write to it. Your 'inputs' lines also look odd; the second line probably overwrites the inputs variable, It could also be that the 'init()' call is ambiguous (calling a different function than you assume). I find adding 'print' statements in strategic places a useful debugging tool. – Dirk Oct 15 '18 at 15:14
  • Please don't use os.system() use the subprocess module instead. Also this might (or might not) be related: raspberrypi.stackexchange.com/q/70316/19949 – Ghanima Oct 15 '18 at 15:23
  • Dirk....sorry, there is more to the script but I didn't think it was pertinent to the discussion. Sufficed to say that I read inputs, write the date to screen and file. That portion of the script worked fine. When I added the lines to set the date and time, that's when it stopped. – skip671 Oct 15 '18 at 15:31
  • Dirk....I edited the post and included the entire code up to this point. – skip671 Oct 15 '18 at 15:44
  • Ghanima....Not familiar with the syntax or use of the subprocess module. I will do a little research on that and look at changing the code. – skip671 Oct 15 '18 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.