Arduino WiFI and LCD&Keymade not working

The LCD and Keypad Shield gives you a handy 16-character by 2-line display, 5 buttons and a controllable backlight.
mirrornode
Posts: 4
Joined: Thu May 22, 2014 3:38 am

Arduino WiFI and LCD&Keymade not working

Post by mirrornode » Thu May 22, 2014 8:50 am

G'day,

I am attempting to integrate the Freetronics LCD shield into my remote monitoring project.
I'm using a mega 2560 with an Arduino WiFi shield connected to the headers. As the Freetronics LCD shield does not connect directly to the WiFI shield (pin conflict) i have connected it via jumpers from the abundant digital I/O specifically pins 42, 44, 46, 48 and 50.

When my code runs in full the LCD does not display.
When I comment out the WiFi code the LCD functions correctly.

Is this a SPI bus issue?? Any ideas out there to get these two shield to integrate together?

Cheers,

LAS

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Arduino WiFI and LCD&Keymade not working

Post by andrew » Thu May 22, 2014 11:01 pm

Have you change the following line in your sketch to allow for the different digital pins used with the LCD? You mentioned 5 pins but it needs six.

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

mirrornode
Posts: 4
Joined: Thu May 22, 2014 3:38 am

Re: Arduino WiFI and LCD&Keymade not working

Post by mirrornode » Fri May 23, 2014 2:22 am

Apologies, i had left out pin 40 on my original post. My LCD is - LiquidCrystal lcd( 40, 42, 44, 46, 48, 50 );

I have also updated the firmware on the Arduino WiFi shield.

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Arduino WiFI and LCD&Keymade not working

Post by andrew » Fri May 23, 2014 5:02 am

It could be power issues, if you're only running from USB please try with 9~12V into the DC socket on the EtherMega.

mirrornode
Posts: 4
Joined: Thu May 22, 2014 3:38 am

Re: Arduino WiFI and LCD&Keymade not working

Post by mirrornode » Sat May 24, 2014 6:25 am

Thanks for the reply. I have already tried the external power supply. 12VDC into the jack. Still the same issue. Good point to mention is the LCD shield behaves as described in the trouble shooting as it has low voltage when used in conjunction with the WiFi shield.
I have taken voltage measurements from the LCD shield which has 5VDC.

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Arduino WiFI and LCD&Keymade not working

Post by andrew » Sun May 25, 2014 5:28 am

Aha. SPI is on digital 50, 51, and 52 with the Mega - used by the WiFi, try other pins for your LCD.

mirrornode
Posts: 4
Joined: Thu May 22, 2014 3:38 am

Re: Arduino WiFI and LCD&Keymade not working

Post by mirrornode » Mon May 26, 2014 6:49 am

Tested using different pin assignment ( LiquidCrystal lcd( 30, 32, 40, 38, 36, 34 ); ) but still no success. Proved LCD works on current pin assignment with the basic "hello world" but still experiencing same issue mentioned above.

Check out the code below. I have a feeling you might recognize parts of it.

Code: Select all

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <SPI.h>
#include <Wire.h>
#include <LiquidCrystal.h>

// lcd display
LiquidCrystal lcd( 30, 32, 40, 38, 36, 34 );

//pressure Tx values
int sensorValue = A0;
int sensorValueX = A0;
int constrainedValue = 0;
int constrainedValuePressure = 0;
int PressureValuePSI = 0;
int PressureValuemmH2O = 0;
int tankLevel = 0;
int sensorRAW = 0;
int pressuresensorRAW = 0;
#define TANK_SENSOR 0

// Scalling of 0-1023 counts with respect to 0V-5V
#define TANK_EMPTY 500 // 0
#define TANK_FULL 1023 //1023
#define TxLRV_PSI 0
#define TxURV_PSI 25
#define TxLRV_mmH2O 0
#define TxURV_mmH2O 17577

IPAddress ip(10, 0, 0, 20);

// Output testing pin assignment
int pumpStart = 5;
int pumpStop = 6;
byte controlbyte; // 8 bit data 


// Access to WiFi network
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
int keyIndex = 0;
int status = WL_IDLE_STATUS;

WiFiServer server(80);


void setup() {
  lcd.begin(16, 2); // testing lcd
  lcd.print("testing"); // testing lcd
  Serial.begin(9600);
  analogReference(DEFAULT);
  pinMode(pumpStart, OUTPUT);
  digitalWrite(pumpStart, LOW);
  pinMode(pumpStop, OUTPUT);
  digitalWrite(pumpStop, LOW);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
 
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while(true);
  }
  WiFi.config(ip);
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    delay(2000); // allow time for program to cycle
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();
  delay(100);
  // you're connected now, so print out the status:
  printWifiStatus();
}

void loop() {
  // listen for incoming clients
AutoControl();
ManualControl();
IrrigationControl();
PressureSensor();
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    String currentLine = "";
    // an http request ends with a blank line
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        if (c == '\n') {
          if (currentLine.length() == 0){
          // 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: 30");  // refresh the page automatically every 30sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          
          sensorValue = analogRead( TANK_SENSOR );
          constrainedValue = constrain( sensorValue, TANK_EMPTY, TANK_FULL );
          tankLevel = map( constrainedValue, TANK_EMPTY, TANK_FULL, 0, 100 );  
        
          client.print( "<html><center>" );
          client.print( "<h1>Skynet Potable Water Level</h1>" );
          client.print( "<table width=200 cellspacing=0 cellpadding=0 border=1>" );
          client.print( "<tr><td bgcolor=#cccccc height=" );
          client.print( 2 * (100 - tankLevel) );
          client.print( "></td></tr>" );
          client.print( "<tr><td bgcolor=#3333aa height=" );
          client.print( 2 * tankLevel );
          client.print( "></td></tr>" );
          client.print( "</table><br><br>" );
          client.print( "<h2>" );
          client.print( tankLevel );
          client.print( "&#37;" );
          client.print( " water level</h2>" );          
          client.print("System Pressure: ");
          client.print(PressureValuePSI);
          client.print( "PSI - " );
          client.print(PressureValuemmH2O);
          client.print( "mmH2O" );
          client.print( "</center></html>" );
          client.print("<br><html><center>");
          client.print("<h3>");
          client.print("Pump Motor Controls</h3>");
          client.print("<a href=\"/H\"><button> AUTO </button></a>");
          client.print("<a href=\"/L\"><button>MANAUL</button></a>");
          client.print("<a href=\"/Y\"><button>IRRIGATION</button></a><br>");
          client.print("<a href=\"/T\"><button>Man. START</button></a>");
          client.print("<a href=\"/M\"><button>Man. STOP </button></a><br>");
          client.print("<a href=\"/X\"><button>Irr. START</button></a>");
          client.print("<a href=\"/Z\"><button>Irr. STOP </button></a><br>");
          client.print("<h4>");
         
client.print("Annunciator Panel</H4>");
          client.print("<table border='1' cellpadding='5' cellspacing='0'>");
 client.print(" <tr>");
          if(controlbyte == 1){
   client.print(" <td style='background-color:#00FF00;'>AUTO</td>");
 }
           else{
   client.print(" <td style='background-color:#D8D8D8;'>AUTO</td>");
 }
         if(controlbyte == 1){
   client.print(" <td style='background-color:#D8D8D8;'>MANUAL</td>");
 }
         else{
   client.print(" <td style='background-color:#00FF00;'>MANUAL</td>");
 }        
  client.print("</tr>");
  client.print("<tr>");
        if(controlbyte == 11){
   client.print(" <td style='background-color:#00FF00;'>Pump Running</td>");
 }
           else{
   client.print(" <td style='background-color:#D8D8D8;'>Pump Running</td>");
 }
        if(controlbyte == 11){
   client.print(" <td style='background-color:#D8D8D8;'>Pump Stopped</td>");
 }
           else{
   client.print(" <td style='background-color:#FF0000;'>Pump Stopped</td>");
 }
   client.print("</tr>");
  client.print("<tr>");
        if(controlbyte == 21){
   client.print(" <td style='background-color:#00FF00;'>Irr. Running</td>");
 }
           else{
   client.print(" <td style='background-color:#D8D8D8;'>Irr. Running</td>");
 }
        if(controlbyte == 21){
   client.print(" <td style='background-color:#D8D8D8;'>Irr. Stopped</td>");
 }
           else{
   client.print(" <td style='background-color:#FF0000;'>Irr. Stopped</td>");
 }
  client.print("</tr>");
client.print("</table>");
           client.print("</center></html>");           
           client.println("</html>");
          break;
          }
          else{
            currentLine = "";
          }
        }
        
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLine += c;
        }
        // output code
        if (currentLine.endsWith("GET /H")) {
        controlbyte = B00000001; // AUTO CNT
        }
        if (currentLine.endsWith("GET /L")) {
        controlbyte = B00001010;  //MANUAL CNT
        }
        if(currentLine.endsWith("GET /T") && controlbyte == 10){
        controlbyte = B00001011;   //MAN START
        }
        if(currentLine.endsWith("GET /M") && (controlbyte ==10 || controlbyte == 11)){
        controlbyte = B00001100;   // MAN STOP
        }
        if(currentLine.endsWith("GET /Y")){
        controlbyte = B00010100;   // Irr. mode
        }
        if(currentLine.endsWith("GET /X") && controlbyte == 20){
        controlbyte = B00010101; //Start Irr.
        }
        if(currentLine.endsWith("GET /Z") && (controlbyte == 20 || controlbyte ==21)){
        controlbyte = B00010110; // Stop Irr.
        }
      }
    }
    // give the web browser time to receive the data
    delay(1000);
   
    // close the connection:
   client.stop();
   Serial.println("client disonnected");
  }
}


void printWifiStatus() {
  delay(1000);
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

int AutoControl(){
  sensorRAW = analogRead(sensorValueX);
    if(controlbyte == 1){
      if(sensorRAW <= TANK_EMPTY){
      digitalWrite(pumpStart, HIGH);
      digitalWrite(pumpStop, LOW);
      }
      if(sensorRAW >= TANK_FULL){
      digitalWrite(pumpStop, HIGH);
      digitalWrite(pumpStart, LOW);
      }
    }
    Serial.println(sensorRAW);// for testing. remove on final rev.
    delay(1000);// for testing. remove on final rev.
    Serial.println(controlbyte);// for testing. remove on final rev.
    delay(1000);// for testing. remove on final rev.
}


int ManualControl(){
  if(controlbyte == 11){
      digitalWrite(pumpStart, HIGH);
      digitalWrite(pumpStop, LOW);
  }
  if(controlbyte == 12){
      digitalWrite(pumpStop, HIGH);
      digitalWrite(pumpStart, LOW);
  }
}

int IrrigationControl(){
  sensorRAW = analogRead(sensorValueX);
  if(controlbyte == 21 && sensorRAW < TANK_FULL){//manual start
      digitalWrite(pumpStart, HIGH);
      digitalWrite(pumpStop, LOW);
  }
  if(controlbyte == 22 || sensorRAW == TANK_FULL){ // manual stop
      digitalWrite(pumpStop, HIGH);
      digitalWrite(pumpStart, LOW);
  }
}
int PressureSensor(){
  pressuresensorRAW = analogRead(sensorValueX);
  constrainedValuePressure = constrain(pressuresensorRAW, 0, 1023 );
  PressureValuePSI = map(constrainedValuePressure, 0, 1023, TxLRV_PSI, TxURV_PSI); 
  PressureValuemmH2O = map(constrainedValuePressure, 0, 1023, TxLRV_mmH2O, TxURV_mmH2O);
}


angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Arduino WiFI and LCD&Keymade not working

Post by angusgr » Wed May 28, 2014 12:06 am

Hi mirrornode,

Sorry to hear it's still not working.

What exactly do you see on the display if you run the sketch you just posted? Totally blank display, black squares, or something else?

If you simplify the setup() and loop() functions in your sketch to just this:

Code: Select all

 void setup() {
      lcd.begin(16, 2); // testing lcd
      lcd.print("testing"); // testing lcd
 }

 void loop() {

 }
Do you see the correct "testing" output, or do you have to strip out some of the code above this as well? Do you have to actually unplug the Wifi shield before the LCD works?

Finally, can you post a photo of your wiring setup? Are you very sure there are no spurious connections, especially to the SPI pins?

Sorry for the all questions, hopefully we can get to the bottom of this.

- Angus

moonerj2
Posts: 11
Joined: Sun Jun 08, 2014 11:44 pm

Re: Arduino WiFI and LCD&Keymade not working

Post by moonerj2 » Thu Jun 12, 2014 8:19 am

i have a similar issue.

the plan is to run a Race Start Controller , with currently the following
DHT > Temp > pin 22
RTC > Time > pin A6,A7
Relay > to switch 12V circuits > 23, 24,25,26
Buzzer > 6V runs ok on 5V > 27

and LCD > using LiquidCrystal(31,30,35,34,33,32)
Backlight controlled by pin 36 and buttons to A0 ,
this is for users to change menu settings

and the DMD on the following, to display a count down, time and temp
Aref > Aref
Gnd > Gnd
pin 13 > pin 52
pin 12 > pin 50
pin 11 > pin 51
pin 10 > pin 53
pin 9 > pin 9
pin 8 > pin 8
pin 7 > pin 7
pin 6 > pin 6

everything works ok on there own , LiquidCrystal(31,30,35,34,33,32) works but the LCD library doesn't work as in the " form " demo in "examples","LCD". which demonstrates the use of menus.
As in
# include LCD.h
Lcd.lcd()

Any advice would be greatly accepted.
cheers richard

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Arduino WiFI and LCD&Keymade not working

Post by angusgr » Thu Jun 12, 2014 11:09 pm

moonerj2 wrote: everything works ok on there own , LiquidCrystal(31,30,35,34,33,32) works but the LCD library doesn't work as in the " form " demo in "examples","LCD". which demonstrates the use of menus.
As in
# include LCD.h
Lcd.lcd()
Hi Richard,

Sounds like an interesting project, lots of components!

When you say everything works OK on its own, does this include the LiquidCrystal library with the LCDKeypad display? Do some of the examples work but not others? When you say the "form" demo doesn't work, what exactly happens - does the screen work and not the buttons, or vice versa, or nothing happens at all? Please be as specific as you can.

- Angus

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest