-
Notifications
You must be signed in to change notification settings - Fork 2
Finishing Up
The actual functionality of the datalogger is in place. Though, a few minor changes will help clean things up on the datalogger.
- Flash an LED while the Pi is Logging
- Format the numbers in our log file
- Automatically start script on boot
##Flash LED It would be helpful to have a visual indicator that the datalogger is running when not connected to the computer. In exercise 2, we were introduced to easy ways to control LEDs.
from gpiozero import LED
Add new variables
led = LED(17)
led_on = False
Add logic to toggle an LED every second
#split the delay into many 1 second intervals
#toggle the led every second
for i in range(DELAY_INTERVAL):
if led_on:
led.off()
led_on = False
else:
led.on()
led_on = True
sleep(1)
##Format our Log Entry We have long, decimal results. It would be better to truncate them to significant digits.
We will use the same string formatter from the initial DHT exercises.
In the interpretter:
>>> num = 25.200000762939453
>>> "{:0.2f}".format(num)
~ ~ ~
>>> "{:0.4f}".format(num)
~ ~ ~
The "f" stand for floating point, which is how computers typically store numbers with decimals. The 2 or 4 represents how many digits we want to keep.
This information came from Pyformat, more specifically their section on number padding
I have decided to reduce temperature and humidity to 1 decimal point, and my potentiometer voltage to 6 decimal points .
##Automatic startup on Boot
When we deploy out in the field, we want our datalogger to begin automatically when we add power. Auto-starting a script is a pretty common feature, so Raspberry Pi thankfully gives us this rc.local tutorial to get us started.
Please read the instructions carefully! Particularly parts about script.py & and how to reference "absolute" filenames.
##Other things to consider
- Maybe add a shutdown button to safely unplug the Pi while the script is running.
Wiki for Rhewlab Environmental Sensing Project
- Setting up Raspberry Pi
- Getting started with GPIO
- Reading Temperature and Humidity with DHT
- Adding a RTC to the Raspberry Pi
- Datalogging with Python
- Connecting to ADC with Raspi
- Finishing up
Digital
Analog