Hardware Reference
In-Depth Information
Advanced Usage
The SD library actually makes use of three internal libraries: Sd2Card, SdVolume,
and SdFile. All the functions present in the SD library are wrapper functions
that call different functions in these three libraries. The SD library follows the
Arduino philosophy, making it easy to do advanced functions. However, you can
still use these three libraries if you need access to even more advanced functions.
Sd2Card card;
SdVolume volume;
SdFile root;
There are numerous functions, and these functions are mainly out of the
scope of this topic, but there are a few that may be of interest.
To get information about the card size, you can get data about the geometry of
the SD card—that is, the number of clusters and the number of blocks per cluster.
unsigned long volumesize = volume.blocksPerCluster();
volumesize *= volume.clusterCount();
volumesize *= 512;
On SD cards, blocks are always 512 bytes. You can get the amount of blocks per
cluster, and the amount of clusters on the card, giving you the card size, in bytes.
More utility functions are listed in the example program: CardInfo. It is avail-
able in the Arduino IDE: Files
Examples
SD
CardInfo.
Example Program and Sketch
For this application, you build a data-logging application. The aim is to under-
stand how sunlight evolves during a day. For this, you will require several
components, but the sensor in this application is a light dependent resistor, or
LDR for short. An LDR will have variable resistance depending on the amount
of sunlight (or artii cial light) it receives. The circuit for this example will require
a pull-down resistor in order to create a circuit known as a voltage divider . This
is illustrated in Figure 12-5. The voltage at Vin is always 5 volts, and depending
on the resistance of the LDR, the voltage at Vout will be somewhere between
the maximum of 5 volts and the minimum of 0 volts, depending on the light
being received.
When there is no light, the resistance or the LDR will be high, and the refer-
ence voltage will be closer to zero. When there is a lot of sunlight, the resistance
will be weak, and the reference voltage will be closer to 5 volts. This reference
is read by an ADC on the Arduino's A3 pin. The ADC will compare the voltage
on the pin to the 5 Volts the Arduino runs off. It will return a value between 0
and 1023, and depending on the component you use, it is possible to calculate
the Lux value of visible light.
 
Search WWH ::




Custom Search