Go Down

Topic: Issue with Sainsmart 1602 LCD Sheild and Adafruit Datalogging Sheild (Read 20 times) previous topic - next topic

wxmaking

Hello all,

I attempting to save weather data on the Adafruit Data logger shield: http://www.adafruit.com/products/1141 while displaying said data live on the Sainsmart 1602 LCD Shield, which is all currently being controlled by a Uno R3 board.

Individually between the two shields (so only one is attached to the Arduino Uno board) I can get both to work, but when I stack them together I experience a issue with the LCD shield. The LCD stays in the no data blank stat throughout the whole run of the sketch, and will flicker every time the data logger shield flashes its red LED which indicates data was written to the SD card. Here is the sketch that is loaded onto the Uno:

--------------------------------------------------------------------------------------------------
//code used to print and save weather data, combines code from SD data logger test and LCD display Test.
//Started on 12-10-14

#include <Wire.h>     //I2C comunication library
#include "RTClib.h"  //Real time clock library, downloaded
#include <SD.h>      //SD library
#include <LiquidCrystal.h>  //LCD library

int tmp102Address = 0x48;  //Temp sensor Hex address
RTC_DS1307 RTC;            //Address from the RTC library
const int chipSelect = 10;  //chip selection pin for SD car
LiquidCrystal lcd(8,9,4,5,6,7);  //pins used for controlling LCD display
//File logfile;

void setup(){
  //Start up everything
  lcd.begin(16,2);
  Wire.begin();
  Serial.begin(9600);
  RTC.begin();
  pinMode(10, OUTPUT);
  //check SD car is working properly
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop(){
  //Pull data and time and print to Serial communication, comment out serial communications once code is working
  DateTime now = RTC.now();
  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);
  Serial.print(';');

  //Pulls temp data from sensor than print to Serial communication, comment out serial communication once code is working
  float celsius = getTemperature();
  float fahrenheit = (1.8*celsius)+32;
  float kelvin = celsius + 273.15;
  Serial.print(fahrenheit);
  Serial.print('F');
  Serial.print(';');
  Serial.print(celsius);
  Serial.println('C');
  Serial.println(' ');
 
  //Print date, time, and data to SD card
  File dataFile = SD.open("temp.txt",FILE_WRITE);
  if (dataFile){
    dataFile.print(now.year(), DEC);
    dataFile.print('/');
    dataFile.print(now.month(), DEC);
    dataFile.print('/');
    dataFile.print(now.day(), DEC);
    dataFile.print(';');
    dataFile.print(now.hour(), DEC);
    dataFile.print(':');
    dataFile.print(now.minute(), DEC);
    dataFile.print(':');
    dataFile.print(now.second(), DEC);
    dataFile.print(';');

    dataFile.print(fahrenheit);
    dataFile.print(';');
    dataFile.println(celsius);
    dataFile.close();
  }
  else{
    Serial.println("error opening temp.txt");
  }
 
  //Print temp data to LCD display
  lcd.clear();
  lcd.print('Temp:');
  lcd.setCursor(0,2);
  lcd.print(celsius);
  lcd.setCursor(5,2);
  lcd.print('C');
  lcd.setCursor(9,2);
  lcd.print(fahrenheit);
  lcd.setCursor(15,2);
  lcd.print('F');
  //cycle ~10 seconds
  delay(10000);
}

  //function used to calculate temp using bineary math
  float getTemperature(){
  Wire.requestFrom(tmp102Address,2);

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  int TemperatureSum = ((MSB << 8 ) | LSB) >> 4;

  float celsius = TemperatureSum*0.0625;
  return celsius;
}
--------------------------------------------------------------------------------------------------

The issue to me seems like I'm over lapping communication pins between the LCD display and the Data logger shield, but I have looked over this a dozen times and I do not see that as a issue. Also, if that was the case I would expect both shields to fail, not just one working and the other fails.

Anyone have a idea what is happening, I'm a bit lost here.

cattledog

I believe that there is a conflict on digital pin 10 which is the spi chip select for the data logger shield and the backlight control for the lcd button shield.

Quote
The LCD stays in the no data blank stat throughout the whole run of the sketch, and will flicker every time the data logger shield flashes its red LED
Can you confirm that the lcd is blank because the backlight is not on?

If this is the source of the problem, I think you are going to have to modify one or the other of the shields. I'm not sure which is the better way to go. On the lcd shield, if you don't turn the backlight on and off, you could disconnect pins 15/16 from the transistor and pin 10 backlight control and power them from jumper wires with a resistor. On the data logger shield you can cut the trace to pin 10 from the cs pad. Connect that pad to another pin, and then change the cs pin call in the sketch and maybe the library. If you Google around, you can find some documentation on that process.

But before you start hacking, let's confirm that the pin 10 conflict is the source of your problem.

Go Up