Commit 86b69e47 authored by Torje Garnes Anderson's avatar Torje Garnes Anderson
Browse files

Upload New File

parent ac7f8663
import Adafruit_BBIO.ADC as ADC
from time import sleep
import threading
w1 = "/sys/bus/w1/devices/28-00000bc634bd/w1_slave" #this reads the temperature values from the sensor at P9_12
ADC.setup() #Needed for Adafruit to work
i = 0 #Counter for every sensor reading
j = 0 #Used to combined 10 sensor readings with temperature
k = 0 #Same as j
f = open('csv_file', 'w') #Used for reading into csv_file
tempArray = [] #Array for holding the temperatures
pulseArray = [] #Array for all the sensor readings
class Temperatur: #This class is used to getting the temperature
def temp(self): #Function for temperature reading
raw = open(w1, "r").read() #Reads the temperature from sensor
temp = str(float(raw.split("t=")[-1]) / 1000) #Formatting the temperature
tempArray.append(temp) #Adding it to the array
print('Temperatur: ' + str(float(raw.split("t=")[-1]) / 1000)) #This is only for us when we do the testing
def __init__(self):
t = threading.Thread(target=self.temp) #Open a thread so we can do sensor and temperature at the same time
t.start() #Starting the thread
class Puls: #This class is used for getting the sensor values
def pulse(self): #Function for sensoe reading
value = ADC.read("P9_40") #Using the ADC.read function on pin P9_40 to get the sensor value
volt = value * 1.8 #A test to see if it was any different when adding 1.8 (suggested from teacher)
pulseArray.append('{:.6f}'.format(value)) #Adding the sensoe value to the array
print('Verdi: ' + str('{:.6f}'.format(value)) + ' Volt: ' + str('{:.6f}'.format(volt))) #Only used for testing
def __init__(self):
t = threading.Thread(target=self.pulse) #Open a thread so we can do sensor and temperature at the same time
t.start() #Starting the thread
print('Reading') #headline for testing
while i < 100: #Looping through all the readings 100 times
Puls() #Calling the pulse class each time
if i % 10 == 0: #Every 10th reading we add a new temperature reading
Temperatur()
i += 1 #Adding 1 for the loop counter
sleep(0.1) #Sleep every 0.1 second so we do 10 readings every second for the pulse
while j < len(pulseArray): #This loop is used for adding everyhing to the csv_file
f.write(str(j) + ',' + pulseArray[j] + ',' + tempArray[k-1] + '\n') #Writing everything to the csv_file j goes from 0-99,
j += 1 #Adding 1 evertime
if j > 10: #Check to see if we have 10 readings
k = j / 10 #If we do k = j and devide it by 10 so the temperature is the same for all 10 readings
f.close()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment