Enhanced LiquidCrystal

one more clue, perhaps, is that the while which 2 lines autoscroll seems to depend on where I wrote last (the 2 lines I didn't write last are the ones that scroll), the autoscroll commands are always sent first to the upper 2 lines then to the lower 2 lines.

I think I am finished with the project at this point, unless some smart person can figure out that last bug. I've done a lot more than I set out to do at the beginning, which was just to get it working with the 40x4 display. I've learned a lot and had a lot of fun doing it.

I've learned a lot and had a lot of fun doing it.

... and provided a very useful contribution to the community on your first try. [smiley=dankk2.gif]

... and provided a very useful contribution to the community on your first try.

Agreed [smiley=thumbsup.gif]

Mowcius

Hey is the server down again. I have downloaded your new code but appear to have lost it and I don't seem to be able to download it again...

Mowcius

Thanks to Ben and Don for all their help. I think the server is OK now.

It did download again, eventually (took like 5 minutes) but thanks again for the code.

Mowcius

I've known about the bug with 40x4 displays and autoscroll now for 3 weeks and it finally occurs to me that there is surely an UGLY rather stupid work around for it. I haven't tested it actually but I'm sure it would work. it would involve calling autoscroll twice in succession. I suppose it might be necessary to reposition the cursor between the 2 calls. Even if for some reason the hd44780 controlling the 2 lines that scrolled after the first command received the second one, it would just keep scrolling. It could even be built into the library as a special case only with 40x4 displays and I could pretend I'd fixed the bug. But it would be ugly and stupid. :-/

Well ugly and stupid would be better than not working...

Mowcius

I posted the idea so people could use the work around. And perhaps to inspire someone with a different perspective to see a real fix.

Scrolling gets blown out of proportion when I work on the library, because its the complicated bunch of things the display can do and so is involved in many of the tests in my test program (which is included with the download). In real code, I have no use for it. I knew about the bug for at least 2 weeks before I posted anything about it; I was pretty sure no one would find it in a short period of time; I wouldn't have found it except that I started putting together a thorough test procedure when I started working on the library, adding tests as I added features and found problems to demonstrate. Then before I post code I run 4 interfaces on 4 different shapes of LCDs, 2 interfaces on the 40x4.
That takes almost an hour but it leaves me pretty confident I've found everything I ever knew could be a problem.

Great work.

I've been wondering about the RW pin.

I have a project in development that needs a very fast bar graph. I was going to use the programmable characters to make the last segment variable length to get a one dot wide bar resolution.

There are two, possibly academic questions:

  • Is "faster than the eye can see" really true for something like a bar graph?

  • Is there any way to, and do you get any advantage out of, trying to sync the value update (which is related to analog sampling in my case) to the refresh cycling of the LCD?

I was thinking of an experiment that involves getting the bar graph working, and then using something like an adjustable sine wave synthed signal to drive it. Walk the frequency up until you can't really get the bar graph to follow the signal. Try that with and without the RW.

I'm in the middle of building a shield for this project and can't try this experiment right now, but I'm planning to. Do you have an old version of the code around I could try?

Well I would like to do a bar graph on my 40x4 but it seems very slow at refreshing. When I write one character over another it is visibly taking a long time. Any ways of speeding it up?

I did see something on fast refresh on LCDs some time ago but I can't for the life of me find it. Anyone else know where it is?
[edit]I can't have been looking very hard before, here it is:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264215873/0[/edit]

Mowcius

"writing 80 characters to the screen then 80 blanks and looping through that 20 times. The results are:
4 data pins 727 milliseconds
8 data pins 644 milliseconds"
so (80+80)*20 = 3200 characters in less than 3/4 of a second. your bar graph is one line long so either 20 or 40 characters. Lets say you have 40 chars. 727 *40/3200 = 9 milliseconds. Probably the rest of your code will be the limiting factor.

in the benchmark I print 80 character long strings. If you use a for loop and call once per character, of course it will go slower because of all the loop and call overhead. If you need maximum speed you might create an array of strings of different lengths for the different bar lengths.

Yeah it was the other code. After having a play around it is much faster now :slight_smile:

Mowcius

other thoughts about bar graphs that may be obvious:

if you're using an array of strings they should follow the pattern "x ", "xx ","xxx ",.. so that trailing spaces overwrite what was left over from last time. If you use the for loop and single character print you want to do the same thing--print spaces over the old bar. Using clear takes 2 milliseconds and then you have to reconstruct the whole screen.

A program that does bar graphs is likely to want to divide somewhere and if you can work it out so that >> will do, that is a LOT faster. so putting a short label on the line and having 16 or 32 segments in the bar may have a big payoff in speed.

Yes, I will be sticking a bargraph in my media player project. It has an rMP3 and a 40x4 LCD showing lyrics, time, track etc. I will have a bargraph for the volume and for the track length (probably) but they don't need to be very fast...

Mowcius

I'm probably overthinking this. I had thought that the display had something like a 200Hz refresh cycle, but that appears to be the refresh of one row, not the whole display. The datasheet I'm looking at shows a 64hz frame rate. at 64 Hz, I only need to get the bar graph into the LCD in 15 ms more or less, which clearly works without the RW. I don't really want to use the RW, because I want to use the pin for something else :slight_smile:

Ok, for my media player thing (mentioned above) I have been experimenting with code.

I have a for command measuring the volume (mapped from 0-39) and then it writes the boxes on the LCD line accordingly. I tried getting it to write spaces over the unused places but it was very slow. I am currently getting it to write 40 spaces over the whole line before the write and this is just visible (when the display is doing nothing else).

Anyone got any ideas of what I can do to speed it up?

Mowcius

The media player sounds like a neat project!
How do you map the volume to 40 segments? Integer division is slow, but not a disaster. Floating point IS a disaster in terms of performance, of course. I suggested 32 segments and >>. There may be a way to think in terms of 64 segments and >> with the result ending up in only 40 real segments; I'm usually too dull to work tricks like that out.

If you were really willing to dig into Liquid Crystal you could take what I had posted with the busy flag, stop making it a library but pull it into your own program. At that point you know which pins are used and you can combine those 2 things with issue 140 in the google code forum for Arduino to use AVR ports instead of digitalRead and digitalWrite. This would make checking the busy flag feasible, faster than ever, and hugely speed up some other small places. You would need to use RW, so you'd lose that pin. There were some delayMicroseconds(1) lines that I commented out but never actually removed from the source which would have to be reactivated. That would be a lot of work but the Liquid crystal speed up would be roughly 40% over what it is now, I think. As long as its a library routine, the AVR ports/issue 140 thing seems unavailable.

One of the tricks to using AVR ports is that you can reverse the 4 data pins from write to read during the busy flag check with 1 instruction rather than 4 separate slow calls to functions that have a complex job mapping them; you and the compiler would now know at compile time how that mapping took place. That's where the big saving comes from.

As I was walking the dog I realized that one way to implement this would be to leave liquid crystal as a library routine, but when you call it pass in a function name for it to call to check the busy flag. then you would have to write that one routine. I REALLY like this idea. I will probably get to it in the next couple of weeks.