NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » Redirecting output from terminal to LCD

July 24, 2009
by pedroh96
pedroh96's Avatar

Hey guys! I wrote a code that when I type any message after typing 'screen /dev/cu.PL2303-0000101D 115200 115200', the message appears in my LCD. I'd like to redirect a text file (using cat or something like that) to the LCD. How can I do it?

Oh, my code:

#define F_CPU 14745600

#include <stdio.h>

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/delay.h"
#include "../libnerdkits/lcd.h"
#include "../libnerdkits/uart.h"

int main() {
  // init LCD
  FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);

  // init serial port
  FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  stdin = stdout = &uart_stream;

  uint8_t i;
  char tc[25];
  char message;


  while(1) {
    // Wait for a character to be sent to the serial port.
    tc[i] = uart_read();
    message = tc;
    fprintf_P(&lcd_stream, PSTR("%c"), tc[i]);

  return 0;

Regards, pH

July 24, 2009
by wayward
wayward's Avatar

It's a Mac, right? You can do:


and have fun with things like:

cat file > $LCD

echo Hi from $(hostname) > $LCD

If you need to set the baud rate, character size, parity, stop bits, etc. before this will work, you can do this:

stty -f $LCD 115200 -parity -cstopb    # 115200 baud 8N1
July 25, 2009
by pedroh96
pedroh96's Avatar

:( . I can't get it working. When I use 'cat file > $LCD', many || appears in my screen, and I can't use the last command. How can I use the last command (with echo, for exemple).

Thanks for helping, pH

July 26, 2009
by pedroh96
pedroh96's Avatar

What should I do to get it working? This (echo Hi from $(hostname) > /dev/cu.PL2303-0000101D 115200), works, but in my screen, i'm getting many '|| || ||' instead of characters. What should I do to fix it?

Regards, pH

July 27, 2009
by mcai8sh4
mcai8sh4's Avatar

Hi pedroh96 - I know we discussed this on IRC last night/day (depending on timezone), but since we didn't reach a definate answer, I thought I'd post our findings here to see if anyone else could shed some light on it.

The '||' appear due to the '\n' character (or \n \r) I would think that you could incorporate something in the code to avoid this - however I've tried and failed! There is another post ( that deals with a similar issue - but that uses python to send the data across.

So, since this issue is annoying me (I thought it would have been quite simple), I hope someone else out there might be able to shed some light.

Our basic goal is this :

Using echo "testing" > /dev/ttyUSB0 (or similar) how can you get the text displayed on the LCD.

I would rather not use the printf idea, something along the lines lcd_write_data(uart_read()); <- but that doesn't work.

I'll try and have another play tonight - I'll post my findings.


July 27, 2009
by wayward
wayward's Avatar

A quick and dirty solution would be to tell echo not to send the terminating newline:

echo -n Testing > /dev/ttyUSB?    # -n flag skips the terminating newline

As for ignoring newlines on the receiving end, that shouldn't really be a problem; just skip the entire "command" subset of ASCII:

c = uart_read();
if (c < 0x20) {  // first 32 characters in ASCII are nonprintable and reserved
                 // (although IBM has assigned them visual representations, too)

  ;  // do any extra command-char processing here (clear LCD on newline, etc.)

} else {

Canonical HTH,


August 01, 2009
by pedroh96
pedroh96's Avatar

Can't get it working. I have opened a new thread in Ubuntu Forums:

I think they can help me better.

August 01, 2009
by wayward
wayward's Avatar


echo -n HEY > /dev/cu.PL* 115200

won't do what you're hoping to achieve, since 115200 is seen by echo as just another thing to write to the output device -- not as a specific baud rate parameter. Screen knows it is supposed to "talk" to serial devices, so it has provisions for specifying baud rate and suchlike, but echo is blissfully ignorant in that department.

Did you try setting the communication parameters before writing using echo? What error did you get when you tried

stty -f /dev/cu.PL* 115200 -parity -cstopb

By the way, I assumed you were using a Mac, but since you appear to be on Ubuntu which is a GNU/Linux distribution, the syntax will be a little different:

stty -F /dev/cu.PL* 115200 -parity -cstopb

Do try one of these two, depending on what OS you have, and let us know what the result was. Simply "doesn't work" can't help us help you! Oh, and you may need to prefix the command with sudo, so

sudo stty -F /dev/cu.PL* 115200 -parity -cstopb  # for Ubuntu

before you try echo.


August 03, 2009
by pedroh96
pedroh96's Avatar

Hi Zoran,

Here is what happens:

iMac:write_msg fastshop$ sudo stty -f /dev/cu.PL* 115200 -parity -cstopb; echo -n HEY > /dev/cu.PL*
iMac:write_msg fastshop$

When I type this, I still get the || || || || on the LCD. Here is an image of the LCD when trying sudo stty -f /dev/cu.PL 115200 -parity -cstopb; echo -n HEY > /dev/cu.PL:

NerdKits write_msg project error

Thanks for helping!

September 14, 2009
by wayward
wayward's Avatar

hey pedroh96,

I forgot about this thread :) Any progress here? Did you get it to work?

Post a Reply

Please log in to post a reply.

Did you know that any circuit of voltage sources and resistors can be simplified to a "Thevenin" equivalent circuit? Learn more...