Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot write to second row of LCD screen #2

Open
flyn-org opened this issue Dec 13, 2013 · 14 comments
Open

Cannot write to second row of LCD screen #2

flyn-org opened this issue Dec 13, 2013 · 14 comments

Comments

@flyn-org
Copy link

The following code

int main(void)
{
pifacecad_open();
pifacecad_lcd_backlight_on();
pifacecad_lcd_write("Hello,\nWorld!");
pifacecad_close();
}

displays

Hello,

instead of

Hello,
world!

That is, I cannot get anything to appear on the second row of my LCD.

When I run libpiface's test.c, I only see:

    Screw you guys

but not the following line.

Oddly, running the hangman Python demo works (i.e., makes use of both rows), but C seems not to.

@tompreston
Copy link
Member

What about:

int main(void)
{
    pifacecad_open();
    pifacecad_lcd_backlight_on();
    pifacecad_lcd_write("Hello");
    pifacecad_lcd_set_cursor(0, 1);
    pifacecad_lcd_write("World!");
    pifacecad_close();
}

I'm not suggesting this as a solution, just identifying where the problem is (pifacecad_lcd_write calls pifacecad_lcd_set_cursor).

@flyn-org
Copy link
Author

Explicitly calling pifacecad_lcd_set_cursor does not seem to help.

@xpeace
Copy link

xpeace commented Jan 28, 2014

I just tried to write to the second line using the pifacecad command line util
I had no success here as well ...

sudo /home/pi/pifacecad open blinkoff
sudo /home/pi/pifacecad write "XXX-Controller\nLoading..."
sudo /home/pi/pifacecad backlight on

anyone has had success writing to the second line using the pifacecad util ?
How do I insert a linefeed character (\n) in there ?

@tompreston
Copy link
Member

@MikePetullo Have you tried the dev_tp branch?
@xpeace I've had success with actually typing a new line.

$ ./pifacecad write "hello
> there"

I'm not sure why \n isn't working. Perhaps it's being passed in as two separate characters? Hm, it's being drawn as ¥ for me.

@xpeace
Copy link

xpeace commented Jan 29, 2014

I`ve also seen the ¥ glad this is consistent :-) thanks for checking

@tompreston
Copy link
Member

@xpeace ¥ is the same index as the backslash character. I bet that has something to do with it.

$ python3
>>> chr(0x5d)
'\\'

http://symlink.dk/electro/hd44780/lcd-font.png

@flyn-org
Copy link
Author

Using dev_tp, the code in my initial comment now works. Running:

./pifacecad write "012345678901234
foo"

works too. Running:

./pifacecad write "0123456789012345
foo"

(one more digit on the first line) does not work. It seems that the '5' being printed in the final character cell causes the '\n' to be ignored. (Note that in the previous example, ending in '4', there is a blank cell remaining in the first line.) I also observed that in the latter case, pifacecad does not terminate---it just hangs after printing the first line.

@xpeace
Copy link

xpeace commented Jan 30, 2014

I also had problems when setcursor and other send_command functions are called (especially when using all 16 digits): try this on the dev_tp branch:

// edit in pifacecad.c comment out busy check
void pifacecad_lcd_send_command(uint8_t command)
{
//while(is_busy()); // wait until not busy
sleep_ns(DELAY_SETTLE_NS); // for testing only
pifacecad_lcd_set_rs(0);
pifacecad_lcd_send_byte(command);
sleep_ns(DELAY_SETTLE_NS);
}

@tompreston
Copy link
Member

Does this fix this bug?

@JohnWulff
Copy link
Contributor

I will check this in the next couple of days and report by replacing this temporary comment

@barcoboy
Copy link

I am having the same issue. Trying to use the pifacecad command in BASH shell scripts, and I can only write to the first line. The "cursor" command does move the cursor around the display, but it seems the write command always starts writing text in the home position.

As a workaround, I've added this little code snippet to the middle of pifacecad-cmd.c and recompiled:

} else if (strcmp(arguments.cmd, "write2") == 0) {
    pifacecad_lcd_set_cursor(0, 1);
    pifacecad_lcd_write(arguments.cmdargs[0]);

@tompreston
Copy link
Member

Did the merge above not fix the issue?

@barcoboy
Copy link

Hi Tom. After getting everything working in Raspian and OpenELEC, I found this that was still outstanding. It appears the problem is in pifacecad-cmd.c, as compiling your code from Dec 13, 2013 works fine, as does the test.c script, but running the following bash commands do not work correctly:

./pifacecad open
./pifacecad backlight on
./pifacecad write "Hello World"
./pifacecad setcursor 5 1
./pifacecad write "Goodbye"

After running the setcursor command, I see the cursor has jumped to the 5th column of the 2nd row, but the next write command starts back at the home position and overwrites part of the "Hello World".

@barcoboy
Copy link

I finally got this to work with the pifacecad executable example.

In src/pifacecad.c, I commented out line 129:

// pifacecad_lcd_send_command(LCD_SETDDRAMADDR | cur_address);

Now after a setcursor command, the next write statement does not start at the home position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants