lasasvia.blogg.se

Raspberry pi temperature and light logger
Raspberry pi temperature and light logger













raspberry pi temperature and light logger
  1. RASPBERRY PI TEMPERATURE AND LIGHT LOGGER HOW TO
  2. RASPBERRY PI TEMPERATURE AND LIGHT LOGGER INSTALL
  3. RASPBERRY PI TEMPERATURE AND LIGHT LOGGER 64 BIT
  4. RASPBERRY PI TEMPERATURE AND LIGHT LOGGER CODE

Sensor2Label = Label(root, text='Sensor 2:',font=('times',16)) Sensor1Display = Label(root, font=('times',20)) Sensor1Label = Label(root, text='Sensor 1:',font=('times',16)) txt file.įrom _tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAggĭefaultStartTime = StringVar(root,value='7:00:00')ĭefaultEndTime = StringVar(root,value='19:00:00')ĬlockLabel = Label(root, text='clock',font=('times',16))Ĭid(row=0,column=0, padx=5,pady=5)Ĭlock = Label(root, font=('times', 20, 'bold'), bg='white')Ĭid(row=0,column=1,pady=5, padx=5) 4 threads are used, 1 to read and display the temperature data, 1 to get and display the timestamp, 1 to plot and display the temperature graph, and 1 to log the data onto the. To keep the graphics user interface responsive while the application does its work in the background, multi threading is necessary. The graph also refreshes itself every day at midnight, so that it will only display temperature data for 1 day. I also added a list box that displays the 10 most recent logged data, mainly to see that it is actually logging something. Since i am at it, i added a few other features such as logging intervals, and start/end of logging window. I imported the matplotlib module to plot the graph I thought it might be interesting to display the average temperature read by both sensors as a graph on a monitor against time to see the temperature behavior throughout the day. The argument for the DS18B20 class is the address of the sensor.

RASPBERRY PI TEMPERATURE AND LIGHT LOGGER CODE

Take note of both addresses, when you create the sensor object in the code using the DS18B20 module for example The terminal output will show all device addresses, in this case mine is 28-0000092b0c92 and 28- 0000092b4cf8 Once you have hooked up both sensors according to the schematic and powered up everything:

RASPBERRY PI TEMPERATURE AND LIGHT LOGGER 64 BIT

We will need the 64 bit address for both sensors, and you can do that from the command line. However if you are using a breakout board that already has a pull resistor, there is no need for this. Use a 4.7K resistor (i usually use 4.7K since i have a truckload of these, you may use 10K as well) to pull up the data for good practice. Connect the data pins of the DS18B2O to this pin on the pi. The one-wire pin on the Raspberry pi is pin 7, or GPIO4. Since we are using 2 DS18B20s, we can connect them to the same 1 wire bus. Since the DS18B20 uses the one wire interface, the data wire literally runs on, 1 wire! How convenient.

RASPBERRY PI TEMPERATURE AND LIGHT LOGGER INSTALL

$ sudo pip3 install ds18b20 Schematic Diagram DS18B20 wiring schematic for data logging We can use code that manually searches for the temperature output in the one wire directory, however i am going to skip all that since there is already a DS18B20 module built for that and i can simply get the temperature with 1 line of code. Instead, you may go to the reference here

RASPBERRY PI TEMPERATURE AND LIGHT LOGGER HOW TO

# Print out and log the temperature until the program is stopped.Since there are many tutorials introducing the DS18B20 and how to use it, i shall not talk about it here. # '=' into degrees Celsius, then degrees Fahrenheit # If the '=' is found, convert the rest of the line after the # Look for the position of the '=' in the second line of the # While the first line does not contain 'YES', wait for 0.2s Lines = read_temp_raw() # Read the temperature 'device file' # Convert the value of the sensor into a temperature

raspberry pi temperature and light logger raspberry pi temperature and light logger

# Finds the correct device file that holds the temperature dataĭevice_folder = glob.glob(base_dir + '28*')ĭevice_file = device_folder + '/w1_slave'į = open(device_file, 'r') # Opens the temperature device file Os.system('modprobe w1-therm') # Turns on the Temperature module Os.system('modprobe w1-gpio') # Turns on the GPIO module My new bit is at the end where it displays the temperature in the console but also writes the date/time and temperature to a file called temp.csv. One problem I had was that the Raspberry Pi can’t get on the internet until AFTER it has logged in (it requires authorisation on a web page to join the school network), so to set the clock to roughly the right time & date I used the following command:Īnd here’s the Python 3 code, modified from the CamJam EduKit code. The temperature sensor is part of the excellent CamJam Sensors EduKit /products/camjam-edukit-2-sensors – this costs an insane £7 for a tin box containing a breadboard, jumper wires, huge LEDs, a buzzer and light-dependent resistor.ī) when the classroom filled up with studentsĬ) when those students turned their computers on I then opened the CSV file in Libre Office on the Pi and made a simple line chart. We’re taking real historical weather data, analysing it in Excel and making Word documents about our findings.Ī simple Python script running on a Raspberry Pi logs the time and temperature every 5 minutes in a CSV file. Today I logged the temperature in our ICT room as part of a wider Y7 project on data handling, spreadsheets and climate change.















Raspberry pi temperature and light logger