I am recently seeing strange behavior in my Arduino Yun.
Just using the microcontroller, I enter the following:
#include <stdlib.h>
#include <string.h> // For string operations.
#include "Keyboard.h"
#include "Mouse.h"
void setup() {
Keyboard.begin();
Keyboard.println("Hello world.");
Keyboard.print("Hello world.");
}
Rather than getting two lines as expected, I get Hello world.Hello world.
.
It is a very strange error because println (docs) is so 'core' to Keyboard function. I've never had this issue before and I've been playing with it for months. I am running IDE 1.6.11.
A possibly relevant detail
I had this working on my Yun months ago without the #include "Keyboard.h"
and #include "Mouse.h"
. I opened the IDE again just recently and, upon compiling, it failed saying I needed to add those lines. So I did, and it now println
doesn't work.
1 Answer 1
Please test: Keyboard.print("Hello world.\n");
...
That works. println still doesn't.
I'm going to guess here that println is doing something odd in the Yun libraries. I note that the Keyboard.cpp file in my release has this in it:
#define SHIFT 0x80
const uint8_t _asciimap[128] =
{
0x00, // NUL
0x00, // SOH
0x00, // STX
0x00, // ETX
0x00, // EOT
0x00, // ENQ
0x00, // ACK
0x00, // BEL
0x2a, // BS Backspace
0x2b, // TAB Tab
0x28, // LF Enter
0x00, // VT
0x00, // FF
0x00, // CR <---------- note!
Notice that linefeed has a code mapped (0x28) but carriage return (CR) does not (unless you call 0x00 a mapping).
I think you'll find that when you hit Enter on a keyboard it is sending a CR (after all, it used to be labelled the "return" key) and not a LF.
However I thought that the Print class outputted both:
size_t Print::println(void)
{
return write("\r\n");
}
Maybe yours doesn't. I'm not certain which exact println
will be pulled in for a Yun. The fact that it used to work, and now doesn't, suggests a change there somewhere.
println
docs in the question.