I have the Serial LCD 20x4 display, and I use SoftwareSerial to talk to it. Occasionally, it is a little glitchy, and there are a couple things that either don’t work, or I can’t figure out how to do, and I was wondering if anyone had any insight on the product.
There is a great clear screen command. However, the Variable.println(“Display this”), does not add a carriage return. It just seems to add a garbage output carriage return character. How can that be done?
I’d have to check to be sure but I doubt that the println() command has forgotten to send a CR. That’s the difference between it and a print(). I wonder if there’s something else running in your code that could screwup the timing needed to run at whatever baud rate you’re using (what is it ?). The library page says the following …
The library has the following known limitations:
If using multiple software serial ports, only one can receive data at a time.
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
Not all pins on the Leonardo support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
If your project requires simultaneous data flows, see Paul Stoffregen’s AltSoftSerial library. AltSoftSerial overcomes a number of other issues with the core SoftwareSerial, but has it’s own limitations. Refer to the AltSoftSerial site for more information.
http://arduino.cc/en/Reference/softwareSerial
It’s set to the standard 9600. It’s a standard Arduino (Red Board) that I am testing on. I will be using a Mega for final production of what I am creating. If you look at the page on SoftwareSerial (I can try to find the link again), even there it says it sends a line feed “character” and not actually the command for a line feed.
As I write this, maybe this is the difference??? The Serial LCD ONLY recognizes commands when you preface it with Variable.write(0xFE);. This seems to tell the unit, wait a second, the next number or hex is acutally a command set instead of a character, for example, setting the cursor position or clearing the screen. Maybe println simply cannot work as some of the docs suggest, but maybe by adding the following will. I will try shortly.
Variable.write(0xFE);
Variable.write(13); //ASCII for carriage return
And the answer is… no. That did not do a carriage return. It did make the cursor blink, however.
Maybe a little more info about what you are trying to accomplish would help us… Why do you need a carriage return? Why not use ```
lcd.setCursor(0,1); //Sets cursor to the the second line
codlink:
Maybe a little more info about what you are trying to accomplish would help us… Why do you need a carriage return? Why not use ```
lcd.setCursor(0,1); //Sets cursor to the the second line
That's because he's using a serial LCD and the Arduino LCD library only works with parallel load LCDs.
Still I think you and his last tries are onto something. The PIC decoding the data is obviously not looking for the CR character (ASCII code) as a command and is instead trying to display it. So there must be a way of commanding a new line, or going to a line, via the command set instructions.
EDIT : and the answer in section 3.3 of the manual.
https://www.sparkfun.com/datasheets/LCD/SerLCD_V2_5.PDF
Ah, I gotcha… It being Serial never registered to me…
Thanks you guys. I was going to revisit this question as I went to a Spark Fun basic training on Arduino this weekend. That was one of my questions, but they responded how you did, Codlink, to use the LCD library. Mee-n-Mac seems to have answered this, but I would concur that the LCD library only works with LCD’s using the parallel load LCD’s (the ones with tons of pins ).
So setCursor is no bueno. The other attempted suggestion was to measure the string with a concatenate and then use the set position using the hex code method. That would work with a 16x2 display, but it will NOT work with a 20x4, because for whatever stupid reason, lines 1 and 3 are consecutive, but not lines 2 and four. What I mean is that if you go to a character number past line one, the next character number, 148 I think, is actually line 3 not 2! Crazy.
So why do I want to do a carriage return right now? Ironically, no specific reason other than to be able to do it. You look at examples, and just general testing, and it’s nice to be able to print out an example one line at a time instead of “Hello, WorldHello, World,Hello,World”. That just annoys me.
Any more ideas would certainly be appreciated. Thanks so much!
Firestorm:
The other attempted suggestion was to measure the string with a concatenate and then use the set position using the hex code method. That would work with a 16x2 display, but it will NOT work with a 20x4, because for whatever stupid reason, lines 1 and 3 are consecutive, but not lines 2 and four. What I mean is that if you go to a character number past line one, the next character number, 148 I think, is actually line 3 not 2! Crazy.
I'm not following all of the above but I will say that every cursor position in the LCD has a number. You can set the cursor to go to that position/number. So you can do the same thing as a CR, you just need to track the present cursor position and calculate the cursor position a CR would accomplish. Set the cursor to that number and Bob's your uncle.
If line 1 goes to line 3, so what. It’s a few extra lines of code to map that out.
Yeah, I could make it super complex to capture the length of the string, subtract from 20 then add that many positions to get to the next line, if it is less than 20 characters. If it is more than 20 characters… blah, blah.
But don’t you think that is rather ridiculous? You would think someone would have had to written a simple carriage return. I mean maybe not, but that is pretty crazy if they haven’t, since the basic arduino library has that function, you would think that anyone writing code would have at least minimal function.
And for a 20x4 display:
L1C1 = 128
L2C1 = 192
L3C1 = 148
L4C1 = 212
You could write it and submit it… Over the past 2 years of being on this forum and several others, I have not came across anyone asking about a carriage return for a LCD… So maybe you’re the only one that wants it?
LOL. Fair enough. I suppose that’s the irony. I don’t really need it either. It just seemed like a simple function. (And granted up to this weekend, I didn’t understand how to use serial monitor. It’s still a little fuzzy for SoftwareSerial, but I haven’t played with it since this weekend.
Firestorm:
It just seemed like a simple function.
It would be, at either the receiving end for the PIC firmware to decode, or at the sending end, for a new "SerLCD" library to do. Funny thing is I've never felt a need to use a CR when writing "stuff" to a character LCD. I've always known I had to keep track of where everything is and so I've written strings, like "VoltA = ", to a specific cursor position and subsequently filled in the changing data also by setting the cursor position and then writing the data. And I guess I did this because I knew there were only 2 lines x 18 characters or 4 lines by 20 characters or ...
I never used a character display as some sort of rolling display limited to 2 or 4 lines. That’s a use case where having a CR or new line command would be useful.