LCD + SD + RTC
Moderators: adafruit_support_bill, adafruit

LCD + SD + RTC

by bmco2n on Sat Mar 02, 2013 4:32 pm

Dear Support,
Your new tutorial designs are impressive and easy to follow. Congratulations. :D
I"m using an Arduino wireless SD shield (without the Xbee) atop a UNO.
I've managed to get the LCD to work on one sketch that senses movement. Building this to use the SD card and RTC presents two problems:
This sketch is supposed to detect movement (PIR) and just count it as a "1". It compiles and prints to the SD card OK, but the two problems are:
1) The "LOGGERnn" increments as 01, 21, 41, etc.
An error msg appears:"gnu.io.RXTXPort$MonitorThread.run(RXTXPort.
java:1575) Error inside Serial.serialEvent()

java.io.IOException: Bad file descriptor in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available
(RXTXPort.java:1532)
at processing.app.Serial.serialEvent(Serial.java:258)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
I have no idea what this means, since wiring is OK (see below).

2) The LCD 16X2 display doesn't start at (0,1) and doesn't display "count" that should increase by "1" each event. Instead, a letter P or - or 0 appears at (13, 1) and (14, 1), changing at each event. Trying different lcd.setCursor(y, x) doesn't affect anything. Another PIR sketch does work OK without code for the SD card and Millis instead of RTC. Is the sketch too ambitious?
Code: Select all | TOGGLE FULL SIZE
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12) ;
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
RTC_Millis RTC;
File myFile;
void error(char *str)
{
  Serial.print("error: ");
  Serial.print(str);
}
const int chipSelect = 4;
const int inputPin = 2;
long count = 0;
int pirState = LOW;
//=====================SETUP====================================
void setup() {
  Serial.begin(9600);
  Wire.begin();
  RTC.begin(DateTime(__DATE__,__TIME__));
  pinMode(inputPin, INPUT);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting
  //begins with 0):


  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Good Morning");

  //================SD card ============
  Serial.print("Starting SD card ----");
  pinMode(4, OUTPUT);
  if(!SD.begin(chipSelect)) {
    Serial.println("Card Failed");
    while(1);
  }
  Serial.println("Card OK");
  delay(100);

  char filename[] = "LOGGER00.CSV";
  delay(100);
  for (uint8_t i=0; i<100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = 1%10 + '0';
    if (! SD.exists(filename)){
      myFile = SD.open(filename, FILE_WRITE);
      break;
    }
  }
  if(!myFile) {
    error("couldn't create file");
  }
  //===================Print Header++++++++++++++++++++++
  Serial.println();
  Serial.print("LOGGER FILE...");
  Serial.println(filename);
  DateTime now = RTC.now();
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.println(now.day(), DEC);
  Serial.println("Time  PIR");
  if(myFile){
    myFile.print(now.year(), DEC);
    myFile.print("/");
    myFile.print(now.month(), DEC);
    myFile.print("/");
    myFile.println(now.day(), DEC);
    myFile.println("Time  PIR");
  }
}

//=========================LOOP===============================
void loop() {
 
 
  pirState = digitalRead(inputPin);
 
  if (pirState == HIGH) {
    count ++;
    lcd.setCursor(0, 1);
    lcd.print(count);
    DateTime now = RTC.now();
    Serial.print(now.hour(), DEC);
    Serial.print(now.minute(), DEC);
    Serial.print(".");
    Serial.print(now.second(), DEC);
    Serial.print("   ");
    Serial.println("1");
    if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);
   
    }

    if(myFile){
      myFile.print(now.hour(), DEC);
      myFile.print(now.minute(), DEC);
      myFile.print(".");
      myFile.print(now.second(), DEC);
      myFile.print("   ");
      myFile.println("1");
      myFile.flush();
    }
    if(pirState == HIGH) {
      pirState = LOW;
    }

    delay(5500);

  }


}
bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: LCD + SD + RTC

by adafruit_support_bill on Sun Mar 03, 2013 10:37 am

The Java errors are from the Arduino IDE/Java runtime. Sometimes those go away if you restart. In extreme cases the install may have been corrupted and you will need to re-install.

The LCD problem sounds like it could be a marginal connection somewhere. Is this on a breadboard? If so, re-seat all your connections and make sure that the contacts grip the jumpers securely.
User avatar
adafruit_support_bill
 
Posts: 31771
Joined: Sat Feb 07, 2009 10:11 am

Re: LCD + SD + RTC

by bmco2n on Mon Mar 04, 2013 3:01 pm

Hi Forum,

Thanks so much for the comments about re-installing the Arduino library as a remedy for my SD logging problem. I"ll try starting over on the installations. I'll let you know the result.

I'm embarrassed to say that I didn't ground the CdS light resistor and now it works fine. Your wiring diagram was really good, but I missed the ground through the resistor. :oops:
bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm