Hello.
I have a ST7920 lcd connected to an arduino uno, the code reads 1 temps sensor and displays the data in 8 rows. Later i will connect 6 more sensors. I used u8g2 lib.The code is working but the refresh rate of the readings is rather slow, every line update is about half a second (the first line takes 0,5 seconds, the second 1 second and the last one updates every four seconds.. Probably is the code is written but thats what i found.
Below is the code and the wiring.
You are calling the LcdScreen() function in every iteration of loop() - that's bound to slow things down. It really only needs to be updated 2 or 3 times per second.
Also you are updating all parts of the LCD in on call to the function. Split that up so (say) 2 lines are updated on each successive iteration of loop(). The difference should not be noticeable to the human eye.
I split the LcdScreen() in 4 parts, each part is reading 2 sensors and displaying their data.
Each sensor updates it's data in the screen every 8 seconds, one by one.
So nothing happened, it's still slow. I tried to update only the reading values in the screen and keep the rest unchanged but no luck.
I'd be inclined to try it without them, or at least to drop nextPage and move the firstPage call into setup. They're the only bits of your code I can think of that could be responsible for the slowness and since you're not using multiple pages as far as I can see, you may not need them.
first/next is how that library handles that display. It just is. I haven't tried doing without them even if I am sure the paging is not needed. YMMV as usual.
You are slowing things down by reading the temperature sensor within first/next block, and maybe more often than strictly necessary at that. I don't know how your temperature library works, but it takes a long time to get the temp from that sensor, there are ways to split the request to take a new reading from getting the new reading whilst you do something else, possibly updating the display with the previous requested reading.
In my code above I have LcdScreen displaying 8 labels and temp readings. I split the screen in 2 parts, screen1 (labels) and screen2 (readings). Normally labels should be displayed first and readings after. Strangely it displays 1 line at a time, label-reading then label-reading and so on. It takes 16 seconds to display everything.
I moved firstpage to setup. As a result, only 1 line is printed. I removed do-while and first-next pages and then I have only readings..
So they are needed.
alto777:
I don't know how your temperature library works, but it takes a long time to get the temp from that sensor, there are ways to split the request to take a new reading from getting the new reading whilst you do something else, possibly updating the display with the previous requested reading.
This concept is key to getting reasonable performance using DS18B20-type sensors and is supported by the DallasTemperature library by using the proper API calls. Using the simple-minded, blocking, version of 'requestTemperatures()' followed by 'getTempCByIndex()' is the easiest technique for newbie programmers to understand. But, it is the worst choice for overall system performance.
Is there another way for reading temperature besides the one you mentioned? Is it faster?
I made a very simple project. Reading 8 sensors and displaying them in Serial. Print() to pc. It took almost 5 seconds to display all 8 readings in 1 line.
koskap:
Is there another way for reading temperature besides the one you mentioned? Is it faster?
Yes, if I say some method gives the worst performance, then, obviously, there's a better way. That's what I was referring to. Use non-blocking techniques to start the conversion, do useful work while the conversion is taking place, and use device addresses (rather than 'ByIndex") to retrieve the temperature readings. See My Reply #13 in this Thread.