Hardware Reference
In-Depth Information
away! This is an example of lossy compression. It takes advantage of assumptions of how
the audio data will be interpreted in our brains - for example, if a quiet and a loud sound are
played together, the quiet sound isn't heard, and therefore there is no value to the ear in the
data representing it.
If you wanted to record birdsong in your bird box, then without audio compression you
would quickly run out of storage space on the SD card. Lossy compression isn't suitable for
all applications; for example, you wouldn't want to throw away data about bird visits.
Instead, lossless compression would be more appropriate.
Lossless compression represents data in a more eficient format. For example, if you had a
list of numbers 2,0,0,0,0,0,1, instead of sending each 0 you could encode the list as 2,5x0,1.
Zip compression is an example of this form of compression (and is used to make the
Raspbian OS download smaller).
If you needed to transfer your bird data remotely, over a mobile phone connection, then you
might use zip to make the ile smaller, or you might consider doing some other processing
(to get rid of noisy readings) to send just the information you need.
In some cases you want to know that the data hasn't been corrupted. In this case you might
add redundant data so that you can detect or even correct any errors. MD5 checksums that
represent the contents of a long ile with a short sequence of characters are an example of
this. You came across MD5 checksums in Chapter 1, “Getting Your Raspberry Pi Up and
Running”, to detect if the Raspbian OS download had been corrupted.
The Complete Logging Program
he program in Listing 17-1 records the time, which sensor triggered and whether it was
broken or unbroken in ile.
Listing 17-1 recordBird.py
#!/usr/bin/env python
import piface.pfio as p
import datetime
p.init()
#Define the inputs/output pin number that
#the beams are connected to.
INNER_BEAM = 0
OUTER_BEAM = 1
#keeps track of the last state the beam was in
continued
 
Search WWH ::




Custom Search