Hi! Is it possible to use 8-bit ASCII characters with the Arduino?
I'm currently interfacing with an old parallel printer that support 8-bit ASCII, but I cant print special norwegian
characters like "æ, Æ, ø, Ø, å, Å.
Ofcource I can for the printer to print just one Character at the time, by sending the ASCII decimal value, but I want the Arduino to convert a sentence like "Dette er en test på norsk!" and send it right out to the printer.
I'm using a shift shift register to feed the printer, and the code looks like this:
void printChar(char* value) {
while (digitalRead(busy) == HIGH) {}
String mystring(value);
for (int i = 0; i < 20; i++) { //i should be larger than upper bound
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, mystring[i]);
digitalWrite(latchPin, HIGH);
digitalWrite(strobe, LOW);
delay(2);
digitalWrite(strobe, HIGH);
delay(5);
}
while (digitalRead(busy) == HIGH) {}
}
Is it possible to use 8-bit ASCII characters with the Arduino?
ASCII is a seven bit code.
In ASCII, codes 128 and above are undefined.
Can the Arduino handle eight bit characters? Yes, of course.
The question you should be asking is - Does the printer support the Norwegian characters, and if so, how are they accessed?
There are chars. There are signed chars. There are unsigned chars. If you look at the range of values that can be stored in each type, you'll see the answer to your question.
Now, making the libraries that you use use the same type variable may be a different story.
That code, by the way is atrocious. Wrapping a string in a String, and then access one character at a time from the String is just pissing resources away. It is a complete waste.
the printer can handle norwegian characters, and if I for example want to print the character Å, I send the decimal value 148, and tell the printer to print. The problem is that I can't figure figure out how to convert a special character to ascii values above 127
The problem is that I can't figure figure out how to convert a special character to ascii values above 127
There are chars. There are signed chars. There are unsigned chars. If you look at the range of values that can be stored in each type, you'll see the answer to your question.
hansibull:
Hi! Is it possible to use 8-bit ASCII characters with the Arduino?
I'm currently interfacing with an old parallel printer that support 8-bit ASCII, but I cant print special norwegian
characters like "æ, Æ, ø, Ø, å, Å.
Ofcource I can for the printer to print just one Character at the time, by sending the ASCII decimal value, but I want the Arduino to convert a sentence like "Dette er en test på norsk!" and send it right out to the printer.
I'm guessing that what you'd like to know is how to have printChar("B[color=red]Å[/color]R") send 66, 148, 82 to the printer -- rather than something like 66, 195, 133, 82, as it probably does at the moment.
The arduino should support 8bit characters in strings just fine, but it's less likely that the arduino editor supports 8bit strings in a compatible way. Modern editors tend to produce "unicode", prefix-based format with prefix characters that lead into multibyte sequences for non-ascii characters, rather than simple 8bit sequences. I'm not sure what the compiler does.
You can do explicit 8bit characters with the backslash escape: char b = "b\148r";
Close, except the three characters following the backslash are three octal digits, and obviously you can't assign a string pointer to a single char.
For 148 decimal, you need char* b = "\224BC";
hansibull:
Hi! Is it possible to use 8-bit ASCII characters with the Arduino?
I'm currently interfacing with an old parallel printer that support 8-bit ASCII, but I cant print special norwegian
characters like "æ, Æ, ø, Ø, å, Å.
Do you want to handle such characters at compile-time or at run-time?
Have you worked out which charset the printer actually uses (likely to be an
ISO-latin-xx or a Microsoft one)? People often use "ASCII" loosely to describe
one of the charsets that includes it but adds more characters, since often these
are adopted solely to add a few currency symbols.
In source files its often safest to stick to pure ASCII, using numerical escapes for 8-bit
char values, so that the code will do the same thing whatever locale the compiler
ran in.
It was supposed to bechar b[] = "b\148r";
I should have remembered that it was octal, though. I grew up with octal.
Note that Java (the Arduino editor is written in Java, probably), which probably means that it saves "unicode" in the source file, rather than "8-bit ascii." (You can consider this confirmed, at least for Mac. Given char x[]= "aåçd";
a look at the .cpp file with a "more primitive" editor shows char x[]= "a\u00e5\u00e7d";
Yes you can send whatever bytes you want through serial.
Serial
write()
Description
Writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function instead.
Syntax
What your printer does with them depends on your printer and how it is set up. I remember in the past having printers that I could load character sets to. Nowadays that may all be PC-generated instead, I dunno.
When you set bytes to send, don't bother with the backslashes. Single quote characters in code make it easy to see that the code is looking for a newline character ('\n') but the harder to read quickly value 10 is just as good and hey that's decimal 10 without translating to binary 1010 or octal 73 or hex 0A, which all work as well.