Go Down

Topic: Ethernet Shield + SD + LCD Serial (Read 535 times) previous topic - next topic

bruguera

First sorry but not sure where to open the thread.

Im working with ethernet+sd+lcd but having problems with this example:

Code: [Select]
#include <Wire.h>
#include <SD.h>
//#include <LiquidCrystal_I2C.h> //Libreria pantalla LCD
#include <SPI.h>
#include <Ethernet.h>


EthernetServer server(80);
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;
//LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
void setup()
{
// lcd.begin(20,4);
// Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  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);
  digitalWrite(10, HIGH);
 
 
   Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop()
{
 
   // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");       
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
//    lcd.setCursor(0,0); //Situarse en linea 0 caracter 0
//  lcd.print(dataString);
  } 
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}


When the LCD lines are commented it works good, without comments the program does not work.

Im pretty sure its because the SD uses pin 4 for SS, and LCD use the same pin for SDA.

So my question its, there is a way to change this pins (maybe the SDA for LCD library to another analog port?)

bruguera

Ok, replying to myself http://forum.arduino.cc/index.php/topic,37243.0.html this looks like bad news.

PaulS

Quote
this looks like bad news.

Why? That thread is referring to the true I2C pins (analog pin 4 and analog pin 5) on a different board. It has nothing to do with the digital pin.

A link to the library you are using, and/or some meaningful names for the arguments, not magic numbers, in the call to the constructor would be useful.

SurferTim

Adding to PaulS, you should post links to the hardware. There are at least a couple models of ethernet shield and a few models of LCD displays.

Don't give up so easily!

bruguera


Adding to PaulS, you should post links to the hardware. There are at least a couple models of ethernet shield and a few models of LCD displays.

Don't give up so easily!



Using Arduino UNO And Ethernet shield wiz 5100

There is a way to not use for example the library of LCD and configure by hand the port used for SS?.

Sorry no idea on how to solve the problem

SurferTim

#5
Sep 06, 2013, 03:32 am Last Edit: Sep 06, 2013, 03:55 am by SurferTim Reason: 1
Quote
Using Arduino UNO And Ethernet shield wiz 5100

You are not using a LCD serial display?

You should post a link to that device.

PaulS

Quote
There is a way to not use for example the library of LCD and configure by hand the port used for SS?.

Since SS (Slave Select) is a SPI term, not a Serial term, you really WILL have to post a link the LCD you have.

You've referred to it as a Serial LCD, you've use SPI terms to talk about it, and you are using the I2C version of the library. These are 3 exclusive means to talk to devices.

bruguera


Quote
There is a way to not use for example the library of LCD and configure by hand the port used for SS?.

Since SS (Slave Select) is a SPI term, not a Serial term, you really WILL have to post a link the LCD you have.

You've referred to it as a Serial LCD, you've use SPI terms to talk about it, and you are using the I2C version of the library. These are 3 exclusive means to talk to devices.


Oh sorry i forgot that info. Im using 4x20 LCD exactly this model http://arduino-info.wikispaces.com/LCD-Blue-I2C with the library from here https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

SurferTim

Try moving the lcd up one pin. Use D5-D8 instead of D4-D7.
Code: [Select]
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 5, 6, 7, 8, 3, POSITIVE);


Go Up