problem with LCD ks0256

Dear Arduino’s specialist

i need your help to find the right values for the buttons on my LCD
http://wiki.keyestudio.com/index.php/Ks0256_keyestudio_LCD1602_Expansion_Shield

code extract : "

adc_key_in = analogRead(0); // 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
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this…"

i don’t know if it is V, ohm, …how to catch de centered value for each button ?

Another problem :

where do i have to plug the wire called blight ? see attached file pollailier schema_bb.jpg

Thanks in advance for your help

i don't know if it is V, ohm, ...how to catch de centered value for each button ?

I am having trouble understanding what that means.

The code that you posted may be part of a function. You, at some point in your program, call the function and it reads the keys and returns a value corresponding to the key pressed. What that value is I can't say without seeing the rest of the program.

Thanks to try to help me…
ok i put the code in attachment

for exemple when i put directly the LCD on the arduino uno buttons works normaly but when i replace by wire so the button doesn’t work anymore

poulailler.ino (20.3 KB)

Duke08: for exemple when i put directly the LCD on the arduino uno buttons works normaly but when i replace by wire so the button doesn't work anymore

Does that mean that when you plug the LCD shield onto the Uno it's ok, but as an alternative you have it "loose" and connected by wires from the shield's pins to the Uno?

I have what looks like the identical shield, but mine is DFR branded, part number DFR0009. On mine, the buttons are all on analog pin A0; I see your code says A1. But whatever, are you sure you wired A1 from the shield to A1 on the Uno, along with a ground?

(I'm curious to know (assuming I understood you correctly) why you are using the shield not plugged in on top of the Uno?)

yes you are right i try to plug by wire and not directly to the uno

i plug the A0 LCD on A1 uno output ; it’s verified and correct

i know why not directly on uno because it’s a program not directly done by myself…and normally it takes a pro mini (see attachment)

all ground are on a same line with negative alimentation, is it correct or do i need to separate ground and negative plug ?

and the skecth attached i replaced the pro mini by the uno…but i always respect the pin number.

thanks for you help

Duke08: yes you are right i try to plug by wire and not directly to the uno

So I think you had better explain why?

Paul, why i use an arduino uno with wire instead of nano

because i have only that ...my problem is to find the value of button to put in my program

poulailler_schema_bb.jpg
Thought as much. Didn't look at your schematic before - it however shows a Pro Mini, not a Nano.

So you have to write a simpler code which simply reads the ADC twice a second and displays the value for each button. You write it down and then determine values halfway between the steps you find to use as the values in the "if" statements in your full code.

I hope you read and understood the warning about the nasty wiring fault in some versions of this display shield.

It would be better if your "up" and "down" buttons and LDR were connected to ground with pull-up resistors to 5 V.

You would be better to use a 5 V switchmode regulator module to obtain your 5 V.

thanks