logo elektroda
logo elektroda
X
logo elektroda

Course display on WeMos WiFi D1 R2 ESP8266 and LCD 2004 4*20 I2C Yellow HD44780

nowy.zielony.pczątku 2400 26
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18251225
    nowy.zielony.pczątku
    Level 5  
    Hello, I would like to make a cryptocurrency course display based on WeMos D1 R2 ESP8266 and LCD 2004 4*20 I2C. I am a beginner about arduino and need help to adapt the code from oled to lcd. The display would display 2 currencies BTC/PLN(first line) and BCH /PLN(second line). The api would download from bitbay.net Here is the code:
    Code: C / C++
    Log in, to see the code
    .
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #3 18252056
    nowy.zielony.pczątku
    Level 5  
    I found another code for just LCD and it works, only now I have a problem setting up the bitbay.net API
    Original code:
    Code: C / C++
    Log in, to see the code
    .


    The code after my change displays "BTC/PLN: 1.0".Please don't scoff, I don't know the programming language. I do by trial and error method using and comparing codes.

    Code: C / C++
    Log in, to see the code
    .
  • #5 18255351
    nowy.zielony.pczątku
    Level 5  
    nowy.zielony.pczątku wrote:
    Code: C / C++
    Log in, to see the code
    .
    nowy.zielony.pczątku wrote:
    Code: C / C++
    Log in, to see the code
    .
    nowy.zielony.pczątku wrote:
    Code: C / C++
    Log in, to see the code
    .
    .

    And I changed it to as above. It displays "BTC/PLN: 0.00"
  • #6 18260623
    khoam
    Level 42  
    nowy.zielony.pczątku wrote:
    I changed it to as above.
    .
    So, what specifically does this 'url' look like in your code now? In the post above it is without the changes I wrote about in post #4.
  • #7 18260737
    nowy.zielony.pczątku
    Level 5  
    Originally there was
    nowy.zielony.pczątku wrote:
    const char* host = "api.coindesk.com";
    and there is
    nowy.zielony.pczątku wrote:
    const char* host = "bitbay.net";
    There was
    nowy.zielony.pczątku wrote:
    String url = "/v1/bpi/currentprice.json";
    and it is
    nowy.zielony.pczątku wrote:
    String url = "/API/Public/BTCPLN/ticker.json";
    .
    The full API address is: bitbay.net/API/Public/BTCPLN/ticker.json
  • ADVERTISEMENT
  • Helpful post
    #8 18266789
    khoam
    Level 42  
    I have good news and bad news ;) The good news is that I have managed to rework the code from post #3 to work with bitbay.net. The bad is that it's quite a lot of changes. I've commented out the LCD references in the code - the results are displayed in the Arduino IDE serial port monitor. I have kept the original Italian comments :) .
    I used the information in this link:
    https://docs.bitbay.net/reference#wprowadzenie-1
    Code: C / C++
    Log in, to see the code
    .
    Result of the program:
    Code: Bash
    Log in, to see the code
  • #9 18269427
    nowy.zielony.pczątku
    Level 5  
    @khoam your code worked :D Except that another problem has occurred. The arduino reboots every now and then after showing the IP or after showing the course, this is the first problem, is this indicative of a faulty arduino? The second is that after connecting to the local internet it crashes on showing the IP address and does nothing further (the problem does not occur when connecting to the internet from the phone).
    Code: C / C++
    Log in, to see the code
    .
  • #10 18269450
    khoam
    Level 42  
    nowy.zielony.pczątku wrote:
    Arduino reboots every now and then after showing IP or after showing the course, this is the first problem, is this indicative of a faulty arduino?
    .
    I tested the program for several tens of minutes, but without the LCD. There were no reboots. Try testing my version of the program from post #8 and write if there are reboots too. If there are none, then the problem may lie, somewhere in the handling of the display.

    nowy.zielony.pczątku wrote:
    The second is that after connecting to the local internet it crashes on showing the IP address and does nothing further
    .
    Does it then also display "No connection to bitbay.net" in the serial port monitor in the Arduino IDE?

    Added after 1 [minute]:

    Are you powering the LCD module from +5V? Probably so, then haven't you forgotten about the level converters on the I2C bus between the Wemos and the display?
  • #11 18269714
    nowy.zielony.pczątku
    Level 5  
    khoam wrote:
    I tested the program for several tens of minutes, but without the LCD display. There were no reboots. Try testing my version of the program from post #8 and write if there are reboots too. If there are none, then the problem may lie, somewhere in the handling of the display.
    .
    It displays such bushes:
    [code]
    Code: Bash
    Log in, to see the code
    .
    Am I doing something wrong? Because the idea is to see the register about here when the arduino turns on and after waiting a while, yes?
    Course display on WeMos WiFi D1 R2 ESP8266 and LCD 2004 4*20 I2C Yellow HD44780 .

    khoam wrote:
    Do you power the LCD module from +5V?
    .
    Well yes I have connected to +5V
    khoam wrote:
    If so, did you forget the level converters on the I2C bus between the Wemos and the display?
    .
    What is this?
    I would add that other code e.g. for displaying "hello world", works fine. It does not reboot.
  • ADVERTISEMENT
  • #12 18269755
    khoam
    Level 42  
    nowy.zielony.pczątku wrote:
    Displays such bushes:
    .
    The speed of the serial port monitor in the Arduino IDE should match what is in Serial.begin(). In the program from post #9, this is 115,200.

    nowy.zielony.pczątku wrote:
    What is that?
    .
    I know in the popular "fritzing" on the net they ignore such converters. If you want one, don't use it.
    Read for yourself here:
    https://hackaday.io/project/8856-incubator-co.../log/30825-level-shifting-and-sdascl-pull-ups

    Later today I will try to test this code with the LCD display.
  • ADVERTISEMENT
  • #13 18269896
    nowy.zielony.pczątku
    Level 5  
    Ok, so your @khoam code from post #8 on the serial port shows the course correctly and connects to the internet from the phone. When connecting to the home internet, it happens as you thought i.e. it stands on showing the IP and every now and then it prints "No connection to bitbay.net". Probably blocking something on the network (network in DHCP mode if that matters).

    After uploading the code from post #9 the arduino restarts and on the serial port it displays this at once:
    [code]
    Code: Bash
    Log in, to see the code
    .
  • #14 18269947
    khoam
    Level 42  
    What version of ESP8266 do you have in Boards Manager? I tested with version 2.5.2
    What version of the ArduinoJson library do you have in Library Manager. I tested with version 5.13.5.
  • #15 18269979
    nowy.zielony.pczątku
    Level 5  
    The ESP8266 version is: 2.6.0
    The version of the ArduinoJson library is: 6.13.0
  • Helpful post
    #16 18270175
    khoam
    Level 42  
    nowy.zielony.pczątku wrote:
    The ESP8266 version is: 2.6.0
    .
    After installing this version, I actually observe reboots. Please perform a downgrade to version 2.5.2 and test.

    Added after 2 [hours] 37 [minutes]: .

    I have completed the tests. The version of the code from post #9 works with the LCD without any problems. The prerequisite is a downgrade of the ESP8266 in the Arduino IDE to 2.5.2. I'm (heavily) limiting my activity on the Forum from now on, so I hope someone will help you if there are questions from your side.
  • #17 18272184
    nowy.zielony.pczątku
    Level 5  
    @khoam Huge thanks for your help. The course display is working :D The final hurdle is the home network which I don't want to work with. I should add that I have eset antivirus which supposedly blocks something there but after unblocking it still the same.
    Course display on WeMos WiFi D1 R2 ESP8266 and LCD 2004 4*20 I2C Yellow HD44780 .
    Course display on WeMos WiFi D1 R2 ESP8266 and LCD 2004 4*20 I2C Yellow HD44780 .
  • Helpful post
    #18 18452278
    khoam
    Level 42  
    As of 5 February there is a new certificate for bitbay.net, so the SHA-1 fingerprint will also change (SHA256 is not supported in the Arduino HAL for ESP8266). It should be:
    Code: C / C++
    Log in, to see the code
    The current certificate is valid until 14.08.2020.

    Course display on WeMos WiFi D1 R2 ESP8266 and LCD 2004 4*20 I2C Yellow HD44780 .
  • #19 18465384
    nowy.zielony.pczątku
    Level 5  
    The project is complete, so I am closing the topic. The project wouldn't really have happened if it wasn't for the help of khoam once again huge thanks. The certificate that khoam writes about can be found on the Firefox browser according to the instructions in the attachment under the name Certificate. I have also designed an enclosure for this project, of course it can be used for another project that uses a wemos r1 d2 and a 4x20 LCD display (note before printing please measure the distances of the slots in the wemos, I modelled the dimensions on ready-made enclosures for wemos and the dimensions did not match reality). The code may appear to be "pooled" (these are my inserts not khoam's) but it works and does the job. The whole project can be downloaded at this link: https://drive.google.com/open?id=1qeVcJkwW3P7SMQERinYGUtUpMU9ug-X7

    Course display on WeMos WiFi D1 R2 ESP8266 and LCD 2004 4*20 I2C Yellow HD44780 .
  • #20 18487493
    nowy.zielony.pczątku
    Level 5  
    There are two things to be improved/revised. One as the khoam himself pointed out that it would be useful for authentication from bitbay to be via a CA certificate rather than a fingerprint. I've tried to implement this but it's not my level, I've only just started with arduino. Where do I get something like the picture from? How do you do it? The other thing is that I would like the display backlight to turn on when I "wave" my hand, and it works, but the problem is that there are delays and other functions that delay. Do you have to use esp32 or is it enough to improve the code somehow? I tried to solve this problem with the millis() function but was unsuccessful.

    Course display on WeMos WiFi D1 R2 ESP8266 and LCD 2004 4*20 I2C Yellow HD44780 .

    Code: C / C++
    Log in, to see the code
  • #21 18487643
    khoam
    Level 42  
    Perhaps a better solution to start with would be to retrieve this data without validating the site certificate or fingerprint. The main change is to replace the following line of code:
    Code: C / C++
    Log in, to see the code
    By the following:
    Code: C / C++
    Log in, to see the code
    Test if this will work with the "api.bitbay.net" page.

    nowy.zielony.pczątku wrote:
    The second thing is that I would like the display backlight to turn on after a "swipe" of the hand and that works only problem is that there are delay-e and other fucktions that delay.
    .
    I understand that on any of the ports the logic state changes due to a "swipe" of the hand? If so, the easiest thing to do would be to connect an interrupt to that pin and set the display to brighten in the interrupt handler - this would then happen immediately regardless of the delays in loop(). Turning off the backlight would have to happen already in loop() after the specified time.
    https://randomnerdtutorials.com/interrupts-timers-esp8266-arduino-ide-nodemcu/
    https://arduino-esp8266.readthedocs.io/en/latest/reference.html#interrupts
  • #22 18518471
    nowy.zielony.pczątku
    Level 5  
    khoam wrote:
    Maybe a better solution to start with would be to retrieve this data without validating the site certificate or fingerprint. The main change is to replace the following line of code:
    Code: c Expand Select all
    client.setFingerprint(fingerprint);
    By the following:
    Code: c Expand Select All

    client.setInsecure();
    Check if this will work with the "api.bitbay.net" website.


    The change works with api.bitbay.net.
    khoam wrote:
    new.green.start wrote:
    The other thing is I'd like the display backlight to turn on when the hand is "swiped", and that works only problem is there are delay-e and other fuctions that delay.

    I understand that on any of the ports the logic state changes due to a "swipe" of the hand? If so, the easiest way would be to connect an interrupt to that pin and set the display to brighten up in the interrupt handler - then it would happen immediately regardless of the delays in loop(). Turning off the backlight would have to happen already in loop() after the specified time.
    https://randomnerdtutorials.com/interrupts-timers-esp8266-arduino-ide-nodemcu/
    https://arduino-esp8266.readthedocs.io/en/latest/reference.html#interrupts
    .

    Well, not really because the switching would have to take place in a given range of e.g. 10-25 cm and the state changes every now and then. I bought an esp32 to solve this problem. To be precise, on one core would be added a watch and measuring the distance and on the other core would be added downloading data from api.bitbay.net. I uploaded such test code and the board keeps rebooting. Also, did I insert the future tasks well in the brackets "for (;;) "?

    Code: C / C++
    Log in, to see the code
    .
    Register during reboot

    Code: Bash
    Log in, to see the code
  • #23 18518691
    khoam
    Level 42  
    My bet is on the stack size being too small for the individual threads - you're using Serial.print() in the callbacks, and that eats up some memory. I suggest you increase the stack size to 4096 and check. Overall trend right ;) .

    Install yourself an Exception Stack Trace Decoder in the Arduino IDE:
    https://github.com/me-no-dev/EspExceptionDecoder

    This delay(500) between the creation of individual threads is for what purpose?
  • #24 18523151
    nowy.zielony.pczątku
    Level 5  
    The cause turned out to be a limey usb hub. And again, another obstacle. I copied the code from esp8266 to esp32 and errors are popping up. With the added
    Code: C / C++
    Log in, to see the code
    .
    displays: 'class WiFiClientSecure' has no member named 'setInsecure'.
    with added
    Code: C / C++
    Log in, to see the code
    .
    displays: 'client' was not declared in this scope

    Moving this task to a void loop changes nothing.

    Removing one and the other causes this error to be displayed:
    Code: Bash
    Log in, to see the code
    .

    Code: C / C++
    Log in, to see the code
    .
  • #25 18523294
    khoam
    Level 42  
    The setup() and loop() functions are part of a thread (task) called loopTask, for which the priority is set to 1 - you cannot change it.
    You have set the same priority in your tasks - so I suggest you increase the priority for these tasks to at least 2.

    Additionally, in the callback function codeForTask1() at the very end of the for() loop, insert a delay() with such a time interval as is sufficient to update the time on the display. At the moment this gets done every few ms and takes most of Core 0's time - there are also WiFi-related 'system' operations on this core, so there could be a problem.
  • #26 18555772
    JanuszKornas
    Level 11  
    nowy.zielony.pczątku wrote:
    Does esp32 need to be used or is it enough to tweak the code somehow? I tried to solve this problem with the millis() function but failed.
    .
    Once you understand this code, you will grasp what you want and be able to do not such things....
    Link

    In general, the principle of using millis() instead of delay() is that the processor will fly through the loop as fast as the clock allows it to, and it will only perform your task (LED state change or whatever) when the time comes. This is a different way of solving your probem than interrupts.

    Interrupts are useful for the program's response to the user. The user is usually impatient and would like his events to be handled immediately. So, in the interrupts you change the state of some variable (the motion detector has detected movement), and in the main loop you react to such a change and determine in how much time it should e.g. turn off the backlight (you read the time with the help of millis() ).

    In the loop you execute functions that change states of variables (and also in interrupts), and then further in the loop you execute functions that execute something if some variable says so, or e.g. the time has come.

    You can, of course, use ready-made libraries for this, but if you do not implement such simple "multitasking" yourself, at least once, you will not understand how such libraries work.
  • #27 18556015
    khoam
    Level 42  
    JanuszKornas wrote:
    As you understand this code, you will grasp what you want and be able to do not such things....
    .
    But on an AVR rather than an ESP32 ;) .
    A version of the flashing diode for ESP32 is for example here:
    https://www.savjee.be/2020/01/multitasking-esp32-arduino-freertos/

    JanuszKornas wrote:
    Generally the principle of using millis() instead of delay() is that the processor flies through the loop as fast as the timer allows it, and will only perform your task (changing the state of the LED or whatever) when the time comes. This is a different way of solving your probem than interrupts.

    On the ESP32, the delay() function works completely differently and calls the RTOS vTaskDelay() function - other tasks (threads) may be executing during the delay(). Using millis() is therefore somewhat pointless in such a case.

Topic summary

A user sought assistance in adapting code for a cryptocurrency course display using a WeMos D1 R2 ESP8266 and an LCD 2004 I2C. The initial code was designed for an OLED display and needed modifications to work with the LCD. The display was intended to show BTC/PLN and BCH/PLN prices sourced from the Bitbay API. Various responses provided guidance on modifying the code, including changing the API URL and addressing issues with the display and network connectivity. The user encountered reboots and connection problems, which were resolved by downgrading the ESP8266 board version and adjusting the code. The project was completed successfully, with suggestions for further improvements, such as using a CA certificate for authentication and implementing a hand-swipe feature for backlight control.
Summary generated by the language model.
ADVERTISEMENT