Go Down

Topic: Moved LCD to other pins and it stopted working (Read 2488 times) previous topic - next topic


I just got a new MEGA 1280 and an Ethernet shield for it and fired it up...
Worked nice with just the LCD, so I added the Ethernet Shield and ran it as a web-server.  I moved the LCD pins to 52, 40, 50, 44, 45, 46, 47 and now I can get anaything on it.  I am fairly confident it is a programing problem since this is my fist attempt.

Anyone see any problems?


LCD voltage meter and ethernet interface
with under and over voltage alarms

#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>

// LiquidCrystal display with:
    // rs on pin 52
    // rw on pin 40
    // enable on pin 50
    // d4, d5, d6, d7 on pins 44, 45, 46, 47
    //LiquidCrystal lcd(52, 40, 50, 44, 45, 46, 47);

  int analoginput = 1;     // Analog Vin for volt meter 1
  int ledPin30 = 30;       // LED to indacate over voltage
  int ledPin32 = 32;       // LED to indacate under voltage
  LiquidCrystal lcd(52, 40, 50, 44, 45, 46, 47);    // Set LCD Pins
  int count = 0;
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };      // Enter a MAC address and IP address for your controller below.
  byte ip[] = { 192,168,1, 177 };                           // The IP address will be dependent on your local network:
  Server server(80);                                        // (port 80 is default for HTTP):
  float vout = 0.0;      // set default to 0.0
  int value = 0;
  float R1 = 10000.0;    // !! resistance of R1 !!
  float R2 = 5000.0;     // !! resistance of R2 !!
  float vin = 0.0;       // vin is the caculated Input voltage if analog 1

void setup(){
    // start the Ethernet connection and the server:
      Ethernet.begin(mac, ip);
   // declaration of pin modes
     pinMode(analoginput, INPUT);
     pinMode(ledPin30, OUTPUT);
     pinMode(ledPin32, OUTPUT);
     lcd.begin(16, 2);               // fire up the LCD, it is 16 char. x 2 line

   delay(100);                       // make sure LCD is up

  // start up message (optional)
    lcd.setCursor(0,0);              // set cursor at position 0 and colum 0
    lcd.print("    REPEATER   ");    // first line of text
    lcd.setCursor(0,1);              // set cursor at position 0 and colum 1
    lcd.print("INTERFACE   v1.0");    // second line of text
    delay(2000);                     // keeps message on screen in mili sec. 1000 = 1 sec.
    lcd.clear();                     // clear the screen

void loop(){
 // read the value on analog input
 value = analogRead(analoginput);    // value (raw) from analog pin)
 vout= (value * 5.0)/1024.0;         
 vin = vout / (R2/(R1+R2));
 lcd.print("     ");
 lcd.print(vin, 1);
 lcd.setCursor(11,0);                // start cursor at charactor 11 on line 0 (first)
 // check for under voltage
 if (vin < 2.0)
 { digitalWrite (ledPin32, HIGH);  
   lcd.print("  LOW WARNING!! ");
   else {
         digitalWrite (ledPin32, LOW);
 // check for Over voltage
 if (vin > 4.0)
 { digitalWrite (ledPin30, HIGH);  
   lcd.print(" OVER VOLTAGE!");
   else {
         digitalWrite (ledPin30, LOW);
  // clear the 2nd line if ther is no alarm
  if (digitalRead(ledPin30) == LOW && (digitalRead(ledPin32) == LOW))   {
     lcd.print("                ");
  // end LCD volt meter code start ethernet ...
 // listen for incoming clients
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // 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");
          // output the value of each analog input pin          
          //for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            //client.print("analog input ");
            //client.print(" is ");
           // client.print(analogRead(analogChannel));
           // client.println("<br />");
          client.print("Battery Voltage ");
          client.print(" Volts ");
          client.println("<br />");
          client.print("Status = ");
        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
    // close the connection:
 //////// END ETHERNET CODE ///////////


The most likely cause is the wiring, did you check that the LCD worked after  moving the pins before adding the ethernet code?

If not,  try the sketch with the calls to  Ethernet.begin,  server.begin commented out. If you don't see the start-up message then double check your wiring.


The SPI pins on the Mega are 50-53. Where do all your pins fall with respect to that range?

How does the Ethernet board communicate with the Arduino? Hint: There was a reason you needed to include SPI.h.
The art of getting good answers lies in asking good questions.


The SPI pins on the Mega are 50-53. Where do all your pins fall with respect to that range?

Did not know that! 
I moved the LCD to start at pin 22 and that solved that problem, But I still had problems.
I tested the code without the Ethernet Shield and all is good.
Put it on and LCD does not work (so I thought) but I did notice faint letter... Hu
Turns out that the USB cable did not have enough power to run it all and that caused problems for the LCD.

Thanks for the help I would not have found that the shield was using pin 50-53 for a long time!


Do you have a current-limiting resistor on the LCD back light LED?
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131