Notifications
Clear all

Keypad control not working

156 Posts
3 Users
24 Reactions
9,671 Views
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

@will, thanks a mil, this is actually mmmm a lot better and more readable. It is just after 2 in the morning here, so I am off to bed, again, I really appreciate your help. I have compiled it, and get an err of "'moveToShed' was not declared in this scope" on line 141. We can really continue when you are free, tomorrow or next week.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 

@will 

I had been trying to follow along with all this but these libraries are a nightmare.

Downloaded Adafruit-GFX-Library-master.zip and still errors.

Multiple libraries were found for "Keypad.h"

 


   
kobusven95 reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

@robotbuilder 

Yeah, there have been a few threads where the dreaded Keypad has appeared. One never seems to be able to get a single version, or, of you can get down to a singleton - it appears to be the wrong one.

The original code was quite bulky and poorly indented, so i didn't even try to compile it. just read it and try to absorb the gist of it.

Unfortunately, the new version I uploaded still require the same libraries, so it probably won't compile for you either. I found the only way to get rid of the stuff was to comment out some lines that used them or #defining them to something that I could use to "simulate" a keypad entry (for example).

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 
Posted by: @kobusven95

It is just after 2 in the morning here, so I am off to bed, again

Yeah, I thought you might be in Africa.

I have compiled it, and get an err of "'moveToShed' was not declared in this scope" on line 141.

Yep, I took a look at it and it appears that I go too loose and uninhibited and fouled up a couple of things. That particular error, I think, was caused by the "while" loop in GetNumber not having a closing "}".

While I was at it, I added some code to actually set the value of "num" before it gets tested, I'm assuming that kid.getKey returns a char value equal to the key pressed. So I subtract '0' to turn it into a single integer digit. For instance '5'-'0' = 5.

I also changed the starting prompt to use displayInfo, after all it's available 🙂

Here's the new version (same name as before, since it IS replacement).

I've deleted the .ino file since there's a new, improved version in a following post.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

@kobusven95

OK, here's a new version with a lot more changes. I'm going to stop working on it until you have a chance to read it, compile it and ask questions about it.

I moved the step0-step9 values into an array shedSteps which allowed me to combine all of GetNumber() into only 4 lines of code. It seemed pointless to call it from loop(), so I moved the code into loop() and deleted the function.

Although the variable "num" was supposed to be returned from GetNumber() it was never set and never returned by the old function. I have left "num" as a global value and it can be accessed in the sketch, but be aware that it will retain its previous value until changed in loop().

I removed the char confkey, since it s no longer used.

The step0-step9 values are used to turn the stepper, but they seem to be angles rather than step counts. Is that correct or is that aspect still being developed ?

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 
Posted by: @will

@robotbuilder 

Yeah, there have been a few threads where the dreaded Keypad has appeared. One never seems to be able to get a single version, or, of you can get down to a singleton - it appears to be the wrong one.

Not sure what hardware @kobusven95 is using exactly.  I went to Bill's tutorial on the keypad and the liquid crystal display and the provided code worked fine.  Just have to buy a keypad and hook up the stepper motor.  Probably not much use to @kobusven95 if he is using a different keypad or display.  However the logic is probably the same although I am not sure what is meant by "... and confirm the selection with a C".

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

@robotbuilder 

IIRC I think he said it was a MEGA2560. Must be something big with all those high pin numbers 🙂

The stepper motor commands don't look right to me yet, seems like he's using degrees instead steps and there doesn't seem to be any zeroing for the bridge start position. I'm expecting that the sketch will grow.

For the time being, I think he's just trying to get it started, all parts initialized and get the bridge turn commands working. I'm no railroader so it's all new and interesting to me.

That would be the smart move, get the messy stuff working and then move on to the complicated bits adding new code only after each addition is tested and approved.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 
Posted by: @robotbuilder

Not sure what hardware @kobusven95 is using exactly.  I went to Bill's tutorial on the keypad and the liquid crystal display and the provided code worked fine.

That's major advance !

although I am not sure what is meant by "... and confirm the selection with a C"

You may find it easier to work with the latest version I sent to him (ModSet0.ino) as it collapses much of the logic into a few oft-called modules. The result is that it's a lot easier to wade into (although not yet compiled or verified).

The "C" to confirm refers to the selection of a train destination corresponding to a keypad entry of '0' - '9'. After the selection is chosen, it is displayed to the screen and then the user is asked to press the 'C' button on the keypad to confirm that the shed id selection is correct.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 

@will 

I came into this thread a bit late and am guilty of not reading all the posts or code in enough detail! I now get what is going on! Unable to compile your last example until I fix the Adafruit_I2CDevice.h missing error.

The stepper motor commands don't look right to me yet, seems like he's using degrees instead steps and there doesn't seem to be any zeroing for the bridge start position. I'm expecting that the sketch will grow.

I noticed the deg0 to deg9 variables in your example are not being used. Anyway I will spend some time on the code and wait until @kobusven95 responds.

 


   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

@robotbuilder @will

Hardware: Arduino Mega 2560, 2.4" TFTLCD shield, Keypad, stepper motor, ( https://www.walmart.com/ip/2-PCS-DC-5V-Micro-Stepper-Motor-28BYJ-48-With-5V-ULN2003-Drive-Test-Module-Board-5-Line-4-Phase/826688419). I will upload photos of it, as well as the keypad script.


   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

@will, please see attached.

20211211 083830
20211211 083815
20211211 083808
20211211 083759
20211211 084114

 


   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

@kobusven95 

Wow, don't you ever sleep ? 🙂

Thanks for the pictures and the include files. I'll install them tomorrow and see how that works.

Anything seems possible when you don't know what you're talking about.


   
kobusven95 reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 
Posted by: @robotbuilder

@will 

I noticed the deg0 to deg9 variables in your example are not being used. Anyway I will spend some time on the code and wait until @kobusven95 responds.

Those variables are from the OP's source, not added by me. As I said, I expect that there will be more happening with the servo and that the current version seems to be using angles instead of step counts.

There used to be similarly named variables step0-step9 which I collapsed into the array shedSteps.

Anything seems possible when you don't know what you're talking about.


   
kobusven95 reacted
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

@will, @robotbuilder

it compiles without errors.

but, there are a few workflow errors. ie. display do not refresh after the "bridge is moving message", stepper is dead etc. Busy looking into those.


   
ReplyQuote
Page 4 / 11