Yet Another LCD and Ethernet Conflict Post For Help...

So, I’ve been dealing with this conflict problem for a couple of weeks now, and have done a variety of things to try and address it up to an including buying new LCD shields. Here’s my sad song…

Using a genuine Arduino Mega, a DFRobot Ethernet Shield (W5200) V1.1, and a Freetronics 16x2 LCD Shield. Using the Mega and the Ethernet shield works just fine. Using the Mega and the Freetronics works just fine. Using all three stacked together works just fine, if you use separate sketches that don’t try to access both shields. If you combine the two working sketches, problems abound…

The Ethernet Shield claims it only uses D13, D12, D11, D10, and D4 if you use the card slot.
The Freetronics LCD claims it onlyy uses A0 (Buttons), D3 (Backlight), D4, D5, D6, D7, D8 and D9.

I bought the Freetronics shield because it did NOT use D10 for backlight, which was conflicting with the ethernet shield using a different LCD shield.

Anyway… The following code is compiled and loaded…

 Testing Freetronics LCD with Keypad Shield & DFRobot Ethernet Shield W5200 V1.1 Attaching to MySQL

 LCD Shield Info
 Pins used by LCD & Keypad Shield:
   A0: Buttons, analog input from voltage ladder
   D4: LCD bit 4
   D5: LCD bit 5 
   D6: LCD bit 6 
   D7: LCD bit 7 
   D8: LCD RS
   D9: LCD E
   D3: LCD Backlight (high = on, also has pullup high so default is on)
/*Serial, Ethernet and MySQL Includes */
#include <SPI.h>
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
LCD Includes
#include <Wire.h>
#include <LiquidCrystal.h>
LCD Defines
// Pins in use
#define BUTTON_ADC_PIN           A0  // A0 is the button ADC input
#define LCD_BACKLIGHT_PIN        3  // D3 controls LCD backlight
 Init the LCD library with the LCD pins to be used
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );   //Pins for Freetronics 16x2 LCD shield. ( RS, E, LCD-D4, LCD-D5, LCD-D6, LCD-D7 )
//LiquidCrystal lcd( 8, 9, 1, 5, 6, 7 );   //Pins for Freetronics 16x2 LCD shield. ( RS, E, LCD-D4, LCD-D5, LCD-D6, LCD-D7 )
/* Serial, Ethernet, and MySQL set up code */
// Assign psuedo MAC address to Ethernet Shield
// Note, if this changes then my DHCP network reservation IP address will not work
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xCE };
// Create needed DB connection objects and parms
IPAddress server_addr(192,168,1,100);  // IP of the Raspberry Pi MySQL Server
char user[] = "arduino";               // MySQL user login username
char password[] = "XXXXXXXX";        // MySQL user login password
// Build simple dummy test insert
char INSERT_SQL[] = "INSERT INTO welldb.well_tank (inches,gallons) VALUES (50,1234.56)";
//Establish Ethernet and MySQL objects
EthernetClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
  //button adc input
  pinMode( BUTTON_ADC_PIN, INPUT );         //ensure A0 is an input
  digitalWrite( BUTTON_ADC_PIN, LOW );      //ensure pullup is off on A0
  //lcd backlight control
  digitalWrite( LCD_BACKLIGHT_PIN, HIGH );  //backlight control pin D3 is high (on)
  pinMode( LCD_BACKLIGHT_PIN, OUTPUT );     //D3 is an output
  //set up the LCD number of columns and rows: 
  lcd.begin( 16, 2 );
  //Print some initial text to the LCD.
  lcd.setCursor( 0, 0 );   //top left
  lcd.print( "Freetronics 16x2" );
/* Serial, Ethernet and MySQL */
 while (!Serial); // wait for serial port to connect
 Serial.println("Starting Ethernet Connection...");
 if (Ethernet.begin(mac_addr)) {
   Serial.print("Ethernet Connected...");
 else {
   Serial.println("Ethernet Connection Failed!!!");
 Serial.println("Starting MySQL Connection...");
 if (conn.connect(server_addr, 3306, user, password))
   Serial.println("MySQL Connected...");
   Serial.println("MySQL Connection Failed!!!");

void loop() {
  /* Ethernet and MySQL */
  delay(2000); //Wait 2 seconds so not writing to DB like crazy
  Serial.print("Recording data.");
  // Initiate the query class instance
  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
  // Execute the query
  // Delete the cursor to free up memory
  delete cur_mem;
  //Debug A
  Serial.print("StepA ");
  byte timestamp;
  //Debug B
  Serial.print("StepB ");
  // print the number of seconds since reset (two digits only)
  timestamp = ( (millis() / 1000) % 100 );   //remainder of divide-by-100, keeps value to 0-99 even when result > 100
  //Debug C
  Serial.print("StepC ");
  lcd.setCursor( 14, 1 );
  lcd.print( timestamp, DEC );
  //Debug D
  Serial.print("StepD ");

I see the following on the Serial Monitor

21:03:43.763 -> Starting Ethernet Connection...
21:03:49.019 -> Ethernet Connected...
21:03:51.026 -> Starting MySQL Connection...
21:03:54.478 -> Connected to server version 5.5.5-10.1.37-MariaDB-0+deb9u1
21:03:54.478 -> MySQL Connected...
21:03:56.471 -> Recording data.
21:03:57.489 -> StepA
21:03:57.522 -> StepB
21:03:57.522 -> StepC
21:03:57.522 -> StepD
21:03:59.532 -> Recording data.
21:03:59.532 ->

The LCD and debug displays show that I can write to the LCD for the initial display setup (i.e. I see Freetronics 16X2 on the LCD, then my ethernet connection work (I get a DHCP IP assigned), and then I connect to the DB, and write a test record to the DB. All this works just fine. But right after Debug step C I try and update the LCD, and that then kills the ethernet connection (Step D shows I’ve lost my IP).

I initially thought that because Pin 4 is SS for the micro card that writing to the LCD, which also maps D4 was messing around with the ethernet card and causing it to go into card write mode. So, I changed the LCD set up to use D1 rather than D4. That did not help. I then tried several other mappings for the LCD and they all had the same result.

The DFRobot site has very little info on the W5200 based ethernet shield that I can use to figure out what all the pins it uses are doing so that is a dead end for me. I’ve ordered two genuine Arduino ethernet cards and hope that will solve my problem (at least this problem), but I’d really like to learn and understand why this is not working, and I’m at the end of my current knowledge. Please, can someone with a penchant for helping greenhorns throw me a rope?! Really would like to understand this better…

So, I’ve been dealing with this conflict problem for a couple of weeks now, and have done a variety of things to try and address it up to an including buying new LCD shields.

“Boilerplate” reminder to post code nicely according to the forum instructions - has now been implemented, thank you. :grinning:

Thanks for the style feedback. Always happy to learn and improve... And if it makes the posting easier to follow all the better... Hopefully I applied your feedback appropriately. I also removed some extraneous code comments that didn't apply to the posting. The original code did a lot of button reading but it had nothing to do with the issue so I removed it but forgot to remote the associated comments. The posted code is what I'm actually using to try and debug the issue I'm having. Also, last night I started to wonder if it might be a power issue for my hardware stack. I've only been using the USB power and maybe the reset on the ethernet board is triggered by the LCD power usage. I'll try later this morning using a barrel jack power source as well to try and eliminate a power reset as the cause. Thanks again...

Please do not attempt to power up any serious project using the "Barrel Jack" (or "Vin") and on-board regulator - unless you are using a "RoboRed" board which has a proper switchmode regulator on-board.

For testing, and/ or current draw up to 500 mA, use the USB port - you can use an inexpensive 5 V USB "Phone charger". For any higher current draw, use a suitable 5 V regulated (switchmode) supply connected to the 5V pin and ground as well as your other modules. "Phone chargers" are readily available with capacity up to at least 2.1 A.

Using the higher power didn't matter anyway, still hangs at the exact same time in the process. Interestingly, I thought it might be a slave select issue with the ethernet shield getting switched into card reader mode when the LCD get written to, but the last time i ran the sketch I monitored my router attached list and saw the Arduino appear in the wire conceded section, and then vanish when the LCD write happened between StepC and StepD. So, the card is apparently being reset entirely, not just switched into memory card reader mode (or I'd think it would stay listed on the router). Is there any utility type sketch logic that can show the state of all pins when called to help with debugging pin conflicts? I am not able to find much info on the DFRobot Ethernet (W5200) shield so I'm finding it hard to determine which shield pins are really being used. I've found other help postings that imply it's using more than just D10 thru D13. Some docs/postings imply it may be using A0 or A1, or also D2 or D4. I'd assume that if D2 or D4 is being used its to control SS on the memory card slot on the SPI bus. Wish I could read tech specs better. The Freetronics doco seems pretty solid so that's apparently reliable. And I've looked at but they don't list this particular DFRobot ethernet shield and all DFRobot site does is dump you to the site, which isn't very helpful if you ask me.