Pages: [1]   Go Down
Author Topic: Moved LCD to other pins and it stopted working  (Read 1210 times)
0 Members and 1 Guest are viewing this topic.
The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Quote
/*
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);
      server.begin();
 
   // 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.setCursor(0,0);
 lcd.print("     ");
 lcd.setCursor(0,0);
 lcd.print(vin, 1);
 
 lcd.setCursor(11,0);                // start cursor at charactor 11 on line 0 (first)
 lcd.print("Volts");                  
 
 // check for under voltage
 if (vin < 2.0)
 { digitalWrite (ledPin32, HIGH);  
   lcd.setCursor(0,1);
   lcd.print("  LOW WARNING!! ");
 } 
   else {
         digitalWrite (ledPin32, LOW);
        }      
         
 // check for Over voltage
 if (vin > 4.0)
 { digitalWrite (ledPin30, HIGH);  
   lcd.setCursor(0,1);
   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.setCursor(0,1);
     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");
          client.println();
          // output the value of each analog input pin          
          //for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            //client.print("analog input ");
            //client.print(analogChannel);
            //client.print(" is ");
           // client.print(analogRead(analogChannel));
           // client.println("<br />");
          //} 
          client.print("Battery Voltage ");
          client.print(vin);
          client.print(" Volts ");
          client.println("<br />");
          client.print("Status = ");
          client.print("");
          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();
  }
 //////// END ETHERNET CODE ///////////
 
delay(30);
}
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 48993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Did not know that! 
Thanks
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!
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7183
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have a current-limiting resistor on the LCD back light LED?
Logged


The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep, I even tried it with no back light.
Logged

Pages: [1]   Go Up
Jump to: