I am trying to read a barcode scanner through a rs232 module attached.
When i read the standard EAN13 code in the serial monitor i get it as i want it.
But when i scan the standard EAN13 code to the lcd i get an extra character.
See attachment.
I would like to remove that character after the 4.
Can somebody help me out?
The code is also attached
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
SoftwareSerial mySerial(8, 9); // RX, TX
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
// when characters arrive over the serial port...
if (mySerial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (mySerial.available() > 0) {
// display each character to the LCD
lcd.write(mySerial.read());
}
}
}
Because print() converts the data as readable ASCII text.
But the data that is read from the scanner already is already readable text.
When i use print() i get "5755564850484951555754505213" send to the display and the serial monitor.
But when i use write() i get "9780201379624" send to the serial monitor.
and the display but with that extra character on the display.
probook:
Because print() converts the data as readable ASCII text.
But the data that is read from the scanner already is already readable text.
When i use print() i get "5755564850484951555754505213" send to the display and the serial monitor.
But when i use write() i get "9780201379624" send to the serial monitor.
and the display but with that extra character on the display.
But,
char c = mySerial.read();
lcd.print(c);
would NOT do that, and might resolve the "extra character" problem.
probook:
When i use print() i get "5755564850484951555754505213" send to the display and the serial monitor.
But when i use write() i get "9780201379624" send to the serial monitor.
and the display but with that extra character on the display.
That last 13 is the new line character ('\n'). Read the serial port till you receive '\n', replace it by a nul character and print the complete string that you received. You can look at example 2 in the updated Serial Input Basics thread how it is done; just replace Serial in the example by mySerial.
Alternatively, in your current code check for the '\n' and ignore it.
I have printed the so called characters on my LCD (16x02 I2CLCD) for the codes 0x0D (CR = Carriage Return) and 0x0A (NL = New Line). The characters have appeared as follows. The characters look same having four horizontal bars and two dots.
Fig-1
The last character on the LCD of the OP is something different (only for bars) from the above.
Fig-2
I have printed all the characters on the LCD for the codes : 0x00 - 0xFF; I have not seen any character having four bars.
I have checked the graphics characters chart of the LCD; there is also no 4-bar character.
Fig-3
To erase that particular character from the LCD of the OP, we need to know when that character has arrived which can only be known from its 8-bit (ASCII) code. We can have a counter for tracking the cursor position and once the character is detected, we erase the character from the LCD. Unfortunately, we don't have code for this 4-bar character!
After some research it turns out that the character is indeed a Carriage Return.
Because
"57 55 56 48 50 48 49 51 55 57 54 50 52 13" Are Ascii characters.
57 - 48 = 9
55- 48 = 7
56 - 48 = 8
48 - 48 = 0. Etc.
So i get the code: "9780201379624"
The last one 13 is a Carriage Return according to the Ascii list.
So i guess not every LCD displays the "CR" the same way.
To erase that particular character from the LCD of the OP, we need to know when that character has arrived which can only be known from its 8-bit (ASCII) code. We can have a counter for tracking the cursor position and once the character is detected, we erase the character from the LCD. Unfortunately, we don't have code for this 4-bar character!
So i guess not every LCD displays the "CR" the same way.
Good detective work so far - here's the rest:
Background-
The Arduino createChar() function allows you to create and store up to 8 'custom characters'.
They are stored in the CGRAM (Character Generator Random Access Memory) section of the LCD controller represented by the numbers 1 - 8 in the vertical column at the left of the chart in reply #7.
There are only 8 bytes of memory allotted for this function and they are accessed by what are known as the 'non-printing' ASCII codes 0x00 - 0x07.
Due to a characteristic known as 'memory foldback' they can also be accessed by the 'non-printing' ASCII codes 0x08 - 0x0F.
Keep in mind that there are only eight physical RAM locations but there are two usable addresses for each, not unlike a room with a two doors where both doors access the same space.
Your case-
The and codes that are causing your mystery characters are actually the 'non-printing' ASCII codes 0x0D - 0x0A and are identified as such on good ASCII code charts.
These correspond to the foldback addresses for two of the Arduino 'custom characters'.
Since you have (probably) not used the createChar() function to store anything specific at those addresses you are going to wind up displaying some random character corresponding to the bits that happen to be at those location when the LCD controller fires up.
It looks like many, but not all, LCD controllers are not quite random and happen to have bits corresponding to four horizontal bars at those locations.
So now you do know the ASCII code for those characters whether they are 4-bars or anything else, they are 0x0D and 0x0A !