hi can any one tel me if this should work.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(45, 44, 6, 43, 9, 42); // here is where you tell it what pins you want to use
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
Unfortunatly i am already using the normal pins for an SD card. my full code for my project is below. It is a data logger.
In my full code all i am trying to do is print some test text as the start for the time being.
#include <LiquidCrystal.h>
#include <SD.h>
#include <SPI.h>
#include <RTClib.h>
#include <Wire.h>
const int analogIn = A0;
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;
LiquidCrystal lcd(45, 44, 6, 43, 9, 42);
int switchState = 0;
// how many milliseconds between grabbing data and logging it. 1000 ms is once a second
#define LOG_INTERVAL 1000 // mills between entries (reduce to take more/faster data)
// how many milliseconds before writing the logged data permanently to disk
// set it to the LOG_INTERVAL to write each time (safest)
// set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to
// the last 10 reads if power is lost but it uses less power and is much faster!
#define SYNC_INTERVAL 1000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()
#define ECHO_TO_SERIAL 1 // echo data to serial port
#define WAIT_TO_START 0 // Wait for serial input in setup()
// the digital pins that connect to the LEDs
#define redLEDpin 2
#define greenLEDpin 3
// The analog pins that connect to the sensors
#define gateOpenpin 22 // digital pin 22
#define gatePhotopin 23 // digital pin 23
#define gateMotoropen 24 // digital pin 24
#define gateMotorClose 25 // digital pin 25
//int lastPhotoState = LOW;
//int lastOpenState = LOW;
RTC_DS1307 RTC; // define the Real Time Clock object
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
// the logging file
File logfile;
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
// red LED indicates error
digitalWrite(redLEDpin, HIGH);
while(1);
}
void setup(void)
{
Serial.begin(9600);
lcd.begin(16, 2);
Serial.println();
lcd.print("LCD Test");
// use debugging LEDs
pinMode(redLEDpin, OUTPUT);
pinMode(greenLEDpin, OUTPUT);
pinMode(gateOpenpin, INPUT);
pinMode(gatePhotopin, INPUT);
pinMode(gateMotoropen, INPUT);
pinMode(gateMotorClose, INPUT);
#if WAIT_TO_START
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START
// initialize the SD card
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(10, 11, 12, 13)) {
error("Card failed, or not present");
}
Serial.println("card initialized.");
Serial.println("GateLogger By Kinetic Automation"); // company branding
// create a new file
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
if (! logfile) {
error("couldnt create file");
}
Serial.print("Logging to: ");
Serial.println(filename);
// connect to RTC
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
logfile.println("Site Address:,7 Ha'penny Dell Waterlooville "); // Type in the site address hear
logfile.println("Site ID, 001:");
logfile.println(" Date, Time, LOG ENTRY");
#if ECHO_TO_SERIAL
Serial.println(" Date , Time , LOG ENTRY");
#endif //ECHO_TO_SERIAL
}
void loop(void)
{
DateTime now;
// delay for the amount of time we want between readings
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
digitalWrite(greenLEDpin, HIGH);
// fetch the time
now = RTC.now();
logfile.print(now.day(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.year(), DEC);
logfile.print(" ");
logfile.print(", ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
#if ECHO_TO_SERIAL
Serial.print(now.day(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.year(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL
switchState = digitalRead(gateOpenpin);
if (switchState == HIGH)
{
logfile.print(", ");
logfile.print("-OPEN-");
Serial.print("-OPEN-");
}
switchState = digitalRead(gatePhotopin);
if (switchState == HIGH)
{
logfile.print(", ");
logfile.print("-Photo Cell-");
Serial.print("-Photo Cell-");
}
switchState = digitalRead(gateMotoropen);
if (switchState == HIGH)
{
logfile.print(", ");
logfile.print("-Gate Opening-");
Serial.print("-Gate Opening-");
}
static int timerRunning = 0;
static int startTime = 0;
static int endTime = 0;
static int elapsedTime = 0;
if (timerRunning == 0 && digitalRead(gateMotoropen) == HIGH){
startTime = millis(); // micros() for really short events
timerRunning = 1;
}
if (timerRunning == 1 && digitalRead (gateMotoropen) == LOW){
endTime = millis();
timerRunning = 0; // reset for next capture
elapsedTime = endTime - startTime;
if (elapsedTime >= 10000)
{
Serial.print ("Gate Fully Open");
}
else
{
Serial.print ("-Obstacle Detect on Opening ");
}
Serial.print ("(Time for Gate to Open = ");
Serial.print (elapsedTime);
Serial.print ("mS)");
logfile.print(", ");
logfile.print(elapsedTime);
}
switchState = digitalRead(gateMotorClose);
if (switchState == HIGH)
{
logfile.print(", ");
logfile.print("-Gate Closing-");
Serial.print("-Gate Closing-");
}
static int timer1Running = 0;
static int startTime1 = 0;
static int endTime1 = 0;
static int elapsedTime1 = 0;
if (timer1Running == 0 && digitalRead(gateMotorClose) == HIGH){
startTime1 = millis(); // micros() for really short events
timer1Running = 1;
}
if (timer1Running == 1 && digitalRead (gateMotorClose) == LOW){
endTime1 = millis();
timer1Running = 0; // reset for next capture
elapsedTime1 = endTime1 - startTime1;
if (elapsedTime1 >= 10000)
{
Serial.print ("Gate Fully Closed");
}
else
{
Serial.print ("-Obstacle Detect on Closing ");
}
Serial.print ("(Time for Gate to Close = ");
Serial.print (elapsedTime1);
Serial.print ("mS)");
logfile.print(", ");
logfile.print(elapsedTime1);
}
RawValue = analogRead(analogIn);
Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);
Serial.print("-(Aux Current = "); // shows the voltage measured
Serial.println(Amps,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("Amps)");
delay(1000);
logfile.print(", ");
logfile.print(Voltage,3);
logfile.print(", ");
logfile.print(Amps,3);
logfile.println();
#if ECHO_TO_SERIAL
Serial.println();
#endif // ECHO_TO_SERIAL
digitalWrite(greenLEDpin, LOW);
// Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
// which uses a bunch of power and takes time
if ((millis() - syncTime) < SYNC_INTERVAL) return;
syncTime = millis();
// blink LED to show we are syncing data to the card & updating FAT!
digitalWrite(redLEDpin, HIGH);
logfile.flush();
digitalWrite(redLEDpin, LOW);
}