Tutorial: como utilizar o Data Shield com Arduino

Neste tutorial, vamos mostrar como utilizar o Data Shield com Arduino. O Data Shield consiste em um display de LCD, um suporte para cartão MicroSD, um suporte para bateria do "Real Time Clock" e botões.

O Data Shield pode ser usado como central de monitoramento de horários, de pessoas e de entrada e saída (data logger). Pode ser usado também para armazenamento, organização de dados e mostrar os dados no display LCD.

 

Incubadora Lab de Garagem

 

Primeiramente coloque a bateria de 3V que vem junto com o Data Shield, depois coloque um cartão micro-SD (sem o cartão o Data Shield não funciona). Agora conecte o Data Shield no Arduino.

Agora, baixe as bibliotecas disponíveis na Loja LdG: Se caso estiver utilizando a versão 002x da IDE do Arduino, baixe deste link. Se estiver utilizando a versão 1.0 da IDE do Arduino, baixe deste link.

Baixe o código exemplo disponível na Loja LdG, clicando aqui

OBS: Para a versão 1.0 da IDE comente a linha em vermelho.

/*

Exemplo de programa escrito para o DATA SHILED do Laboratório de garagem http://labdegaragem.com

Versão 1.0 - 01 Mar 2012
Versão 1.1 - 08 Mar 2012 - correção do bug do fadeout do Display, assim como no tempo do fadeout.

Escrito por Jiri Trnka

Compilar com Arduino IDE 0019 a 0023

Código sob licença de código aberto "open source" GPL.
Cópia autorizada desde que mantida a referência aos autores

OBS: Para utilizar o LCD adicione DS1307RTC.h e LiquidCrystal_I2c.h

*/

// ***************** INCLUDES of the necessary libraries *************
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
//#include <WProgram.h>
#include <avr/pgmspace.h>
#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h> //Necessary to LCD
#include <SD.h>

// ***************** CONSTANTS *****************
const int ERROR_WINDOW = 50; // tolerance +/- this value for the button's analog input
const int BUTTONDELAY = 50; // button's debounce delay
const int BUTTONREPEAT = 200; // repeat delay of the pressed buttons
const int TIMEOUT = 30000; // timout value to exit to default display in miliseconds (remember that INT type max allowed value is 32767)
const int LEDPIN = 5; // output pin for the PWM of the LCD backlight
const int CONTRASTPIN = 9; // output pin for the PWM of the LCD contrast
const int SD_CS = 8; // Pin 8 is the CS chip select of the SD memory card on this Shield
const int BUTTONPIN = A0; // input pin for the buttons

// ************ BUTTONS position and analog values ************************
// [UP (2)] 460
// [SEL (5)] 0 [LFT (1)] 133 [RGT (4)] 715 [RST]
// [DWN (3)] 273

const int SELBTN = 0; // Analog value for the SELECT button
const int LFTBTN = 133; // Analog value for the LEFT button
const int DWNBTN = 273; // Analog value for the DOWN button
const int UPBTN = 460; // Analog value for the UP button
const int RGTBTN = 715; // Analog value for the RIGHT button

// Uncomment the following line to send DEBUG messages to the serial port at 9600 bauds
// #define DEBUG_ON

// Flash memory stored string table. Necessary because otherwise the strings will take up too much of our very limited RAM.
// Use either PrintLCDAt_P or PrintLCD_P to print these strings to the LCD.
prog_char string_0[] PROGMEM = "1. Contraste "; //0
prog_char string_1[] PROGMEM = "2. Backlight "; //1
prog_char string_2[] PROGMEM = "3. Data "; //2
prog_char string_3[] PROGMEM = "4. Hora "; //3
prog_char string_4[] PROGMEM = " Menu Principal "; //4
prog_char string_5[] PROGMEM = " Contraste "; //5
prog_char string_6[] PROGMEM = " Backlight "; //6
prog_char string_7[] PROGMEM = " Data "; //7
prog_char string_8[] PROGMEM = " Hora "; //8
//array of pointers to the flash based string table
PROGMEM const char *string_table[] = {
string_0, string_1, string_2, string_3, string_4, string_5, string_6, string_7, string_8
};

// ********** GLOBAL VARIABLES **********
// LCD
LiquidCrystal_I2C lcd(0x20,16,2); // set the i2c LCD address to 0x20 and define a 16 rows and 2 lines display
byte backlight; // values from 0 to 255 LCD backlight
byte contrast; // values from 0 to 255 LCD contraste
long previousMillis; // will store last time of timout
unsigned long currentMillis; // will store the current time counter
boolean BacklightON = true; // used for the control of the backlight timout
boolean SDCARD = true; // used for disabling the logging in case of SD CARD failure
File myFile;
char DATAFILE[] = "data.log"; // Name of the Data file that will be created on the SD memomry card, this name must be in the 8.3 DOS format

// Buttons
unsigned long buttonLastChecked = 0; // variable to limit the button getting checked every cycle
short previousval = 0; // initialization of the variable to 0
short pushedbutton = 0; // initialization of the variable to 0
short previousbutton = 0; // initialization of the variable to 0
unsigned long lastbtnpress = 0; // initialization of the variable to 0

// ********** ARDUINO SETUP **********
void setup()
{
pinMode(LEDPIN, OUTPUT); // sets the LCD LED backlight pin as output
pinMode(CONTRASTPIN, OUTPUT); // sets the LCD Contrast pin as output
pinMode(A1, INPUT); // sets the Analog pin 1 as input
pinMode(A2, INPUT); // sets the Analog pin 2 as input
pinMode(A3, INPUT); // sets the Analog pin 3 as input

// Up to 6 timers can be defined, see documentation of the TimeAlarms Library for details
// Alarm.timerRepeat(15, RepeatTask); // timer that calls the "RepeatTask function every 15 seconds
Alarm.timerRepeat(1,0,0, RepeatTask); // timer that calls the "RepeatTask function every hour (up to 6 different timers can be set)

lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.print("DATA SHIELD v1.1"); // Print a message to the LCD.
lcd.setCursor(0, 1); // set the cursor to column 0, line 1 (note: line 1 is the second line, since counting starts with 0):
lcd.print("labdegaragem.com"); // Print a message to the LCD.
backlight=EEPROM.read(1); // Read from the EEPROM the backlight value set by the interface. It is stored in the EEPROM address 1
analogWrite(LEDPIN, backlight); // Turn On the LCD Backlight to the value stored in the EEPROM
contrast=EEPROM.read(0); // Read from the EEPROM the contrast value set by the interface. It is stored in the EEPROM address 0
if (contrast > 81) contrast=0; // A formatted or new chip has all it's EEPROM bytes set to 255, and contrast at 255 is the minimum contrast, so in order to have something on the display we test new chips here.
analogWrite(CONTRASTPIN, contrast); // Set the LCD contrast to the value stored in the EEPROM
#ifdef DEBUG_ON
Serial.begin(9600); // Serial port initialize
Serial.println("Data logger BOOT");
#endif
// On the labdegaragem DATA SHILED, CS is pin 8. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(SD_CS)) {
lcd.clear();
lcd.print("Cartao SD falhou");
lcd.setCursor(0, 1); // set the cursor to column 0, line 1 (note: line 1 is the second line, since counting starts with 0):
lcd.print(" Log desativado "); // Print a message to the LCD.
SDCARD = false;
#ifdef DEBUG_ON
Serial.println("INIT SD Falhou!");
#endif
Alarm.delay(2000); // For the library TimeAlarms, it is necessary to use the Alarm.delay function instead of the standard Delay function.
}
setSyncProvider(RTC.get); // Sync the Arduino clock from the time of the RTC, resync every 5 minutes (default value)
Alarm.delay(5000); // Wait for splash screen
previousMillis = millis(); // Reset timout counter
if (SDCARD) {
myFile = SD.open(DATAFILE, FILE_WRITE); // if SD card present, open the data.log file, note that only one file can be open at a time, so you have to close this one before opening another.
digitalClockWrite();
myFile.println(";Boot");
myFile.close(); // close the file
}
lcd.clear(); // pretty self explaining, isn´t it?
}
// ********** ARDUINO MAIN LOOP **********
void loop()
{
digitalClockDisplay(); //call function
Alarm.delay(50); // refresh of the alarm trigger, with i2c displays do not choose values under 50 ms in order to avoid ugly flickering.

if( buttonLastChecked == 0 ) // see if this is the first time checking the buttons
buttonLastChecked = millis()+BUTTONDELAY; // force a check this cycle because we do not need to check every cycle
if( millis() - buttonLastChecked > BUTTONDELAY ) { // make sure a reasonable delay passed
if( int buttNum = buttonPushed(BUTTONPIN) ) {
previousbutton=buttNum;
mainMenu();
}
buttonLastChecked = millis(); // reset the lastChecked value
}

// check to see if it's time to timeout the backlight; that is, if the
// difference between the current time and last time of some button event
// is bigger than the interval.
currentMillis = millis();

if(currentMillis - previousMillis > TIMEOUT) {
if (BacklightON != false) {
fadeBacklight();
}
}
}

 

// ******************* FUNCTIONS ****************************

// ************* Read Buttons *************
int buttonPushed(int BUTTONPIN) {
int val = ERROR_WINDOW; // variable to store the read value
val = analogRead(BUTTONPIN); // read the input pin
#ifdef DEBUG_ON
Serial.println(val); // Output to serial port the analog value of the pressed button
#endif
if (val < (previousval-ERROR_WINDOW) or val > (previousval+ERROR_WINDOW)) { // Avoid duplicate button presses

// we don't use the upper 1023 position because that is the same as the
// all-open switch value when the internal 20K ohm pullup is enabled.
if( val >= (RGTBTN-ERROR_WINDOW) and val <= (RGTBTN+ERROR_WINDOW) ) { // 716
previousval = val;
pushedbutton = 4; // RIGHT
previousMillis = currentMillis; // reset of timout
BacklightON = true;
lastbtnpress = millis(); // reset the lastChecked value
return pushedbutton;
}
else if ( val >= (UPBTN-ERROR_WINDOW) and val <= (UPBTN+ERROR_WINDOW) ) { // 469
previousval = val;
pushedbutton = 2; // UP
previousMillis = currentMillis; // reset of timout
BacklightON = true;
lastbtnpress = millis(); // reset the lastChecked value
return pushedbutton;
}
else if ( val >= (DWNBTN-ERROR_WINDOW) and val <= (DWNBTN+ERROR_WINDOW) ) { // 293
previousMillis = currentMillis; // reset of timout
previousval = val;
pushedbutton = 3; // DOWN
BacklightON = true;
lastbtnpress = millis(); // reset the lastChecked value
return pushedbutton;
}
else if ( val >= (LFTBTN-ERROR_WINDOW) and val <= (LFTBTN+ERROR_WINDOW) ) { // 132
previousMillis = currentMillis; // reset of timout
previousval = val;
pushedbutton = 1; // LEFT
BacklightON = true;
lastbtnpress = millis(); // reset the lastChecked value
return pushedbutton;
}
else if( val >= SELBTN and val <= (SELBTN+ERROR_WINDOW) ) {
previousMillis = currentMillis; // reset of timout
previousval = val;
pushedbutton = 5; // SELECT
BacklightON = true;
lastbtnpress = millis() ; // reset the lastChecked value
return pushedbutton;
}
else {
previousval = (-ERROR_WINDOW-1);
return 0; // no button found to have been pushed
}
}
else if (pushedbutton < 5) {
if( millis() - lastbtnpress > BUTTONREPEAT ) { // repeat key presses at BUTTONREPEAT interval when buttons are keep pressed
lastbtnpress = millis(); // reset the time of the last key press
previousMillis = currentMillis; // reset of timout
return pushedbutton;
}
}
}

// ************* Main Menu *************
void mainMenu() {

byte offset=0;
int buttNum;

analogWrite(LEDPIN, backlight);
lcd.clear();
lcd.noBlink();
PrintLCD_P(4); //" Main Menu "

do {
PrintLCDAt_P(offset, 0, 1);
buttNum = buttonPushed(BUTTONPIN);
previousbutton = buttNum;
Alarm.delay(BUTTONDELAY);
currentMillis = millis();
switch(buttNum) {
case 1:
loop();
break;
case 2:
if (offset > 0) offset--;
break;
case 3:
if (offset < 3) offset++;
break;
case 5:
switch (offset) {
case 0: //Contrast
ContrastMenu();
break;
case 1: //Backlight
BacklightMenu();
break;
case 2: //Date
DateMenu();
break;
case 3: //Hour
HourMenu();
break;
}
break;
}
}
while (currentMillis - previousMillis < TIMEOUT);
}
// ************* Contrast Menu *************
void ContrastMenu() {

int bar=(contrast/16);
byte prevcontr = contrast;
int prevBar = bar;
lcd.clear();
PrintLCD_P(5); //" Contrast "

do {
bar=(15-(contrast/5));
lcd.setCursor(prevBar,1);
lcd.print(" ");
lcd.setCursor(bar, 1);
lcd.print(char(255));
analogWrite(CONTRASTPIN, contrast);
int buttNum = buttonPushed(BUTTONPIN);
Alarm.delay(BUTTONDELAY);
prevBar = bar;
currentMillis = millis();

switch(buttNum) {
case 1: // esc
contrast = prevcontr;
analogWrite(CONTRASTPIN, contrast);
mainMenu();
break;
case 2:
if (contrast >=5) contrast=contrast-5; // 0 = contrast MAX
break;
case 3:
if (contrast < 81) contrast=contrast+5; // does not make sense to go upper than aprox. 90, the contrast is already at MIN arround this value
break;
case 5: // save
EEPROM.write(0, contrast); // write the new contrast value to EEPROM at address 0
mainMenu();
break;
}
}
while (currentMillis - previousMillis < TIMEOUT);
}
// ************* Backlight Menu *************
void BacklightMenu() {

int bar = (backlight/16);
byte prevback = backlight;
int prevBar = bar;
lcd.clear();
PrintLCD_P(6); //" Backlight "

do {
bar=(backlight/16);
lcd.setCursor(prevBar,1);
lcd.print(" ");
lcd.setCursor(bar, 1);
lcd.print(char(255));
analogWrite(LEDPIN, backlight);
int buttNum = buttonPushed(BUTTONPIN);
Alarm.delay(BUTTONDELAY);
prevBar = bar;
currentMillis = millis();

switch(buttNum) {
case 1: // ESC
backlight = prevback;
analogWrite(LEDPIN, backlight);
mainMenu();
break;
case 2:
if (backlight < 240) backlight=backlight+16; // 255 = backlight MAX
break;
case 3:
if (backlight >=16) backlight=backlight-16; // 0 = backlight OFF
break;
case 5: // SAVE
EEPROM.write(1, backlight); // write the new backlight value to EEPROM at address 1
mainMenu();
break;
}
}
while (currentMillis - previousMillis < TIMEOUT);
}
// ************* Date Menu *************
void DateMenu() {

lcd.clear();
PrintLCD_P(7); //" Date "
lcd.setCursor(1, 1); //line=1 (0 is the first line), x=3
printDayOfWeek(weekday());
lcd.print(" ");
lcd.print(zerolead(day()));
lcd.print("/");
lcd.print(zerolead(month()));
lcd.print("/");
lcd.print(year());

do {
int buttNum = buttonPushed(BUTTONPIN);
Alarm.delay(BUTTONDELAY);
currentMillis = millis();
switch(buttNum) {
case 1: // ESC
mainMenu();
break;
case 5: // Call setup menu
DateSetMenu(); // Back to menu
break;
}
}
while (currentMillis - previousMillis < TIMEOUT);
}
// ************* Date Set Menu *************
void DateSetMenu() {

byte offset=0;
int Day,Month,Year;
Day = day();
Month = month();
Year = year();
lcd.clear();
PrintLCD_P(7); //" Date "
lcd.setCursor(3, 1); //line=1 (0 is the first line), x=3
lcd.print(zerolead(day()));
lcd.print("/");
lcd.print(zerolead(month()));
lcd.print("/");
lcd.print(year());
lcd.blink();

do {
lcd.setCursor(4+(offset*3), 1);
if (offset == 2) lcd.setCursor(12, 1);

int buttNum = buttonPushed(BUTTONPIN);
Alarm.delay(BUTTONDELAY);
currentMillis = millis();
switch(buttNum) {
case 1:
if (offset > 0) offset--;
break;

case 2:
switch(offset) {
case 0:
if (Day < 31) Day++;
lcd.setCursor(3, 1); //line=2 (1 is the second line), x=5
lcd.print(zerolead(Day));
break;
case 1:
if (Month < 12) Month++;
lcd.setCursor(6, 1); //line=2 (1 is the second line), x=8
lcd.print(zerolead(Month));
break;
case 2:
if (Year < 2099) Year++;
lcd.setCursor(9, 1); //line=2 (1 is the second line), x=11
lcd.print(Year);
break;
}
break;

case 3:
switch(offset) {
case 0:
if (Day > 1) Day--;
lcd.setCursor(3, 1); //line=2 (1 is the second line), x=5
lcd.print(zerolead(Day));
break;
case 1:
if (Month > 1) Month--;
lcd.setCursor(6, 1); //line=2 (1 is the second line), x=8
lcd.print(zerolead(Month));
break;
case 2:
if (Year > 2010) Year--;
lcd.setCursor(9, 1); //line=2 (1 is the second line), x=11
lcd.print(Year);
break;
}
break;

case 4:
if (offset < 2) offset++;
break;
case 5: // SAVE
setTime(hour(),minute(),second(),Day,Month,Year); // set Arduino system time
time_t t = now(); // convert to UNIX type time_t
RTC.set(t); // set the time of the RTC chip
lcd.noBlink();
DateMenu(); // Back to menu
break;
}
}
while (currentMillis - previousMillis < TIMEOUT);
lcd.noBlink();
}

// ************* Hour Menu *************
void HourMenu() {

lcd.clear();
PrintLCD_P(8); //" Hour "

do {
lcd.setCursor(4, 1); //line=2 (1 is the second line), x=4
lcd.print(zerolead(hour()));
lcd.print(":");
lcd.print(zerolead(minute()));
lcd.print(":");
lcd.print(zerolead(second()));
int buttNum = buttonPushed(BUTTONPIN);
Alarm.delay(BUTTONDELAY);
currentMillis = millis();
switch(buttNum) {
case 1: // ESC
mainMenu();
break;
case 5: // call setup menu
HourSetMenu(); // Back to menu
break;
}
}
while (currentMillis - previousMillis < TIMEOUT);
}
// ************* Hour Set Menu *************
void HourSetMenu() {

byte offset=0;
int Hour,Minute,Second;
Hour = hour();
Minute = minute();
Second = 0;
lcd.clear();
PrintLCD_P(8); //" Hour "
lcd.setCursor(4, 1); //line=2 (1 is the second line), x=4
lcd.print(zerolead(Hour));
lcd.print(":");
lcd.print(zerolead(Minute));
lcd.print(":");
lcd.print(zerolead(Second));
lcd.blink();

do {
lcd.setCursor(5+(offset*3), 1);
int buttNum = buttonPushed(BUTTONPIN);
Alarm.delay(BUTTONDELAY);
currentMillis = millis();

switch(buttNum) {
case 1:
if (offset > 0) offset--;
break;
case 2:
if (offset==0) {
if (Hour < 23) Hour++;
lcd.setCursor(4, 1); //line=2 (1 is the second line), x=4
lcd.print(zerolead(Hour));
}
else
{
if (Minute < 59) Minute++;
lcd.setCursor(7, 1); //line=2 (1 is the second line), x=4
lcd.print(zerolead(Minute));
}
break;
case 3:
if (offset==0)
{
if (Hour > 0) Hour--;
lcd.setCursor(4, 1); //line=2 (1 is the second line), x=4
lcd.print(zerolead(Hour));
}
else
{
if (Minute > 0) Minute--;
lcd.setCursor(7, 1); //line=2 (1 is the second line), x=4
lcd.print(zerolead(Minute));
}
break;
case 4:
if (offset < 1) offset++;
break;
case 5: // SAVE
setTime(Hour,Minute,Second,day(),month(),year()); // Set arduino system time
time_t t = now(); // convert to UNIX type time_t
RTC.set(t); // set the time of the RTC chip
lcd.noBlink();
HourMenu();
break;
}
}
while (currentMillis - previousMillis < TIMEOUT);
lcd.noBlink();
}
// ************* Print PROGMEM string *************
// This is the gatekeeper function. The only one to really touch the strings in program memory. This keeps the need
// for a buffer string to only one. So, basically we're only using 17 bytes of RAM to store strings.
void PrintLCD_P(int which) {
char buffer[17];
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[which])));
lcd.print(buffer);
}
// ************* Print PROGMEM string at LCD location *************
// Print a string found in program memory to the LCD at a certain location
// Basically this just sets the location and then calls PrintLCD_P to do the work
void PrintLCDAt_P(int which, char x, char y) {
lcd.setCursor(x, y);
PrintLCD_P(which);
}
// ************* Display date / time on LCD display *************
void digitalClockDisplay()
{
// digital clock display of the date and time
lcd.setCursor(1, 0); //line=1 is the LCD´s second line (0 is the first line)
printDayOfWeek(weekday());
lcd.print(" ");
lcd.print(zerolead(day()));
lcd.print("/");
lcd.print(zerolead(month()));
lcd.print("/");
lcd.print(year());
lcd.setCursor(4, 1); //line=2 (1 is the second line), x=3
lcd.print(zerolead(hour()));
lcd.print(":");
lcd.print(zerolead(minute()));
lcd.print(":");
lcd.print(zerolead(second()));
}
// ************* Write date / time into a file on the SD card *************
void digitalClockWrite()
{
// digital clock display of the date and time
myFile.print(zerolead(day()));
myFile.print("/");
myFile.print(zerolead(month()));
myFile.print("/");
myFile.print(year());
myFile.print(";");
myFile.print(zerolead(hour()));
myFile.print(":");
myFile.print(zerolead(minute()));
myFile.print(":");
myFile.print(zerolead(second()));
}
// ************* The day name corresponding to the day number given by the RTC *************
void printDayOfWeek(int dayOfWeek)
{
switch(dayOfWeek){
case 1:
lcd.print("Dom");
break;
case 2:
lcd.print("Seg");
break;
case 3:
lcd.print("Ter");
break;
case 4:
lcd.print("Qua");
break;
case 5:
lcd.print("Qui");
break;
case 6:
lcd.print("Sex");
break;
case 7:
lcd.print("Sab");
break;
}
}

// ************* Utility function for digital clock/date display: prints leading 0 for single digit numbers *************
String zerolead(int digits)
{
String lead;
if(digits < 10) {
lead ='0'+String(digits);
}
else {
lead = String(digits);
}
return lead;
}
// ************* Tasks to be executed at the interval defined in the Timer ****************************
void RepeatTask (){
if (SDCARD) {
myFile = SD.open(DATAFILE, FILE_WRITE); // if SD card present, open the data.log file, note that only one file can be open at a time, so you have to close this one before opening another.
digitalClockWrite();
myFile.print(";");
myFile.print(analogRead(A1));
myFile.print(";");
myFile.print(analogRead(A2));
myFile.print(";");
myFile.println(analogRead(A3));
myFile.close(); // close the file
}
}
// ************* Fade backlight after inactivity timout and reset to date/time default display *************
void fadeBacklight()
{
BacklightON = false;
// fade out from max to min in increments of 1 point:
lcd.clear();

for(int fadeValue = backlight; fadeValue >= 0; fadeValue -=1) {
// Dims the backlight from the current value to 0 (OFF)
analogWrite(LEDPIN, fadeValue);
Alarm.delay(10); // wait for 10 milliseconds to see the dimming effect.

if (millis()-currentMillis > 50) { // To avoid nasty flickering of the display, do not refresh it on every cycle, keep at least 50 mS between each display refresh
digitalClockDisplay();
currentMillis = millis();
}

// Check if some button was pressed during the dimming progress
if( int buttNum = buttonPushed(BUTTONPIN) ) {
analogWrite(LEDPIN, backlight);
currentMillis = millis(); // reset of timout
BacklightON = true;
mainMenu();
break;
}
}
}

 

A programação exemplo aplica todas as funções de uma vez só. O Data Shield mostrará a data e hora e armazenará estes dados no cartão Micro-SD periodicamente. Portanto se não tiver cartão Micro-SD no suporte do Shield, este não funcionará. Você pode também mudar a data, hora, o contraste e a iluminação do LCD pelos botões do Shield.

 

Por fim, conecte o Arduino no PC, selecione a versão da sua placa Arduino (UNO, Duemilanove, etc), depois selecione a porta (COMx, ttyUSBx, ttyACMx) e clique em UPLOAD. 

Você verá o LCD acender e escrever "Data Shield v1.1 labdegaragem.com" e depois a data e a hora. Para configurar a data, clique qualquer botão para entrar no Menu Principal (exceto os botões "sel" e "rst"). No Menu Principal, irá aparecer 1.Contraste, ao apertar o botão para baixo, você verá 2.Backlight, 3.Data e 4.Hora. Selecione 4.Data e clique em "sel" para configurá-lo. Ao terminar, clique no botão em que está escrito "<" abaixo dele e voltará para o menu principal. Agora é só repetir o processo para cada item do Menu Principal para mudar o que desejar.

 

E é isso! Esperamos que tenham gostado! Caso tenham dúvidas, postem aqui mesmo neste blog! Se tiverem sugestões para tutoriais, clique aqui! Para ver outros tutoriais e projetos desenvolvidos pela equipe LdG e por outros garagistas, clique aqui e aqui, respecitvamente!

 

Referências:

http://www.labdegaragem.org/loja/index.php/31-shields/datashield.html

Biblioteca para Arduino versão 002x: Libraries_002x.zip

Biblioteca para Arduino 1.x:Libraries_1_0.zip

http://labdegaragem.com.br/loja/Example_DATASHIELD.pde

Exibições: 8733

Comentar

Você precisa ser um membro de Laboratorio de Garagem (arduino, eletrônica, robotica, hacking) para adicionar comentários!

Entrar em Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)

Comentário de Paulo Neto em 31 março 2015 às 0:16

Uma pergunta: consigo usar este shield em conjunto com um leitor de RFID?

Comentário de Fernando Garutti Moura em 10 dezembro 2013 às 8:18

Olá,

Gostaria de saber qual a especificação para o cartão microSD.

Testei com um 4GB em fat32 e não funcionou.

O cartão está funcionando normalmente no meu celular.

Abraço!

Comentário de Geovani de Souza em 30 setembro 2013 às 17:09

Boa tarde,

Estou usando o DataShield com o sketch do tutorial. Coloquei um SD de 2Gb FAT32, porém ele continua mostrando "Cartao SD falhou".

Testei o cartão com o Ethernet Shield e ele funcionou normal.

Alguma dica?

Comentário de Marcus A G da Rocha em 9 agosto 2013 às 23:28

Olá, comprei o Datashield, está funcionando perfeitamente. Porém, gostaria de saber como posso utilizar este shield para fazer a leitura de um sensor analógico, armazenar os dados e acessa-los.

Comentário de Victor Botelho em 18 julho 2013 às 17:40

Olá, comprei o Datashield do labdegaragem, porém não consegui fazê-lo funcionar.

Segui o tutorial, mas ao tentar compilar o código que engloba todas as funções do Datashield, aparecem os seguintes erros:

sketch_jul18a.ino: In function 'void setup()':
sketch_jul18a:104: error: 'RTC' was not declared in this scope
sketch_jul18a.ino: In function 'void DateSetMenu()':
sketch_jul18a:421: error: 'RTC' was not declared in this scope
sketch_jul18a.ino: In function 'void HourSetMenu()':
sketch_jul18a:513: error: 'RTC' was not declared in this scope

Com isso, fui testar o exemplo "HelloWorld", que encontra-se na biblioteca LiquidCrystal_I2C. Ao compilar esse exemplo não aparece erro algum, porém, nenhuma ação é executada. Com isso, criei um código para esse Shield, e compilei-o logo após o ter compilado o código de "HelloWorld". Para minha surpresa, usando esse código, aconteceu o que deveria ter acontecido se tivesse compilado "HelloWorld".

O código que fiz é este:

*usei 13, 12, 11 ,9 ,8 e 5 como entradas ou saídas do LCD, pois segui o que diz o Datasheet que encontra-se aqui http://www.labdegaragem.com.br/loja/datashield.pdf

#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 9, 8, 5); 

#define Luz_Fundo 5

void setup() {
lcd.begin(16, 2); 
pinMode(Luz_Fundo,OUTPUT); 
digitalWrite(Luz_Fundo,HIGH); 
}

void loop() { 
for (int i = 0; i < 12000; i++) {
lcd.scrollDisplayLeft();
delay(6000);

}

"HelloWorld" é este:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20,16,2); // set the LCD address to 0x20 for a 16 chars and 2 line display

void setup()
{
lcd.init(); // initialize the lcd 

// Print a message to the LCD.
lcd.backlight();
lcd.print("Hello, world!");
}

void loop()
{
}

Outra coisa, no tutorial diz que o Datashield não funciona se estiver sem um micro SD. Testei-o com e sem o cartão, e o resultado foi o mesmo, descrito acima...

Obrigado pela atenção

Abraço!

Comentário de Fábio Durão em 9 abril 2013 às 15:46

Ylred, este é o primeiro problema que passei, a solução está nos comentários abaixo, leia principalmente os comentários do "Lab de Garagem", depois de executar os passos dele irá conseguir dar upload no sketch, não esquente a cabeça porque algumas bibliotecas .h vão continuar na cor preto quando der um "include", mas mesmo assim funciona. Depois de executar os passos que encontrará nos posts do "Lab de Garagem", terá outros problemas, como os que eu relatei abaixo, vamos juntos tentar resolver, abraço!

Comentário de ylred braga em 9 abril 2013 às 10:43

Estou com problemas nas bibliotecas time, timeAlarm e DS1307RTC, estou usando o arduino 1.5.2 com a biblioteca 1.XXX, o compilador não reconhece estas bibliotecas .

 

 

Comentário de Fábio Durão em 5 abril 2013 às 18:25

Estou com 2 problemas:

1ª A bateria que veio é menor do que o slot, ela ficou sambando e tive que colocar um clips para segurar, não sei se perdeu a carga até porque não ficou claro qual era a polaridade, imagino que o lado maior (+) seja para cima, do contrário daria curto nas laterais, cheguei até a fazer isso errado por falta de informação. Contudo a hora nunca grava, está funcionando com as devidas alterações recomendadas, mas a hora não continua contando quando tiro a USB, as vezes ela para quando tiro a alimentação, as vezes zera, as vezes vai para o ano de 2040.

2ª "Cartão SD falhou" "Log desativado", estava em FAT16, depois formatei para FAT32 e nada, continua o problema.

Alguma ajuda?

Comentário de ylred braga em 27 março 2013 às 14:11

Estou tentando compilar o sketch do datalog  mai ele gera o seguinte erro : C:\Users\Ylred\Documents\Arduino\libraries\Time\Time.cpp: In function 'time_t now()':

C:\Users\Ylred\Documents\Arduino\libraries\Time\Time.cpp:239: error: 'millis' was not declared in this scope

Porfavor me ajude        

Comentário de ylred braga em 27 março 2013 às 14:09

Estou tentando compilar o sketch do datalog  mai ele gera o seguinte erro : C:\Users\Ylred\Documents\Arduino\libraries\Time\Time.cpp: In function 'time_t now()':

C:\Users\Ylred\Documents\Arduino\libraries\Time\Time.cpp:239: error: 'millis' was not declared in this scope

Porfavor me ajude        

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço