zondag 20 februari 2011

My first Arduino project - part 3

Now it's time to start making use of the Adafruit Data Logger shield functionalities

Initialize the shield
So before using the shield I needed to set the time on the data logger shield.  This page describes how this can be done.

To get the sketches working as described in the explanation, I just added the RTC library, toghether with the SD library to my Arduino environment.  I added a libraries directory to the default sketchbook.  I downloaded the adafruit-RTClib-72fc1a4.tar.gz and sdfatlib20101010.zip file and unpacked them in the libraries directory.  The following shows what I did to make these libraries accessible to my Arduino IDE:


someuser@somehost:~/sketchbook/libraries$ pwd
/home/someuser/sketchbook/libraries
someuser@somehost:~/sketchbook/libraries$ ls -la
total 20
drwxr-xr-x 5 someuser someuser 4096 2011-02-20 21:08 .
drwxr-xr-x 8 someuser someuser 4096 2011-02-20 18:54 ..
drwxrwxr-x 3 someuser someuser 4096 2010-07-30 04:36 adafruit-RTClib-72fc1a4
drwxr-xr-x 5 someuser someuser 4096 2011-02-20 18:22 sdfatlib20101010
someuser@somehost:~/sketchbook/libraries$ mv ./adafruit-RTClib-72fc1a4 ./RTClib
someuser@somehost:~/sketchbook/libraries$ mv ./sdfatlib20101010 ./sdfatlib
someuser@somehost:~/sketchbook/libraries$ ls -la
total 20
drwxr-xr-x 5 someuser someuser 4096 2011-02-20 21:08 .
drwxr-xr-x 8 someuser someuser 4096 2011-02-20 18:54 ..
drwxrwxr-x 3 someuser someuser 4096 2010-07-30 04:36 RTClib
drwxr-xr-x 5 someuser someuser 4096 2011-02-20 18:22 sdfatlib
someuser@somehost:~/sketchbook/libraries$ ls -al ./sdfatlib
total 288
drwxr-xr-x 5 someuser someuser   4096 2011-02-20 18:22 .
drwxr-xr-x 5 someuser someuser   4096 2011-02-20 21:08 ..
-rw-r--r-- 1 someuser someuser    558 2010-08-02 09:13 AF_GPS_Mega.txt
-rw-r--r-- 1 someuser someuser   4844 2010-10-10 08:34 changes.txt
drwxr-xr-x 2 someuser someuser   4096 2011-02-20 18:22 html
drwxr-xr-x 2 someuser someuser   4096 2011-02-20 18:22 makePinInclude
-rw-r--r-- 1 someuser someuser   6552 2010-08-13 05:34 readme.txt
drwxr-xr-x 3 someuser someuser   4096 2011-02-20 18:22 SdFat
-rw-r--r-- 1 someuser someuser 224229 2010-08-13 05:23 SdFat.pdf
-rw-r--r-- 1 someuser someuser  21428 2009-02-15 09:11 SdLevel.png
-rw-r--r-- 1 someuser someuser   1921 2010-08-13 05:20 troubleshooting.txt
someuser@somehost:~/sketchbook/libraries$ cp -a ./sdfatlib/SdFat ./
someuser@somehost:~/sketchbook/libraries$ rm -rf ./sdfatlib
someuser@somehost:~/sketchbook/libraries$ ls -la
total 20
drwxr-xr-x 5 someuser someuser 4096 2011-02-20 21:08 .
drwxr-xr-x 8 someuser someuser 4096 2011-02-20 18:54 ..
drwxrwxr-x 3 someuser someuser 4096 2010-07-30 04:36 RTClib
drwxr-xr-x 3 someuser someuser 4096 2011-02-20 18:22 SdFat


I unpacked these files in the libraries directory and renamed them so the resulting directory names (one for each lib) only contained letters and numbers (the arduino IDE doesn't seem to handle anything else very well).

Also, the SD sources are found in a subdirectory that needs to be copied into the libraries directory instead of the unpacked archive file.  So after restart of the arduino IDE, I could start using the libraries.

After the above changes you need to restart your Arduino IDE to have access to the libraries.

So now that the libraries are accessible from the IDE and my data logging shield's time is set, I can start using the RTC and SD functionalities.

RTC

I copied some code into the piece of the application that prints out the RFID token whenever a new token is read. The copied code (see below) however didn't work for me:

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);

I adjusted the source to the following to make it work:

#include <Wire.h>
#include <RTClib.h>
...
RTC_DS1307 RTC;
...
    Serial.print(RTC.now().year(), DEC);

    Serial.print('/');
    Serial.print(RTC.now().month(), DEC);
    Serial.print('/');
    Serial.print(RTC.now().day(), DEC);
    Serial.print(' ');
    Serial.print(RTC.now().hour(), DEC);
    Serial.print(':');
    Serial.print(RTC.now().minute(), DEC);
    Serial.print(':');
    Serial.print(RTC.now().second(), DEC);

My C knowledge is very basic, so there might be a very good reason why the first code didn't work but the above changes work for me.

So now I got a time stamp displayed whenever a RFID token is read.  So, next I'll try to get the SD card involved in the application. But that will be for the next blog entry :-)

Stats
compiler
Binary sketch size: 6162 bytes (of a 30720 byte maximum)
So this still leaves me 24558 bytes of room.

Geen opmerkingen:

Een reactie plaatsen