chitown18th
Posts: 4
Joined: Sun Mar 01, 2020 3:55 am

Need help with Extracting data from Python script

Mon Mar 02, 2020 3:07 am

I posted this but maybe I should have changed my subject since I really need help with extracting the data values from python onto excel or some sort of database. Where I can utilize the data eventually on an excel sheet. It needs to continuously extract the cycle time and cycle count in real time. I have been going crazy with this here is my code as it stands. Thanks to anyone who can help.

Code: Select all

import RPi.GPIO as gpio
import time
gpio.setmode(gpio.BCM)
gpio.setup(25, gpio.IN)#injection
gpio.setup(17, gpio.IN)#automatic
autocyclehappened = False  # has button 1 been pressed?
injectionreset = False
stopper = False
count = 0
start = 0
end = 0
import colorama
from colorama import Fore
print(Fore.RED + "")

while True:
    input_value_17 = gpio.input(17)#Automatic
    input_value_25 = gpio.input(25)#injection
        
    if autocyclehappened == True:
        stopper = True
        
    if input_value_17 == 0 and input_value_25 == 0:
        autocyclehappened  = True # so it knows autocycling has been happpened.
        input_value_25 = 0
    
    if autocyclehappened == True and stopper == False:
        start = time.time()
        print(start)
        input_value_25 = 0
        
    if input_value_25 == 1 and autocyclehappened == True: #only count one cycle.
        injectionreset = True #injection came and went set up for next shot
        
    if input_value_25 == 0 and injectionreset == True:
        autocyclehappened = False # set autocycle false to reset the program.
        injectionreset = False
        stopper = False
        count = count+1
        i = count
        print("cycle count")
        print(i) #[b] <----- Need this [/b]
        print("Cycle time")
        elapsed = (time.time() - start)
        print(elapsed)# [b]<----- and this to update some sort of database HELP!!![/b]
        print("")

    time.sleep(0.1)
    

PhatFil
Posts: 1672
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Need help with Extracting data from Python script

Mon Mar 02, 2020 3:41 am

excel can open remote data sources like odbc compliant databases so if your system uses one already ?

If not you could use the good ol comma separated file CSV

Use the import data features to open your remote data file on the pi.

On the excel side you will probably need a vba script to refresh the sheet to reflect changes in the data file

Return to “Python”