Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Button problem
#1
Question 
Hello !

I think I have a little problem... Actually I assembled Arduino, LCD and miniE shield : it's work ! Then I upload the software on my Arduino : it's work too ! I thought "Great ! It's done !". But I have a problem with buttons... When I press DOWN button I go back in the menus... And LEFT go back to Home screen... So I can't go down in menu...

This problem come from software or from my hardware ? And can we fix it easily ?

Thank for your answers !

Adrien.
Reply
#2
(06-18-2013, 03:04 PM)Ad31rien Wrote: ..This problem come from software or from my hardware ? And can we fix it easily ?

It's actually a hardware problem - somehow. The 5 buttons share one pin and use resistor dividers for "signaling" different voltage levels to the Arduino. Thus these resistors are not perfect, there might be misinterpretations by the software.

You can tweak the software for fixing it. Try altering these values until it works for you. You'll find them in the file mE_keys.ino. These values should work perfectly:

#define key_0_val 73 // right
#define key_1_val 237 // up
#define key_2_val 418 // down
#define key_3_val 624 // left
#define key_4_val 1023 // select

Good luck,
Airic
Reply
#3
Hi !

Thanks a lot Airic ! It work fine for these values :

#define key_0_val 50 // right
#define key_1_val 225 // up
#define key_2_val 418 // down
#define key_3_val 700 // left
#define key_4_val 1023 // select

In fact it was really easy ! Thanks again !
Reply
#4
(06-18-2013, 10:29 PM)Ad31rien Wrote: Hi !

Thanks a lot Airic ! It work fine for these values :

#define key_0_val 50 // right
#define key_1_val 225 // up
#define key_2_val 418 // down
#define key_3_val 700 // left
#define key_4_val 1023 // select

In fact it was really easy ! Thanks again !

I had run into this as well - there is an included Example Sketch that will tell you the values of your button shield. Go to File->Examples->Basics->AnalogReadSerial and upload & run that program with the button shield installed.

When you push down the various buttons, it will give you the ADC value for each button on your shield in the serial output window. Just pad the number buy 10 or so and it should work great (if the output shows 204, 205,203 while holding the button, use 215 for your number).

Saves some trial and error time!

-Matt
Reply
#5
Hey guys
I had my DFrobot and Arduino board last week.
I had the same issues. After contacting Airic, I get knowledge of this thread. I tested and get an new issue. The left button dosn't work in every menu.
So i set the value like in the test program of DFRobot
DFRobot Test Program

and it works.
So the Part at the mE_keys.ino looks like this:
#define key_0_val 50 // right (old: 30)
#define key_1_val 250 // up (old: 240)
#define key_2_val 450 // down (old: 360)
#define key_3_val 650 // left (old: 580)
#define key_4_val 850 // select (old: 760)

Regards Sascha
Reply
#6
Hi!
I made LCD shield as here http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009).
Example code works, buttons work correctly.
From an example I didn't change a code.
Values for buttons in my case

key_0_val 0
key_1_val 147
key_2_val 333
key_3_val 510
key_4_val 743

But with the miniE code button don't work. Huh
Reply
#7
Well, what is it that does not work?
Reply
#8
Thanks for the fast answer.
There is no reaction to pressing of buttons.
#define MOTOR_SLEEP_PIN 10
#define MOTOR_STEP_PIN 11
#define MOTOR_DIR_PIN 12
#define CAMERA_PIN 3
#define FOCUS_PIN 7
#define LCD_BACKLIGHT_PIN 9
#define LCD_KEY_PIN A4
#define LIMIT_SWITCH_PIN_1 A5
#define LIMIT_SWITCH_PIN_2 A6
LiquidCrystal lcd(17, 16, 4, 5, 6, 8);

#define key_0_val 50 // right (old: 30)
#define key_1_val 225 // up (old: 240)
#define key_2_val 400 // down (old: 360)
#define key_3_val 600 // left (old: 580)
#define key_4_val 800 // select (old: 760)

Only when pressing the button SELECT СW changes on CCW and back.

But the most interesting that with MX2 works perfectly.Undecided
Reply
#9
The code you sent is not for the DFRobot shield!

When you check the link, there is a pin-mapping list and it fits the definition of the pins in the miniE code:

Code:
// pin for LCD backlight
#define LCD_BACKLIGHT_PIN   10
// pin for reading analog key input
#define LCD_KEY_PIN         A0  

// --------------------------
// Display
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

you could try these values for the button calibration (in the file mE_keys.ino):

Code:
#define key_0_val 50
#define key_1_val 250
#define key_2_val 450
#define key_3_val 650
#define key_4_val 850

Good luck,
Airic
Reply
#10
Yes, I made the shield for Arduino Nano and pin-mapping for oneself.
I correct your code for my pin-mapping as I specified in the previous post.
I changed values
#define key_0_val 50
#define key_1_val 250
#define key_2_val 450
#define key_3_val 650
#define key_4_val 850
The problem, unfortunately, remained.


I did the same( my pin-mapping) for MX2 and everything works.

I checked my shield such code
Code:
#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(17, 16, 4, 5, 6, 8);

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

#define LCD_BACKLIGHT_PIN   9

// read the buttons
int read_LCD_buttons()
{
  adc_key_in = analogRead(A4);      // read the value from the sensor
  // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  // we add approx 50 to those values and check to see if we are close
  if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  // For V1.1 us this threshold
  if (adc_key_in < 50)   return btnRIGHT;  
  if (adc_key_in < 250)  return btnUP;
  if (adc_key_in < 450)  return btnDOWN;
  if (adc_key_in < 650)  return btnLEFT;
  if (adc_key_in < 850)  return btnSELECT;  

  return btnNONE;  // when all others fail, return this...
}

void setup()
{
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  lcd.print("Push the buttons"); // print a simple message
  pinMode(LCD_BACKLIGHT_PIN, OUTPUT);
}

void loop()
{
  digitalWrite(LCD_BACKLIGHT_PIN, HIGH);
  lcd.setCursor(0,1);            // move to the begining of the second line
  lcd_key = read_LCD_buttons();  // read the buttons

    switch (lcd_key)               // depending on which button was pushed, we perform an action
  {
  case btnRIGHT:
    {
      lcd.print("RIGHT ");
      break;
    }
  case btnLEFT:
    {
      lcd.print("LEFT   ");
      break;
    }
  case btnUP:
    {
      lcd.print("UP    ");
      break;
    }
  case btnDOWN:
    {
      lcd.print("DOWN  ");
      break;
    }
  case btnSELECT:
    {
      lcd.print("SELECT");
      break;
    }
  case btnNONE:
    {
      lcd.print("NONE  ");
      break;
    }
  }

}
Buttons react perfectly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)