Skip to content

Finishing Up

bwasmith edited this page Aug 31, 2016 · 2 revisions

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 TODO

Clone this wiki locally