I'm trying to make a program to work for a stepper driven rotary table (found on CNC zone.com)
As hardware comes an Arduino Nano, a matrix 4 x4 keyboard, an LCD 4 x 20 display + backpack module and a stepper driver.
Compiling and uploading the program as published gives many problems, so I started trying to make the components to work one by one. Keypad: no problem; LCD display as a single item also works, but when I combine these two,I get error messages from the LCD part in the program.
#include <Key.h>
#include <keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {11, 10, 9, 8}; //connect to row pinouts
byte colPins[COLS] = {7, 6, 5, 4}; //connect to column pinouts
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY) {
Serial.println(key);
}
}
/**
* I2C/IIC LCD Serial Adapter Module Example
* Tutorial by http://mklec.com
** Instructions at http://blog.mklec.com/how-to-use-iici2c-serial-interface-module-for-1602-lcd-display
** This uses the Liquid Crystal library from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads GNU General Public License, version 3 (GPL-3.0)
* Pin Connections:
* SCL = A5
* SDA = A4
* VCC = 5V
* GND = GND
*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7); // 0x27 is the I2C bus address for an unmodified module
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it to LOW instead of HIGH
lcd.begin(20, 4);
lcd.clear();
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("http://mklec.com");
lcd.setCursor(0, 1);
lcd.print("I2C Module Demo");
lcd.setCursor(0, 2);
lcd.print("Geduld beloond");
lcd.setCursor(0, 3);
lcd.print("16-08-2015");
delay(10000);
}
Error messages:
Arduino: 1.6.5 (Windows 7), Board:"Arduino Nano, ATmega328"
Bibliotheek Keypad in map: C:\Users\Thuis\Documents\Arduino\libraries\Keypad wordt gebruikt
Bibliotheek Wire in map: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire wordt gebruikt
Bibliotheek LiquidCrystal in map: C:\Users\Thuis\Documents\Arduino\libraries\LiquidCrystal (legacy) wordt gebruikt
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs -IC:\Users\Thuis\Documents\Arduino\libraries\Keypad\src -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire -IC:\Users\Thuis\Documents\Arduino\libraries\LiquidCrystal C:\Users\Thuis\AppData\Local\Temp\build5298228962049564241.tmp\sketch_aug16a_testLCDenKP.cpp -o C:\Users\Thuis\AppData\Local\Temp\build5298228962049564241.tmp\sketch_aug16a_testLCDenKP.cpp.o
sketch_aug16a_testLCDenKP.ino:44:1: error: 'lcd' does not name a type
sketch_aug16a_testLCDenKP.ino:45:1: error: 'lcd' does not name a type
sketch_aug16a_testLCDenKP.ino:46:1: error: 'lcd' does not name a type
sketch_aug16a_testLCDenKP.ino:47:1: error: 'lcd' does not name a type
sketch_aug16a_testLCDenKP.ino:48:1: error: expected declaration before '}' token
'lcd' does not name a type
It puzzles me why in the "stand alone" situation this error does not show, where in the combined program it gives the error. The Keypad works in both programs (on the serial monitor).
I did no test with the stepper driver so far. Writing LCD in capitals gives another error message, but does not solve the problem
I do hope someone can lift a tip of the vale for me.
Foden