Тёмный

EP7 - How to Program Arduino - New Menu with Class and I2C LCD 

ForOurGood
Подписаться 2,7 тыс.
Просмотров 11 тыс.
50% 1

In this episode, I revisit my menu design, and greatly simplify the code, all with the help of a custom button class (which I will show you how to make). Additionally, I am using a larger Liquid Crystal display, controlled via an I2C interface board, just to add some spice.
This is the seventh episode in a series where I will be providing some practical lessons on how to write programs using Arduino. These lessons are intended to be useful information that you can use in your own code immediately, but I also hope it serves as a general lesson to get you thinking about how to write code better.

Опубликовано:

 

13 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 85   
@ForOurGood
@ForOurGood 6 месяцев назад
Attention ESP32 users. Please check my community post with things you should be aware of when implementing this project on a ESP32.
@gaal8762
@gaal8762 8 месяцев назад
Hi, can you share the sketch?
@RNDHVAC
@RNDHVAC 17 дней назад
hi can you help me? i follow your code and if i wanted to make the menu scroll in single/one row what do i change?
@ForOurGood
@ForOurGood 17 дней назад
@@RNDHVAC what is the size of your display?
@RNDHVAC
@RNDHVAC 17 дней назад
@@ForOurGood 20 x4 sir
@ForOurGood
@ForOurGood 17 дней назад
At 33:56 I define the numbers of rows as "DISP_ITEMS_ROWS = 3", if you change this to be "1" it should scroll in a single row (but I have not tested it). Good luck with your project, and please watch the video carefully and try to understand the best you can, if you can understand it well, then it should be easy enough to modify this code to fit most display style requirements.
@RNDHVAC
@RNDHVAC 17 дней назад
@@ForOurGood I've tried that it worked but i also wanted to place my menu in the 4th row i have change things and it keep start in second row how do i change that
@ForOurGood
@ForOurGood 17 дней назад
@@RNDHVAC Ok, so I understand you have got the single row scrolling menu working on the second row, but you want it on the 4th. The "menuItemPrintable" routine not only returns a positive state if the item is to be printed, but it is also responsible for locating the cursor. So the easiest way to push it down would be to add "+2" to the calculation for the Y-pos in the "lcd.setCursor" routine. Ideally you would be better adding a define for this offset value, and then adding this define value as opposed to hard coding the offset value.
@TOMTOM-nh3nl
@TOMTOM-nh3nl 2 месяца назад
Thank You
@ForOurGood
@ForOurGood 2 месяца назад
You're very welcome!
@KM-yw5jy
@KM-yw5jy 8 месяцев назад
I ported your menu system to an ESP32. Everything works wonderfully, but I wasn't able to achieve values up to 10,000 in the settings. Can you help me with this problem? Thank you
@ForOurGood
@ForOurGood 8 месяцев назад
First, you are going to need to right size your variable. To support values up to 10K you will at least need to use a “uint16_t”, and not the “uint8_t” I have shown in the demonstration (Always make sure you understand, and are using the correct variable types). Second, you will need to change the number modifying routine so that it supports up to a non-signed 16bit variable (uint16_t), and that is as simple as changing it to “void adjustUint16_t(uint16_t *v, uint16_t min, uint16_t max)”. Finally, make sure your display layout can support the number of digits you are trying to show. And that’s about all the advice I can think of right now. Happy New Year!
@edfriedrich.
@edfriedrich. 9 месяцев назад
Hi. Im trying to do a menu in the LCD but I have a problem, my code compiles and everything but the problems is in the LCD, when I set the cursor in the option that I want to select ( the cursor is an ">") but the submenu or the suboptions inside of the option where the cursor is, The suboptions appear beneath the option without even selecting them, I think the problems is the LCD, becuase it sparkles and doesnt even show some words; besides, Ive bee checking the code severla times and It does not seem to be the problem. What would you recommend me to do? Btw, great video, love the large videos when you put the whole code from the beginning instead of just showing it
@ForOurGood
@ForOurGood 9 месяцев назад
I know you already checked your code, but I would still suggest you suspect a problem with the code instead of trying to pin the problem elsewhere (actually, I always made this same mistake, and I still often need to remind myself, this is normal human behavior). I suggest trying to come up with some small simple test code if you can, to try to understand what is, and is not working with the LCD (try to prove it is really broken). It's not impossible the LCD is the problem, just extremely unlikely in my experience. My idea with this video format is so that you can follow along, each step of the way you need to check to see you are getting the exact same result I demonstrated. In that way, if you have a problem, you should be able to isolate the problem to a smaller area of code, and hopefully be able to solve it yourself. Additionally, if you can tell me which particular point in the video you are getting stuck, and explain the exact symptoms, it will help me in understanding the problem and suggesting possible solutions. Unfortunately, with the information you provided here I can’t provide any specific ideas on what might be the problem in your code.. Anyway, I am happy to hear the videos are useful to you, because they really suck to make, and really they don’t get that many views considering the work involved..
@edfriedrich.
@edfriedrich. 9 месяцев назад
​​@@ForOurGoodsure, and thanks. Well in my code the root menu has two options "program" and "change date" when you select the first option it is supossed to clear the LCD and show a new menu wich has seven options "Monday" to "Sunday" and every single one of them has 3 options once you select one of them "First hour" "second hour" and "third hour" and when you select one of them it clears the LCD screen and shows a message "You have selected this option (according to the day and the hour)" and the other option in the root menu wich is "change date" just shows a mesaage wich says "You have chosen change date". And the problem when the cursor wich is an ">" is pointing in the "program" option, it shows the option Monday beneath the word "program" and also "Wednesday" above, and without even selecting them, also in the first letters in the word "program" you can see "Sund" overwrite in the word, and I end up with the conclusion that the problem was the LCD because when I put the cursor pointing to "change date" the mistakes that i mentioned dissappear but the words seem to sparkle, like they appear and also dissappear whenever they want. And the thing about the videos, they are great for me, for I'd say some people dont like large videos, perhaps you should consider to add also short videos, like 10 min.
@ForOurGood
@ForOurGood 9 месяцев назад
Difficult to debug someone’s code remotely without seeing it, but let me try! First, there is no problem with the LCD, there are some bugs in your code. I can confirm this because you state that the display shows other menu information "without even selecting them", clearly that has nothing to do with the LCD. For me I can see actually 2 different types of bugs (possibly with some crossover). The first bug is related to the "sparkling" when selecting the second item. This is likely caused because the display is updating unnecessarily for some reason, and rapidly at that, causing the sparkle. It is also likely you are not pacing the loop, similar to the bug I made and showed @1:01:16. The second bug is related to the fact that the sub menu text is being overlayed on the root menu, even though you have not even selected. Hard to be specific here, but it is clear that you have a bug where it is branching off at some point and running some part of the sub menus code. Honestly, it looks like you’re struggling a bit, and that is ok, and all a part of learning. My recommendation to you is step though this video, typing it in word for word, and try to understand everything the best you can as you go. At each step confirm you are getting the exact result I am demonstrating, and at the end you should have a functional menu structure working exactly as I demonstrate. The next step would be to slowly, step by step, modify the code until it matches what you are trying to do. Good luck.@@edfriedrich.
@edfriedrich.
@edfriedrich. 9 месяцев назад
@@ForOurGood Thanks, I found the solution by changing the code to show the menu in the serial monitor and I spot the mistake, it was an error in the void menu. I did not use your code, but it helped me out in the process, thanks.
@ForOurGood
@ForOurGood 9 месяцев назад
Well done! @@edfriedrich.
@giovannivannella8695
@giovannivannella8695 3 месяца назад
Could you show all the finished code at once? because I watched the entire video and you went back and forth many times and modified many things and I missed a lot😃
@ForOurGood
@ForOurGood 3 месяца назад
Hi Giovanni, I am sorry you have some trouble, that is a part of learning, but please be assurred that many other people have confirmed the menu works fine. I don't release the code intentionally, to increase the chance you will learn more by doing, and solving the problems yourself. I suggest you follow the video step by step, confirming that the results you are getting at each step exactly match what I am demonstrating, and if at any point it does not match, then focus on that area, and see if you can solve the problem. Writing code is not always fun, but it can be rewarding when you understand and get things to work as you expected. Good luck!
@anandprasad5472
@anandprasad5472 5 месяцев назад
Sir super but ples code on oled menu sir
@snakezdewiggle6084
@snakezdewiggle6084 7 месяцев назад
How do I get Platform IO. Every thing I try will not work.
@ForOurGood
@ForOurGood 7 месяцев назад
I think I showed that in episode 4 of this series, check it out. There are also plenty of other channels on RU-vid that go into this topic in more depth. Should not be difficult.
@snakezdewiggle6084
@snakezdewiggle6084 7 месяцев назад
@ForOurGood Thanks for the reply. EP 4 is the one. I think I'll stick with writing assembler in txt files, so much faster for debugging.
@riteshpradhan9328
@riteshpradhan9328 9 месяцев назад
Hello sir, i really do appriciate ur work and really understand why u never choose to share your code and i really made a functional menu with your lession and i can prove i do learn and implimented just knowledge provided on ur videos but now m stuck on a place as m using tft-espi library and on my menu system their is a pointer arrow and also white box around my menu item to show pointer but now m stuck i cant figure it out scrolling vertically as shown on this video also i wanna implement if my menu item text is bigger than box m m using to show point then i want my text to scoll horizontally but as off now on my understand i did make that printmenufunction and i do impliment a logic like if its bigger than box then scroll the text else just print inside box also before this logis i do provide condition as u mentioned comparing value with subpos but issue is as i hv to call that print function as many times as how many items i want so if in middle one menu item text is bigger that scrolling function takes time and hold subsequent function to execute now wht to do and also i really cant understand logic behind verticle scrolling can you help me please
@ForOurGood
@ForOurGood 9 месяцев назад
It sounds like you have a good general understanding, and I also understand what you are trying to do with the oversized string. Typically I try to avoid such complications, and therefore have not tried it myself in Arduino, but generally it should not be so hard to do. First, just get the menu to work without the oversized text issue, only then move on to solving the oversized text. Now you should be able to modify the printmenuitem subroutine so it can deal with the oversized text when the item is selected. You will also need some text offset variable that the Printmenuitem will manipulate each time it is called and does the offset for the selected item. The final problem is when to update. As it is, the update is only done when the lineup changes, but now we also need to update at a given animation speed. If it was me, I would try to use the same animation counter for the pointer. If the pointer will change flash state, then I would force a chance to update the menu lineup, but in this case I would add additional logic so that only the selected item actually updates, which in turn would shift the offset. Hope that makes sense! I am just thinking it out in my head, so maybe I am just talking nonsense. Glad you found the videos useful and great to hear you're making a real effort to learn. Good luck!
@riteshpradhan9328
@riteshpradhan9328 9 месяцев назад
@@ForOurGood thanks a lot for reponse me i really do appriciate and if u wanna look my code once that would be quite nice for me but i really do wanna mention one thing all doing these thing as our hobby take your time am here and its really fasinating everytime i do watch your videos i do learn more new things and one context i should tell i really do excite how opensource runs our whole internet and there is people there who put there time and energy to teach and help new comer if some day i can help you thats would be a great opportunity for me
@riteshpradhan9328
@riteshpradhan9328 9 месяцев назад
@@ForOurGood i can provide my github repo link as i do update my codes as if someone would get inspiration to learn something or help me make my project otherwise atleast maintaining on github help me recover my mistakes
@ForOurGood
@ForOurGood 9 месяцев назад
@@riteshpradhan9328 You already help me simply by watching and learning, giving me relief I am not just wasting my time, and that's enough for me! One day in the future, I am sure you will help someone else to learn what you have learnt too.
@riteshpradhan9328
@riteshpradhan9328 9 месяцев назад
@@ForOurGood do u want to check my code once ? Coz i guess that will clarify how i implimented things here and then i can get some suggestion how not to do certaing things
@gamedinnah
@gamedinnah 8 месяцев назад
Very good tutorial! Thank you.
@ForOurGood
@ForOurGood 8 месяцев назад
You're very welcome!
@hoangminhhienle270
@hoangminhhienle270 6 месяцев назад
Your video is very good I ported your menu system to an ESP32. When it's done, everything is done. Check the LCD and the values in setting #2,3,4,6 are flashing continuously, it seems like the previous value overlaps the next value (ex: setting #2 59 overlaps 60). , and the plus and minus buttons are not working properly, the code is exactly the same as in the video because I have checked it many times. Can you help me with this problem? Thank you !!!
@ForOurGood
@ForOurGood 6 месяцев назад
Please tell me the port assignments you are using for the ESP32. Also, I assume you step by step followed the video, so please tell me the timestamp in the video where your testing and my testing did not match anymore.
@hoangminhhienle270
@hoangminhhienle270 6 месяцев назад
@@ForOurGood drive.google.com/drive/folders/1gfArUGxQSZZRa7qmekmvK5lJCL4sr5qX?usp=sharing Can you go to my Google Drive to see the code image and test video on the LCD to help fix the error? thank you
@hoangminhhienle270
@hoangminhhienle270 6 месяцев назад
@@ForOurGood drive.google.com/drive/folders/1gfArUGxQSZZRa7qmekmvK5lJCL4sr5qX?usp=sharing Can you go to my Google Drive to see the code image and test video on the LCD to help fix the error? thank you !
@hoangminhhienle270
@hoangminhhienle270 6 месяцев назад
@ForOurGood drive.google.com/drive/folders/1gfArUGxQSZZRa7qmekmvK5lJCL4sr5qX?usp=sharing Can you go to my Google Drive to see the code image and test video on the LCD to help fix the error? thank you
@hoangminhhienle270
@hoangminhhienle270 6 месяцев назад
@@ForOurGood Can you go to my Google Drive to see the code image and test video on the LCD to help fix the error? drive.google.com/drive/folders/1gfArUGxQSZZRa7qmekmvK5lJCL4sr5qX?usp=sharing thank you
@muhammad-td7mo
@muhammad-td7mo 5 месяцев назад
good work but where is code ???
@ForOurGood
@ForOurGood 5 месяцев назад
Thanks for the easy question! I put all the code in the video, so you can do good work too. Please enjoy 😉
@agahgokdag1845
@agahgokdag1845 5 месяцев назад
DO YOU THİNK THİS PROGRAM WİTH ENCODER ?
@ForOurGood
@ForOurGood 5 месяцев назад
I am not sure what you mean. Is your question "Do you think to make this program with rotary encoder (knob) ?". I have used a potentiometer+knob in my Mini-lathe project to control the speed, but I have not used it to manage the menu yet. Maybe in the future I will show how to do a menu with a knob.
@agahgokdag1845
@agahgokdag1845 5 месяцев назад
@@ForOurGood I'll FOLLOWED...
@colinward322
@colinward322 10 месяцев назад
Can you share the code
@ForOurGood
@ForOurGood 10 месяцев назад
Funny you should ask, I was just working on that. But it might take me a little time to prepare. In the meantime, please enjoy watching all my other videos 😁. Thanks for your comment and query.
@KW-ei3pi
@KW-ei3pi 8 месяцев назад
Wow. You talk really fast. I was exhausted in five minutes. I guess I'm just not cut out for learning in this way. Thanks anyway. Good information I'm sure.
@ForOurGood
@ForOurGood 8 месяцев назад
Hope you eventually find something that works for you. Thanks for taking the time to comment!
@snakezdewiggle6084
@snakezdewiggle6084 7 месяцев назад
@ForOurGood Its probably that Aussie accent 😉
@ForOurGood
@ForOurGood 6 месяцев назад
@@snakezdewiggle6084 actually my accent is pretty weak in these videos, just keep a little in there to keep it interesting. The truth is I just speak too fast, I have often been told that, it does put some people off. But actually when there is so much to get through in a single video, speaking fast is actually unavoidable.
Далее
Display examples - which one to use?
12:41
Просмотров 256 тыс.
EP1 - How to Program Arduino - Making Menus!
44:26
Просмотров 24 тыс.
Сколько стоят роды мечты?
00:59
Просмотров 139 тыс.
ФОКУС -СВЕТОФОР
00:32
Просмотров 336 тыс.
High precision speed reducer using rope
20:19
Просмотров 1,7 млн
Smart Meter Disaster!!
16:33
Просмотров 363 тыс.
Arduino with I2C LCD and Rotary Encoder
16:21
Просмотров 29 тыс.
Menu with voice & rotary encoder - Arduino
15:01
Просмотров 101 тыс.
The BEST DIY PCB Tutorial (ForOurGood PCB Method)
2:45:08
Сколько стоят роды мечты?
00:59
Просмотров 139 тыс.