1

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.

11
  • There are semi colons missing at the end of the print statement, is that just a typo? – Code Gorilla Aug 29 '16 at 20:43
  • How are you receiving this? It may well be that the keyboard emulation is in fact sending a return or newline, and your receiving program isn't interpreting that in the way that you like. That "." in your received output could be a control character, try to get a hexdump or better yet, look at raw scancodes rather than character interpretations. Also look at the documentation (or failing that sourcecode) and see if the println() method is documented to do anything useful for this class. – Chris Stratton Aug 29 '16 at 20:43
  • @ChrisStratton You can see the periods in the output in my input, and the periods don't have any effect on this bug. If I leave them out, we still get no newline/carriage return. – sscirrus Aug 29 '16 at 21:03
  • @ChrisStratton I've added a link to the println docs in the question. – sscirrus Aug 29 '16 at 21:12
  • Again, state how you are capturing the output – Chris Stratton Aug 29 '16 at 21:16
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.