Community
cancel
Showing results for 
Search instead for 
Did you mean: 
DMcPh
New Contributor I
2,053 Views

Can someone help with my Galileo Gen 2 analog pin set up. Im lost...

Jump to solution

On the Galileo Gen 2 arduino board. How do i utilize the analog pins? I have used up pins 2 through 9. Using a 4x4 keypad, a user will enter a code and the servo motor will turn 180 degrees. unlocking a door.

Please show me what librarys i need to install because i found softPMW and softPMWtimer online and it didnt help. It gives me a "not in directory error"

Tags (1)
1 Solution
DMcPh
New Contributor I
174 Views

After countless hours of trying to map a 4x4 keypad to one analog pin to free up space on the digital pins i have decided to just use pins 5-12 for my Keypad and use pin 3 for my servo. This way i can connect my LCD, Keypad, and Servo on the same board without have to wire a bunch of resistors on a bread board. The Base Shield that comes with the Grove Starter Kit Plus has a resistor built into it. So all i had to do was connect devices directly to the board and Run the sketch.

Feel free to test this out on your board with your devices..

______________________________________________________________________________________________________________________________________________________

# include "Printable.h"

# include "Servo.h"

# include "Wire.h"

# include "lcd_I2C.h"

# include "Arduino.h"

# include "rgb_lcd.h"

/* ==================================================================================

File: keypad_password_servo.ino

Author: Darwynn McPherson

// ==================================================================================*/

# include //http://playground.arduino.cc/uploads/Code/Password.zip http://playground.arduino.cc/uploads/Code/Password.zip use password library

# include //http://www.arduino.cc/playground/uploads/Code/Keypad.zip http://www.arduino.cc/playground/uploads/Code/Keypad.zip //tells to use keypad library

# include //tells to use servo library

# include

# include

# include

# include

Servo myservo; // create servo object to control a servo

// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

Password password = Password( "1111" ); //password to unlock box, can be changed

rgb_lcd lcd;

const int colorR = 255;

const int colorG = 0;

const int colorB = 0;

const byte ROWS = 4; // Four rows

const byte COLS = 4; // columns

// Define the Keymap

char keys[ROWS][COLS] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','# ','D'}

};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.

byte rowPins[ROWS] = { 5, 6, 7, 8 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

byte colPins[COLS] = { 9, 10, 11, 12 };

// Create the Keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

Serial.begin(9600);

Serial.write(254);

Serial.write(0x01);

delay(200);

//pinMode(11, OUTPUT); //green light

//pinMode(12, OUTPUT); //red light

myservo.attach(3); //servo on digital pin 3 //servo

keypad.addEventListener(keypadEvent); //add an event listener for this keypad

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

lcd.setRGB(colorR, colorG, colorB);

}

void loop(){

keypad.getKey();

}

//take care of some special events

void keypadEvent(KeypadEvent eKey){

switch (keypad.getState()){

case PRESSED:

Serial.print("Enter:Access Code ");

Serial.println(eKey);

delay(10);

Serial.write(254);

switch (eKey){

case '# ': checkPassword(); delay(1); break;

case '*': password.reset(); delay(1); break;

Serial.println("Now Re-enter");

default: password.append(eKey); delay(1);

}

}

}

void checkPassword(){

if (password.evaluate()){ //if password is right open box

Serial.println("Access Granted");

lcd.print("Access Granted!");

delay(2500);

lcd.clear();

Serial.println("Door is open");

delay(500);

myservo.write(pos --);

delay(3000);

myservo.write(pos = 150);

Serial.write(254);delay(10);

//Add code to run if it works

digitalWrite(11, HIGH);//turn on

delay(500); //wait 5 seconds

digitalWrite(11, LOW);// turn off

}else{

Serial.println("Access Denied"); //if passwords wrong keep box locked

lcd.print("Access Denied");

delay(1500);

lcd.clear();

lcd.print("press * to reset");

delay(2500);

lcd.clear();

Serial.println("Press * to reset");

Serial.write(254);delay(10);

//add code to run if it did not work

digitalWrite(12, HIGH); //turn on

delay(500); //wait 5 seconds

digitalWrite(12, LOW);//turn off

}

}

View solution in original post

28 Replies
FTinetti
Honored Contributor I
134 Views

What IDE are you using/how are you developing your code?

Fernando.

DMcPh
New Contributor I
134 Views

I am using Arduino IDE. Code is written in C++.

FTinetti
Honored Contributor I
134 Views

Plase send the sketch you are using and please copy the error (or just send the screenshot)

Why do you want to use PWM? Pls send the servo motor details you are trying to use.

Fernando.

DMcPh
New Contributor I
134 Views

OK i will post sketch after this. My instructor said that is the only way to enable the usage of pin A0-A5. I have used up all the pins up on the base shield that comes with the grove starter it plus, attaching a 4x4 Keypad to pins 2 through 9. only pins left are is pin 10 through 13 but they arent accessible with the shield. i will post the images and sketch right after this.

DMcPh
New Contributor I
134 Views

# include //i installed these libraries correctly but have a directory error.

# include

# include "Printable.h"

# include "Servo.h"

# include "Wire.h"

# include "lcd_I2C.h"

# include "Arduino.h"

# include "rgb_lcd.h"

/* ==================================================================================

File: keypad_password_servo.ino

Author: Darwynn McPherson

// ==================================================================================*/

# include //http://playground.arduino.cc/uploads/Code/Password.zip http://playground.arduino.cc/uploads/Code/Password.zip use password library

# include //http://www.arduino.cc/playground/uploads/Code/Keypad.zip http://www.arduino.cc/playground/uploads/Code/Keypad.zip //tells to use keypad library

# include //tells to use servo library

# include

# include

# include

# include

Servo myservo; // create servo object to control a servo

// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

Password password = Password( "1111" ); //password to unlock box, can be changed

rgb_lcd lcd;

const int colorR = 255;

const int colorG = 0;

const int colorB = 0;

const byte ROWS = 4; // Four rows

const byte COLS = 4; // columns

// Define the Keymap

char keys[ROWS][COLS] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','# ','D'}

};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.

byte rowPins[ROWS] = { 2, 3, 4, 5 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

byte colPins[COLS] = { 6, 7, 8, 9 };

// Create the Keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

Serial.begin(9600);

Serial.write(254);

Serial.write(0x01);

delay(200);

pinMode(11, OUTPUT); //green light

pinMode(12, OUTPUT); //red light

pinMode(A0, OUTPUT);//My attempt to try to assign pin numbers

digitalWrite(A0, HIGH);

myservo.attach(A0); //servo on digital pin A0 //servo

keypad.addEventListener(keypadEvent); //add an event listener for this keypad

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

lcd.setRGB(colorR, colorG, colorB);

}

void loop(){

keypad.getKey();

myservo.write(pos++);

delay(5);

}

//take care of some special events

void keypadEvent(KeypadEvent eKey){

switch (keypad.getState()){

case PRESSED:

Serial.print("Enter:Access Code ");

Serial.println(eKey);

delay(10);

Serial.write(254);

switch (eKey){

case '# ': checkPassword(); delay(1); break;

case '*': password.reset(); delay(1); break;

Serial.println("Now Re-enter");

default: password.append(eKey); delay(1);

}

}

}

void checkPassword(){

if (password.evaluate()){ //if password is right open box

Serial.println("Access Granted");

lcd.print("Access Granted!");

myservo.write(pos++); //160deg

delay(2500);

lcd.clear();

Serial.println("Door is open");

Serial.write(254);delay(10);

//Add code to run if it works

digitalWrite(11, HIGH);//turn on

delay(500); //wait 5 seconds

digitalWrite(11, LOW);// turn off

}else{

Serial.println("Access Denied"); //if passwords wrong keep box locked

lcd.print("Access Denied");

myservo.write(pos--); // tell servo to go to variable position

delay(2500);

lcd.clear();

Serial.println("Press * to reset");

Serial.write(254);delay(10);

//add code to run if it did not work

digitalWrite(12, HIGH); //turn on

delay(500); //wait 5 seconds

digitalWrite(12, LOW);//turn off

}

}

DMcPh
New Contributor I
134 Views

THIS IS THE ERROR CODE

Arduino: 1.6.0 (Windows 8), Board: "Intel® Galileo Gen2"

Build options changed, rebuilding all

In file included from SenProjKEypad.ino:2:0:

C:\Users\BRUIZZR\Documents\Arduino\libraries\SoftPWM/SoftPWM_timer.h:22:20: fatal error: avr/io.h: No such file or directory

compilation terminated.

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

THIS IS THE ERROR CODE

DMcPh
New Contributor I
134 Views

This is the base shield with the pins.

FTinetti
Honored Contributor I
134 Views

C:\Users\BRUIZZR\Documents\Arduino\libraries\SoftPWM/SoftPWM_timer.h:22:20: fatal error: avr/io.h: No such file or directory

From this error it seems to be that SoftPWM_timer.h depends on avr/io.h which in turn is AVR-dependent, so think it will not possible to use in Intel Galileo...

I do not understand

"

My instructor said that is the only way to enable the usage of pin A0-A5

"

did your instructor explain why?

A0-A5 are "special" in the sense they have ADC, but they can be used as regular "digital" pins... at least in Arduino and I think it would be possible in Galileo too...

Fernando.

DMcPh
New Contributor I
134 Views

Well he says that i cannot just plug the attachment into the pin and expect it to work without the proper library that enables those pins to be accessible. He sent me this link as a reference in order to download the library.

https://urldefense.proofpoint.com/v2/url?u=http-3A__www.instructables.com_id_How-2Dto-2Dadd-2D6-2Dex... http://www.instructables.com/id/How-to-add-6-extra-pins-to-your-Arduino-with-no-ex/

FTinetti
Honored Contributor I
134 Views

Dmcp7600 wrote:

Well he says that i cannot just plug the attachment into the pin and expect it to work without the proper library that enables those pins to be accessible. He sent me this link as a reference in order to download the library.

https://urldefense.proofpoint.com/v2/url?u=http-3A__www.instructables.com_id_How-2Dto-2Dadd-2D6-2Dex... http://www.instructables.com/id/How-to-add-6-extra-pins-to-your-Arduino-with-no-ex/

That URL has rather confusing content/s:

a) Pins A0-A5 can be used as digital pins without anything else, no libraries needed, no hardware needed.

b) Pins A0-A5 are not "automatically" available for PWM, as indicated in that URL. However, I do not understand the relationship between PWM and a blinking LED... digital pins and signals are (mostly) used for a blinking LED... or maybe I'm missing something.

Related to some previous questions:

a) Why do you need to use PWM? What is the hardware you have to control via PWM?

b) Please send the details of the servo motor you are trying to control.

Fernando.

FTinetti
Honored Contributor I
134 Views

Replying to myself just to confirm that analog pins can be used as regular dgital pins.

Sketch:

// the setup function runs once when you press reset or power the board

void setup() {

// initialize digital pin 13 as an output.

pinMode(14, OUTPUT);

}

// the loop function runs over and over again forever

void loop() {

digitalWrite(14, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(14, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}

Result (A0 = digital pin 14):

DMcPh
New Contributor I
134 Views

I do not neccessarily have to use PWM? The servo im using is just like any other servo doesnt really require any special attention. I see how that URL can be confusing. However my instructor just responded to me this evening with another link they may work.

Here is the link.

https://urldefense.proofpoint.com/v2/url?u=http-3A__waihung.net_arduino-2Dtip-2Dturn-2Dyour-2Danalog... http://waihung.net/arduino-tip-turn-your-analog-pins-into-digital-io/

FTinetti
Honored Contributor I
134 Views

hmmmm... moving target... kind of...

If

I do not neccessarily have to use PWM? The servo im using is just like any other servo doesnt really require any special attention.

then you should try a servo library (it's documented as a supported library at https://www.arduino.cc/en/ArduinoCertified/IntelGalileoGen2 Arduino - IntelGalileoGen2)... now I'm lost...

Fernando.

DMcPh
New Contributor I
134 Views

I have found plenty of servo library's and all there examples show connections to pin 0 through 9 none on the Analogs. The LED demonstration was cool but how would you edit that code to set a "Servo" on the analog port A0, A1, etc.?

Here is a servo example if you could point out in this sketch what needs to be adjusted in the void() function so that i can use analog pins please show me. I will make the adjustment in the sketch and then test whether or not they work. THank you..

// Sweep

// Darwynn McPherson mailto:dmcp7600@students.vsu.edu dmcp7600@students.vsu.edu

// This example code is in the public domain.

# include

const int buttonPin = 2;

const int buttonPin2 = 4;

int buttonState = 0;

int buttonState2 = 0;

Servo myservo; // create servo object to control a servo

// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()

{

myservo.attach(5); // attaches the servo on pin 5 to the servo object

pinMode(buttonPin, INPUT);

pinMode(buttonPin2, INPUT);

}

void loop()

{

buttonState = digitalRead(buttonPin);

buttonState2 = digitalRead(buttonPin2);

if(buttonState == HIGH && pos < 180){

myservo.write(pos++); // tell servo to go to position in variable 'pos'

delay(5); // waits 15ms for the servo to reach the position

}

if(buttonState2 == HIGH && pos > 3){ // goes from 180 degrees to 0 degrees

myservo.write(pos--); // tell servo to go to position in variable 'pos'

delay(5); // waits 15ms for the servo to reach the position

}

}

FTinetti
Honored Contributor I
134 Views

Just following the example of the LED, replace

myservo.attach(5); // attaches the servo on pin 5 to the servo object

by

myservo.attach(14); // attaches the servo on pin 14 = A0 to the servo object,

and, as the comment indicates connect the servo to A0.

HTH,

Fernando.

DMcPh
New Contributor I
134 Views

Sir i have just tried this and no progress. The servo doesnt turn at all. Here is the adjustment i made in the setup function.

# include

const int buttonPin = 2;

const int buttonPin2 = 4;

int buttonState = 0;

int buttonState2 = 0;

Servo myservo; // create servo object to control a servo

// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()

{

myservo.attach(14); // attaches the servo on pin A0 to the servo object

pinMode(14, OUTPUT);

pinMode(buttonPin, INPUT);

pinMode(buttonPin2, INPUT);

}

FTinetti
Honored Contributor I
134 Views

Please try first the basic example found at

https://www.arduino.cc/en/Tutorial/Sweep https://www.arduino.cc/en/Tutorial/Sweep

and remember to use 14 instead of 9 in the code as well as connect the servo wire to A0

use exactly the example with just that change, do not add

pinMode(14, OUTPUT);

please send a picture of your hardware setup

HTH,

Fernando.

DMcPh
New Contributor I
134 Views
FTinetti
Honored Contributor I
134 Views

I can't see the video:

DMcPh
New Contributor I
54 Views

https://www.youtube.com/watch?v=gQKz8j4tsJ8 Test using analog pins to turn a servo - YouTube

Try this...

Reply