GRBL + LCD Shield Issue

Hi All,

I am currently using the Uno R3 and the Protoneer Arduino CNC Shield V3.51 (more info here) running GRBL v0.9j to control two stepper motors. I want to use the RGB LCD Shield to allow the user to select a program to run. Without the RGB LCD Shield I am able to run GRBL fine from my PC using UniversalGcodeSender v1.0.9. I wanted to test whether or not the RGB LCD Shield would work with the CNC Shield, so I took the code from the "grblUpload" file:

#include <grbl.h>

and inserted it into the "HelloWorld" file from the Adafruit RGB LCD Shield Library:

/*********************

Example code for the Adafruit RGB Character LCD Shield and Library

This code displays text on the shield, and also reads the buttons on the keypad.
When a button is pressed, the backlight changes color.

**********************/

// include the library code:
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include <grbl.h>

// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

void setup() {
  // Debugging output
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);

  // Print a message to the LCD. We track how long it takes since
  // this library has been optimized a bit and we're proud of it :)
  int time = millis();
  lcd.print("Hello, world!");
  time = millis() - time;
  Serial.print("Took "); Serial.print(time); Serial.println(" ms");
  lcd.setBacklight(WHITE);
}

uint8_t i=0;
void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);

  uint8_t buttons = lcd.readButtons();

  if (buttons) {
    lcd.clear();
    lcd.setCursor(0,0);
    if (buttons & BUTTON_UP) {
      lcd.print("UP ");
      lcd.setBacklight(RED);
    }
    if (buttons & BUTTON_DOWN) {
      lcd.print("DOWN ");
      lcd.setBacklight(YELLOW);
    }
    if (buttons & BUTTON_LEFT) {
      lcd.print("LEFT ");
      lcd.setBacklight(GREEN);
    }
    if (buttons & BUTTON_RIGHT) {
      lcd.print("RIGHT ");
      lcd.setBacklight(TEAL);
    }
    if (buttons & BUTTON_SELECT) {
      lcd.print("SELECT ");
      lcd.setBacklight(VIOLET);
    }
  }
}

and tried to compile. Compiling failed with the following errors:

C:\Users\FLYNNCON\AppData\Local\Temp\buildd7e3f0dc760fe3f51e3a0b303e4b09c2.tmp/core\core.a(wiring.c.o): In function `__vector_16':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/wiring.c:47: multiple definition of `__vector_16'

libraries\GRBL\stepper.c.o:C:\Users\FLYNNCON\Documents\Arduino\libraries\GRBL/stepper.c:416: first defined here

C:\Users\FLYNNCON\AppData\Local\Temp\buildd7e3f0dc760fe3f51e3a0b303e4b09c2.tmp/core\core.a(HardwareSerial0.cpp.o): In function `__vector_18':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial0.cpp:48: multiple definition of `__vector_18'

libraries\GRBL\serial.c.o:C:\Users\FLYNNCON\Documents\Arduino\libraries\GRBL/serial.c:160: first defined here

C:\Users\FLYNNCON\AppData\Local\Temp\buildd7e3f0dc760fe3f51e3a0b303e4b09c2.tmp/core\core.a(HardwareSerial0.cpp.o): In function `__vector_18':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial0.cpp:48: multiple definition of `__vector_19'

libraries\GRBL\serial.c.o:C:\Users\FLYNNCON\Documents\Arduino\libraries\GRBL/serial.c:42: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

with #include <grbl.h> commented out the program compiles fine.

I'm wondering if it is possible to use the RGB LCD Shield with the CNC Shield and GRBL? If so, what approach should I take?

Appreciate the help.

GRBL uses almost all, if not all, of the Arduino UNO pins. Have you checked to see if the LCD is using pins that are free?

The GRBL code uses Timer0 for stepper timing. You can't use it with the Arduino core which uses Timer0 for millis(). GRBL also has its own driver for the serial hardware so you can't use Serial with it.

johnwasser:
GRBL uses almost all, if not all, of the Arduino UNO pins. Have you checked to see if the LCD is using pins that are free?

The GRBL code uses Timer0 for stepper timing. You can't use it with the Arduino core which uses Timer0 for millis(). GRBL also has its own driver for the serial hardware so you can't use Serial with it.

The LCD Shield uses pins A4 (I2C Clock(SCL)), A5 (I2C Data(SDA)), +5v and GND. Any suggestions on how to incorporate and LCD with GRBL?

What did you hope to accomplish with the LCD? I don't think the GRBL code is designed to work with a local output device. I suspect that adding local control will use more memory than the Arduino UNO + GRBL has left.

I've seen cnc machines with lcds showing machine positions using GRBL. They used a mega.

Here is an example of using a second Arduino to display status information based on monitoring the serial line:
http://oliverwhysall.co.uk/the-weekend-project-1-grbl-lcd-display/

johnwasser:
What did you hope to accomplish with the LCD? I don't think the GRBL code is designed to work with a local output device. I suspect that adding local control will use more memory than the Arduino UNO + GRBL has left.

The CNC I am making has a dedicated purpose and will only be running 3 programs. I wanted to use the LCD to allow the user to select which program to run.

Do you think that the two Arduino method is the best route to take?

If it were me, I would switch to a cheap RAMPS 1.4 configuration. You can get a set with a 128x64 graphics LCD or a 20x4 text LCD for about $30. That will allow you to install Marlin firmware and run gcode programs off the SD card. They typically come with FIVE stepper drivers so you will have some spares.

johnwasser:
If it were me, I would switch to a cheap RAMPS 1.4 configuration. You can get a set with a 128x64 graphics LCD or a 20x4 text LCD for about $30. That will allow you to install Marlin firmware and run gcode programs off the SD card. They typically come with FIVE stepper drivers so you will have some spares.

Thanks for the help John! I hadn't heard of RAMPS 1.4 but it seems like the best route for what I'm trying to accomplish.

Pardon my ignorance but how would I incorporate an SD card?

clf139:
Pardon my ignorance but how would I incorporate an SD card?

The SD card slot is on the LCD controller board. You would configure the controller in the Configuration.h file of the Marlin sketch.

johnwasser:
The SD card slot is on the LCD controller board. You would configure the controller in the Configuration.h file of the Marlin sketch.

Thanks John -- I found a different vendor who has pictures that show the SD card slot.