Hardware Reference
In-Depth Information
Why is the i le closed after every write? It is good practice to close a i le when
it is not needed, and it forces data to be l ushed to the SD card. On embedded
systems, you do not know when the user may unplug the system. Leaving a
i le open could potentially mean that data is left unwritten and therefore lost.
Closing the i le ensures that data is written as soon as possible, and the SD card
is left in a clean state.
The result of this sketch creates a text i le that can be imported into a spread-
sheet, like Excel or LibreOfi ce Calc. The results of a sunrise in my city are shown
in Figure 12-7. The ambient light level is already at 200 due to street lights, but
something happened at the 16-minute mark—the visible light suddenly dropped
down considerably, but only for a minute. This was probably the sensor being
blocked—probably by my cat—but it shows that surprises can happen!
Figure 12-7: Example data output
Summa ry
In this chapter, you have seen how to connect an SD card to your Arduino using
different methods, and how to initialize the card. I have shown how to read
and write data to the card, and how that data can be used later to give visual
results. In the next chapter, I will show you how to make an even more visual
impact using TFT screens.
 
Search WWH ::




Custom Search