Offline
Newbie
Karma: 0
Posts: 11
|
 |
« on: February 12, 2013, 11:59:21 am » |
Hi guys, First off, i'm an offshore electrical engineer however electronics (particularly Arduino) is not something i've spent much time with. More used to heavy machinery, 24kV switchboards and 11kV propulsion motors on ships etc. Anyway, excuses aside... I've been tasked to develop a secure entry system into a hazardous area on board a ship, utilising a keypad and servo motor in the first instance. Fortunately i found the vast Arduino online support network early on and have managed to pick up enough to write/borrow/chop a sketch together. However, i'm having trouble when i verify my sketch, i get the following errors... Programme_Attempt_2:9: error: variable or field 'keypadEvent' declared void Programme_Attempt_2:9: error: 'KeypadEvent' was not declared in this scope Programme_Attempt_2:7: error: 'Password' does not name a type Programme_Attempt_2:25: error: 'Keypad' does not name a type Programme_Attempt_2.ino: In function 'void setup()': Programme_Attempt_2:35: error: 'keypad' was not declared in this scope Programme_Attempt_2:35: error: 'keypadEvent' was not declared in this scope Programme_Attempt_2.ino: In function 'void loop()': Programme_Attempt_2:39: error: 'keypad' was not declared in this scope Programme_Attempt_2.ino: At global scope: Programme_Attempt_2:43: error: variable or field 'keypadEvent' declared void Programme_Attempt_2:43: error: 'KeypadEvent' was not declared in this scope From the little i know, it looks or seems to me like the sketch isn't finding the Keypad librarie? It IS in the libraries folder along with 2 other libraries (servo and password) which seem to be working. I have attached the code below if it helps anyone help me. Any help is much appreciated, Colin. #include <Keypad.h> //instructs to use keypad library #include <Password.h> //instructs to use password library #include <Servo.h> //instructs to use servo library
Servo myservo; //declares servo Password password = Password( "1, 2, 3, 4" ); //password to unlock door/start servo, can be changed.
const byte ROWS = 4; // Four rows const byte COLS = 3; // Three columns
// Define the Keymap char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'} };
byte rowPins[ROWS] = { 5, 4, 3, 2 };// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins. byte colPins[COLS] = { 8, 7, 6 };// Connect keypad COL1, COL2 and COL3 to these Arduino pins.
// Create the Keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){ Serial.begin(9600); Serial.print(254); Serial.print(0x01); delay(200); pinMode(11, OUTPUT); //Green light pinMode(12, OUTPUT); //Red light myservo.attach(13); //Servo on digital pin 9 //servo keypad.addEventListener(keypadEvent); //add an event listener for this keypad }
void loop(){ keypad.getKey(); myservo.write(0); } //take care of some special events void keypadEvent(KeypadEvent eKey){ switch (keypad.getState()){ case PRESSED: Serial.print("Enter: "); Serial.println(eKey); delay(10); Serial.print(254); switch (eKey){ case 'A': checkPassword(); delay(1); break; case 'B': password.reset(); delay(1); break; default: password.append(eKey); delay(1); } } } void checkPassword(){ if (password.evaluate()){ //if password is right open door/turn servo 160deg Serial.println("Accepted"); Serial.print(254);delay(10); //Add code to run if it works myservo.write(5); //160deg digitalWrite(11, HIGH);//turn on delay(500); digitalWrite(11, LOW);// turn off }else{ Serial.println("Denied"); //if passwords wrong keep door locked/servo motionless Serial.print(254);delay(10); //add code to run if it did not work myservo.write(0); digitalWrite(12, HIGH); //turn on delay(500); digitalWrite(12, LOW);//turn off } }
|
|
|
|
« Last Edit: February 15, 2013, 06:42:45 am by coldo »
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1569
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #1 on: February 12, 2013, 12:07:57 pm » |
You want to secure an entry system into a hazardous area with an arduino? Ok. well it looks like your sketch can't find the libraries. Where did you put them, in the Arduino sketch folder, under your documents or in the Arduino 1.0.3 folder?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 314
Posts: 35514
Seattle, WA USA
|
 |
« Reply #2 on: February 12, 2013, 12:08:45 pm » |
Programme_Attempt_2:7: error: 'Password' does not name a type Programme_Attempt_2:25: error: 'Keypad' does not name a type These are pretty good indicators that the Keypad.h and Password.h files could not be found. Where did you download these libraries to?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #3 on: February 12, 2013, 12:18:43 pm » |
You want to secure an entry system into a hazardous area with an arduino? Ok. well it looks like your sketch can't find the libraries. Where did you put them, in the Arduino sketch folder, under your documents or in the Arduino 1.0.3 folder?
You want to secure an entry system into a hazardous area with an arduino? Ok. well it looks like your sketch can't find the libraries. Where did you put them, in the Arduino sketch folder, under your documents or in the Arduino 1.0.3 folder?
Thanks for the quick response guys. The libraries are saved; My Documents > Arduino > Libraries Libraries directory contains 3 folders titled; Keypad, Password and Servo. All containing .cpp and .h files. Does it matter where i save my sketch file....? As this is in a different location?
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1569
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #4 on: February 12, 2013, 12:22:12 pm » |
Well try moving them to the other folder. If it doesn't have a libraries folder in it, make one. If it still doesn't work, try the spelling, they might be all lower case letters.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #5 on: February 12, 2013, 12:41:06 pm » |
Well try moving them to the other folder. If it doesn't have a libraries folder in it, make one. If it still doesn't work, try the spelling, they might be all lower case letters.
Ok, just checked spelling, libraries are in the same format as the sketch. Also moved the libraries between the Arduino 1.0.3 folder and my Arduino folder in my documents - same errors are apparent unfortunately. Any other suggestions?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 314
Posts: 35514
Seattle, WA USA
|
 |
« Reply #6 on: February 12, 2013, 12:45:50 pm » |
Any other suggestions? Post a screen shot of the library structure. You are restarting the IDE each time, right?
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1569
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #7 on: February 12, 2013, 12:46:02 pm » |
Do you have a link of where you got them?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #8 on: February 15, 2013, 06:42:06 am » |
Hi again guys. OK. Embarassingly... the original error which resulted in the keypad/password libraries not being found or working was a schoolboy indexing error which i noticed last night and have now fixed. Thanks again for your time though. HOWEVER... Now the servo library wont work!? Or at least the .cpp file. The errors im getting are shown below. C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: In function 'void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)': C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:81: error: 'LOW' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:81: error: 'digitalWrite' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:88: error: 'HIGH' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:88: error: 'digitalWrite' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:92: error: 'clockCyclesPerMicrosecond' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: At global scope: C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:232: error: 'boolean' does not name a type C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: In constructor 'Servo::Servo()': C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:249: error: 'clockCyclesPerMicrosecond' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'uint8_t Servo::attach(int, int, int)': C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:263: error: 'OUTPUT' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:263: error: 'pinMode' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:270: error: 'isTimerActive' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'void Servo::detach()': C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:281: error: 'isTimerActive' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'void Servo::write(int)': C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:292: error: 'map' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'void Servo::writeMicroseconds(int)': C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:300: error: 'byte' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:300: error: expected `;' before 'channel' C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:301: error: 'channel' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:309: error: 'clockCyclesPerMicrosecond' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'int Servo::read()': C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:320: error: 'map' was not declared in this scope C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'int Servo::readMicroseconds()': C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp:327: error: 'clockCyclesPerMicrosecond' was not declared in this scope Again, if anyone has any input it is greatly appreciated, thanks. Colin.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 314
Posts: 35514
Seattle, WA USA
|
 |
« Reply #9 on: February 15, 2013, 10:31:18 am » |
Why do you have a copy of the Servo library in your sketch folder's libraries directory?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #10 on: February 16, 2013, 10:10:59 am » |
Why do you have a copy of the Servo library in your sketch folder's libraries directory?
I do? Could you elaborate - how to fix/what i've done wrong? Apologies for my ignorance!
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 314
Posts: 35514
Seattle, WA USA
|
 |
« Reply #11 on: February 16, 2013, 10:15:42 am » |
I do? Could you elaborate - how to fix/what i've done wrong? Isn't C:\Users\Colin\Documents\Arduino where you store your sketches? C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp This looks like Servo is a library in your libraries folder in the sketch directory. It does not belong here because Servo is a core library.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #12 on: February 18, 2013, 08:28:22 am » |
I do? Could you elaborate - how to fix/what i've done wrong? Isn't C:\Users\Colin\Documents\Arduino where you store your sketches? Ah, i see. Yes, this is where my sketches are stored. I've now deleted the servo copy. C:\Users\Colin\Documents\Arduino\libraries\Servo\Servo.cpp This looks like Servo is a library in your libraries folder in the sketch directory. It does not belong here because Servo is a core library. Ok. So... i have re-arranged and and re-imported the servo library from the Arduino 1.0.3 directory however the same errors are apparent. To clarify - My sketch is in > C:\Users\Colin\Documents\Arduino Keypad, Password and Servo libraries are all now in > C:\Users\Colin\Documents\arduino-1.0.3\libraries Keypad and Password libraries appear to be recognised - Servo is not. Sorry for the very schoolboy issues - all your time is greatly appreciated! I
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 314
Posts: 35514
Seattle, WA USA
|
 |
« Reply #13 on: February 18, 2013, 08:55:45 am » |
Keypad, Password and Servo libraries are all now in > C:\Users\Colin\Documents\arduino-1.0.3\libraries That is not where Keypad and Password belong. Those are not core libraries, and do not belong in the core library folder. Servo is and does. What do your copies of Servo.h and Servo.cpp look like? What does your sketch look like? When I compile the code in the initial post, I only get this "error" message: Binary sketch size: 9,350 bytes (of a 28,672 byte maximum)
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 11
|
 |
« Reply #14 on: February 20, 2013, 04:27:53 pm » |
Keypad, Password and Servo libraries are all now in > C:\Users\Colin\Documents\arduino-1.0.3\libraries That is not where Keypad and Password belong. Those are not core libraries, and do not belong in the core library folder. Servo is and does. What do your copies of Servo.h and Servo.cpp look like? What does your sketch look like? When I compile the code in the initial post, I only get this "error" message: Binary sketch size: 9,350 bytes (of a 28,672 byte maximum) Ok. Moved the keypad and Password libraries from the core libraries to an appropriate location. Re-checked and they appear to work as normal. The servo.h and servo.cpp are shown below; Servo.h looks like; /* Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 Copyright (c) 2009 Michael Margolis. All right reserved.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/* A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. The servos are pulsed in the background using the value most recently written using the write() method
Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. The sequence used to sieze timers is defined in timers.h
The methods are:
Servo - Class for manipulating servo motors connected to Arduino pins.
attach(pin ) - Attaches a servo motor to an i/o pin. attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds default min is 544, max is 2400 write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) writeMicroseconds() - Sets the servo pulse width in microseconds read() - Gets the last written servo pulse width as an angle between 0 and 180. readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) attached() - Returns true if there is a servo attached. detach() - Stops an attached servos from pulsing its i/o pin. */
#ifndef Servo_h #define Servo_h
#include <inttypes.h>
/* * Defines for 16 bit timers used with Servo library * * If _useTimerX is defined then TimerX is a 16 bit timer on the curent board * timer16_Sequence_t enumerates the sequence that the timers should be allocated * _Nbr_16timers indicates how many 16 bit timers are available. * */
// Say which 16 bit timers can be used and in what order #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define _useTimer5 #define _useTimer1 #define _useTimer3 #define _useTimer4 typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_ATmega32U4__) #define _useTimer3 #define _useTimer1 typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) #define _useTimer3 #define _useTimer1 typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) #define _useTimer3 #define _useTimer1 typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
#else // everything else #define _useTimer1 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; #endif
#define Servo_VERSION 2 // software version of this library
#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo #define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached #define REFRESH_INTERVAL 20000 // minumim time to refresh servos in microseconds
#define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer #define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER)
#define INVALID_SERVO 255 // flag indicating an invalid servo index
typedef struct { uint8_t nbr :6 ; // a pin number from 0 to 63 uint8_t isActive :1 ; // true if this channel is enabled, pin not pulsed if false } ServoPin_t ;
typedef struct { ServoPin_t Pin; unsigned int ticks; } servo_t;
class Servo { public: Servo(); uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. void detach(); void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds void writeMicroseconds(int value); // Write pulse width in microseconds int read(); // returns current pulse width as an angle between 0 and 180 degrees int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) bool attached(); // return true if this servo is attached, otherwise false private: uint8_t servoIndex; // index into the channel data for this servo int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH };
#endif
|
|
|
|
|
Logged
|
|
|
|
|
|