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:
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.
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
@khoam your code worked 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).
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?
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?
.
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.
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]
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.
.
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.
@khoam Huge thanks for your help. The course display is working 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.
.
.
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.
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
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.
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.
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.
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 (; "?
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 .
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:
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.
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.
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.
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.