piface / libpifacecad

A simple C library for accessing PiFace Control and Display.
GNU General Public License v3.0
10 stars 8 forks source link

Cannot write to second row of LCD screen #2

Open flyn-org opened 10 years ago

flyn-org commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

Explicitly calling pifacecad_lcd_set_cursor does not seem to help.

xpeace commented 10 years ago

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 commented 10 years ago

@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 commented 10 years ago

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

tompreston commented 10 years ago

@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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

Does this fix this bug?

JohnWulff commented 10 years ago

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

barcoboy commented 10 years ago

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 commented 9 years ago

Did the merge above not fix the issue?

barcoboy commented 9 years ago

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 commented 9 years ago

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.