I have a 16 x 2 LCD shield that I got specifically because it uses pind D4 - D8 for data, allowing me to use shields that use the higher pins (SPI)... or so I thought. By default or at least based on the code I found online, the LCD uses pin 13 for RW. This is optional. But in my code, if I use any LCD calls in the main loop, then nothing gets written to the SD card. I have removed the LCD from the Arduino Uno, and wired it manually NOT connecting anything to pin 13. The LCD uses Pins D4 - D9 and the SD uses D10 - D13. I changed the initialization routing LiquidCrystal to use the option without the RW pin and looking through the code for the Liquid Crystal routines if you do this, it should not mess with RW and again pin 13 is NOT connected, but still nothing written to the SD if I have any LCD commands in the main loop. Here is my code:
// testing how quickly can poll the 3208 ADC
#include<SPI.h>
#include<LiquidCrystal.h>
#include <SdFat.h>SdFat sd;
SdFile myFile;
const int chipSelect = 10;
int lcdpin = 9;
int adcpin = 2;LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
SPI.begin();// Set the cable select for the ADC.
pinMode(adcpin, OUTPUT);
digitalWrite(adcpin, HIGH);// Initialize SdFat or print a detailed error message and halt
// Use half speed like the native library.
// change to SPI_FULL_SPEED for more performance.
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();// open the file for write at end like the Native SD library
if (!myFile.open("speed.csv", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening speed.txt for write failed");
}
myFile.println("ADC,Time");
myFile.close();}
void loop() {
int count;
unsigned long timelog[100];
int datalog[100];// lcd.clear();
// lcd.setCursor(0,0);
// lcd.print(" Ready");
delay(2000);//for(int i = 0;1 < 3;i ++) {
for (int i = 0; i < 100; i ++) {
datalog = adcpinread(7);
_ timelog = micros();_
* delayMicroseconds(100);*
* }*
// lcd.clear();
// lcd.setCursor(0,0);
// lcd.print("counting done");
// delay (3000);
* if (!myFile.open("speed.csv", O_RDWR | O_CREAT | O_AT_END)) {
_ sd.errorHalt("opening test.txt for write failed");_
_ //lcd.setCursor(0,1);_
_ //lcd.print("Disk error:");_
_ }_
_// else {_
_// lcd.setCursor(0,1);_
_// lcd.print("test opened");_
_// } _
_ delay(3000);_
_ for (int i = 0;i < 100; i ++) {_
_ myFile.print(datalog);
myFile.print(",");
myFile.println(timelog);
Serial.print("ADC: ");
Serial.print(datalog);
Serial.print(" Time: ");
Serial.println(timelog);
}
//}
myFile.close();*_* lcd.clear();*
* lcd.setCursor(0,0);*
* lcd.print(" Done");*
* delay(50000);*
* pinMode(3, OUTPUT);*
* digitalWrite(3, HIGH);*
}int adcpinread(int channel)
{
* int adcvalue = 0;** byte transbyte = 6;*
* byte returnbyte;** digitalWrite(adcpin, LOW); // Turn on device "adcpin"*
* // Set the first byte to transfer,*
* // with with a start bit and a 1 for single ended*
* // (not differentail) and the MSB of the channel number*
* if (channel >3) {*
* transbyte = 7;*
* }*
* SPI.transfer(transbyte);** // Set the next transfer byte with the channel number*
* // minus the MSB and catch the first 4 bits of the*
* // return value*
* transbyte |= (channel << 6);*
* returnbyte = SPI.transfer(transbyte);*
* // add the first four bits of the valuse to adcvalue*
* // then shift them to the first four (of 12) bits*
* adcvalue = returnbyte & 15;*
* adcvalue = adcvalue << 8;*
* // recieve the last 8 bits and add them to adc value*
* returnbyte = SPI.transfer(0x0);*
* adcvalue += returnbyte;** //end communication with device adcpin*
* digitalWrite(adcpin, HIGH);*
* return adcvalue;*
}
[/quote]
Please help. I think I have worked around all my other problems (limited pins) by using an 8 input 12 bit ADC, but I REALLY want to have both the SD and the LCD without having to buy a different Aruduino.
Bob