Reputation: 1621
I am trying desperately to get a Bluetooth dongle working with my Arduino but I can't send it a command that it needs. I can use it when I plug it into my computer via a USB to UART chip and send the command (C
) from PuTTY and then press Enter
.
The Bluetooth dongle's command sheet says that the command I am trying to send it C<cr>
but I can't figure out how to send the proper carriage return character from the Arduino code. I have tried using the Serial.println()
function as well as adding the \r
character to my current Serial.write("C\r")
but neither of those are working.
How can I achieve this?
Upvotes: 15
Views: 110157
Reputation: 915
In standard configuration (on Windows and Linux) if you type "help" and then press enter, the following chain of bytes will appear on the serial port (checked with external connected terminal via RS232, and logic analyzer):
0x68(h) 0x65(e) 0x6c(l) 0x70(p) 0x0d(CR: Carriage Return U+000D)
So it seems like PUTTY puts CR on ENTER (no matter if you are on Linux or Windows).
Upvotes: 1
Reputation: 69
The modified PuTTY is the easiest solution. If you want to stick with the standard PuTTY, there's some other options... You can send a newline using ctrl+j before pressing enter, but that's a faff. To automate it, you can use AutoHotKey to change your {ENTER} to ^J{ENTER} when you've got a PuTTY window active:
#if WinActive("ahk_exe putty.exe")
Enter::
SendInput ^J{Enter}
Return
#if
To do this for just one PuTTY window, you can give AHK the name of the window:
#if WinActive("COM8 - PuTTY")
Enter::
SendInput ^J{Enter}
Return
#if
Upvotes: 3
Reputation: 303
Interestingly, I can report the opposite on Win 7: PuTTY for me and my embedded project is sending ONLY \r
over the COM port. Curious, read: frustratingly unexplainable, but I simply look for either character on the other end of the serial connection.
Then, if you enable "Implicit LF in every CR" under Terminal options it will send both \r\n
. Default behaviour seems to be akin to a Commodore machine :D (http://en.wikipedia.org/wiki/Newline). who knew...
Upvotes: 13
Reputation: 340
Sending CR+LF is possible in modified PuTTY. Source code is available at https://github.com/gniemirowski/putty-crlf and Windows binary at https://www.grzegorz.net/pliki/putty-crlf.zip When you run this version just go to Terminal -> Keyboard and select "CR LF" for "The Enter key" option.
Upvotes: 10
Reputation: 91
PuTTY emulates xterm which emulates vt100. To have putty send CR/LF when pressing enter, type ESC[20h in putty after connecting to the serial device. This sets VT100 LNM true.
http://vt100.net/docs/vt100-ug/chapter3.html
Line feed/new line New line ESC [20h Line feed ESC [20l
Upvotes: 9
Reputation: 1
I tried this very simple code (cr = carriage return)
Serial.write(13);
And because the next "printed" caracters will feed the residual text, it's ok.
Upvotes: -1
Reputation: 6513
On arduino program, just use Serial.write
and both characters codes:
Serial.write(13); // CR
Serial.write(10); // LF
And Avoid Serial.print
as it is intended as human readable, so formatted.
Upvotes: 1
Reputation: 21
If you watch the ascii table or similar reference you might find interesting: \r ou \x0D
For better understanding, see : http://www.grok2.com/sedfaq6.html
Upvotes: 2
Reputation: 965
I'm almost sure that you are looking for the \n
new line character.
Upvotes: -1