logo elektroda
logo elektroda
X
logo elektroda

ESP8266 + Encoder + TFT ILI9341: How to create a menu to set the parameters of the DS18b20 thermomet

tvmaniak 1227 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19482736
    tvmaniak
    Level 12  
    Hello.
    I am looking for help in writing a simple menu. I wanted to build a simple thermometer with TFT display (SPI on ILI9341) and encoder. Functionality simple. Measuring the temperature of a liquid with an alarm function that activates when the set maximum or minimum temperature is exceeded. I wanted to add a simple menu where you can set the minimum and maximum temperature, enable/disable the sound alarm function and set the temperature sensor correction parameter (DS18b20). The program itself (without the menu) is almost written, but I have been sitting on the menu for almost 2 months (in my spare time). I have looked through dozens of examples on the internet, and can't seem to get it right. I'm already at the stage of throwing it in the rubbish. It may be simple, but after testing dozens of examples, I'm already confused and complicating things for myself. I tried using tcMenu. A nice generator, but for more advanced users. The menu works fine, but I can't seem to get it to work with my programme.
    Please help, some tips.
    Best regards.
  • ADVERTISEMENT
  • #2 19482874
    2konrafal1993
    Level 38  
    It would be nice if you posted the code you have, then it would be easier to explain what to do and how to do it. It would be even nicer if you wrote down what you are programming in. A simple menu, the simplest one can be created using a select case, I did one and it worked for me. It might be helpful to write out the whole menu on a piece of paper, not just the code, but the structure of the menu and what should be where. To operate such a menu, all you need is an encoder and one button, it can be in the encoder to make it easier.
  • ADVERTISEMENT
  • #3 19483047
    tvmaniak
    Level 12  
    As usual, I have not provided the basic information :) .
    I am writing the program in Arduino. Of course I used an Encoder with a KY--40 button. The assumption is that a long press of the button turns off the thermometer (I will probably use the sleep function) a short press starts the menu. I also tried to use the switch case, but I couldn't combine this with the encoder operation. There are many libraries for the encoder. The menu itself is literally just a few items. Alarm on/off, set minimum temp, set maximum temp, set detector adjustment. Each of the changes will be stored in the Eeprom. Below is the program code I have written so far. I stopped further writing when I got stuck on the menu.
    Code: C / C++
    Log in, to see the code
    .
  • #4 19520184
    marcingebus
    Level 11  
    Start from the beginning, that is, take some Menu with an Encoder as an example and master it. And then add your program to the working example. Generally, you either do Switch-Case, or a much more complicated solution on objects, which will be more elegant in code, but more difficult for beginners to understand. I did on Switch-Case and then modifying when I expanded was a lot of work. Menus like this are two parts that operate on global variables. One part is handling the Encoder, which sets these variables. The other part is the display of the menu, depending on what values the variable takes. Both parts can be called e.g. every 0.5s, or every 0.1s, or whatever suits you in the main loop. In my case, I think the Encoder called something from the interrupt that changed some value responsible for the encoder movements. You do this kind of quasi-multitasking 'by hand'.
  • #5 19520341
    tvmaniak
    Level 12  
    Thanks for the hint. However, the problem is that I could not find such an example for ESP8266 and TFT display.
  • ADVERTISEMENT
  • #6 19520380
    mpier
    Level 29  
    Hello,
    "Switch-Case" has already been mentioned and it will be simple. To make it easier, I suggest you draw this menu on a piece of paper, e.g. like this:
    ESP8266 + Encoder + TFT ILI9341: How to create a menu to set the parameters of the DS18b20 thermomet .
    The whole drawing is one "switch" and the rectangles are "case". The arrows respond to the buttons, here "plus", "minus" and "ust" (settings).

    Greetings

    I added at 17:18:

    I have inserted a drawing. Two minutes of drawing is the whole creative part. Now it just needs to be rewritten in C. It is a simple state machine, I assume not everyone will like it.
  • #7 19521520
    marcingebus
    Level 11  
    I wrote my menus on ArduinoMega, maybe look there for the simplest possible example. Once you understand how it works you can expand it to your size. It is sometimes a mistake and an ordeal if you immediately want a big thing without understanding what each comma or variable is used for. Small is easier to understand. Start small, understand it, then convert it to big.

    It still occurred to me that you need to make the programme multitasking. Which seems obvious to me, but.... Look up how the "Blik without delay" example works. Without such basics you won't get off the ground.



    Added after 4 [hours] 26 [minutes]: .

    In my code it looked like this, yes, maybe you can find something from the examples with fragments like this. Moving the encoder and pressing the button triggered an interrupt, which only changed the value of certain variables.

    //RotaryEncoder
    #include <Encoder.h>
    Encoder myEnc(pinEncoder_dt, pinEncoder_clk);
    int newPositionEncoder,
    oldPositionEncoder = -999,
    changePositionEncoder;.....

    and

    //Button
    #include <EasyButton.h>
    #include <TimerOne.h> /* Sheduler - NO, TimerOne by Jesse ... */
    volatile uint8_t clickCounter=0; // number of clicks in the given time, 100 - if button held down longer
    volatile uint8_t clickCounter2show=0; // as above.
    volatile unsigned long nowEnc, // current click time of the Button
    lastClick=0; // time when the Button was last clicked
    // Instance of the button.
    EasyButton button(pinEncoder_sw);

    I, in my case, extended this so that one click, meant OK, two clicks ESC, and a long hold, was a jump to some specific place in the Menu.
  • ADVERTISEMENT
  • #8 19545563
    uzi18
    Level 24  
    Or use a ready-made product such as espeasy ...
  • #9 19546245
    marcingebus
    Level 11  
    The author writes:
    tvmaniak wrote:
    Welcome.
    I wanted to build a simple thermometer with TFT display (SPI on ILI9341) and encoder .
    .

    uzi18 wrote:
    or use a ready-made one like espeasy ...


    Is ESPEasy able to handle Encoder and TFT display connected to ESP????

Topic summary

The discussion revolves around creating a simple menu for an ESP8266-based thermometer project using a TFT display (ILI9341) and an encoder (KY-040). The user seeks assistance in implementing a menu to set parameters for a DS18B20 temperature sensor, including minimum and maximum temperature settings, alarm activation, and sensor correction. Various suggestions are provided, including using a switch-case structure for menu navigation, drawing the menu layout for clarity, and starting with simple examples to build understanding. Some participants recommend using libraries and existing frameworks like ESPEasy for easier integration of the encoder and TFT display functionalities.
Summary generated by the language model.
ADVERTISEMENT