0

I've already written and tested some code using pigpio to drive a Futaba GP9002A VFD. When using the pigpio lib directly, it worked almost absolutely fine, but after migrating to the pigpio daemon (and replacing all pigpio API method calls with their respective counterparts in the pigpiod API, like spiOpen → spi_open etc.), I started encountering random display errors like wrong characters and / or write positions. Here is how I call the pigpiod:

/usr/bin/pigpiod -lt 0

I've already messed around with the baudrate (lowering it to 50k and eventually to 32k) and the pigpiod sample rate, but the symptoms always remained the same. The hardware (electrical wiring) has not been changed BTW.

What can be the cause? A pigpio config error maybe? Do I have to take something special into account when running SPI through pigpiod? Thank you for any useful hints!

UPDATE: Here's the source code. I've added some simple execution time measurement to find out where any timing problems might occur. All you need here is a valid pigpiod and SPI handle:

void vfd::DisplayChar (char pos_x, char pos_y, char size_x, char size_y, string text)
{
  char             buffer [25];
  unsigned int     i    = 0;
  uint32_t         tick = (uint32_t) 0;
  string::iterator iter;

  tick = get_current_tick (vfd::pigpiod_handle);

  gpio_write (vfd::pigpiod_handle, CD_PIN, 1);

  buffer [0] = vfd::Reverse (0x21);                      // Sets the starting point.

  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  spi_write  (vfd::pigpiod_handle, vfd::spi_handle, buffer, 1);
  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  gpio_write (vfd::pigpiod_handle, CD_PIN, 0);

  buffer [0] = vfd::Reverse (pos_x);                     // column
  buffer [1] = vfd::Reverse (0x00);
  buffer [2] = vfd::Reverse (pos_y);                     // row

  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  spi_write  (vfd::pigpiod_handle, vfd::spi_handle, buffer, 3);
  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;

  gpio_write (vfd::pigpiod_handle, CD_PIN, 1);

  buffer [0] = vfd::Reverse (0x22);                      // Sets the character size.

  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  spi_write  (vfd::pigpiod_handle, vfd::spi_handle, buffer, 1);
  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  gpio_write (vfd::pigpiod_handle, CD_PIN, 0);

  buffer [0] = vfd::Reverse (size_x);                    // horizontal scaling factor
  buffer [1] = vfd::Reverse (size_y);                    // vertical scaling factor

  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  spi_write  (vfd::pigpiod_handle, vfd::spi_handle, buffer, 2);
  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;

  gpio_write (vfd::pigpiod_handle, CD_PIN, 1);

  buffer [0] = vfd::Reverse (0x20);                      // Makes the display write some text.

  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  spi_write  (vfd::pigpiod_handle, vfd::spi_handle, buffer, 1);
  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  gpio_write (vfd::pigpiod_handle, CD_PIN, 0);

  for (iter = text.begin (); iter != text.end (); iter++) {
    buffer [i] = vfd::Reverse ((char) *iter);
    i++;
  }

  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  spi_write  (vfd::pigpiod_handle, vfd::spi_handle, buffer, i);
  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;

  gpio_write (vfd::pigpiod_handle, CD_PIN, 1);

  buffer [0] = vfd::Reverse (0x01);                      // Activates display buffer #1.

  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
  spi_write  (vfd::pigpiod_handle, vfd::spi_handle, buffer, 1);
  cout << "¤¤ " << get_current_tick (vfd::pigpiod_handle) - tick << " ¤¤" << endl;
}

These are the measurements (1 tick = 1 µsec):

¤¤ 214 ¤¤
¤¤ 815 ¤¤
¤¤ 1033 ¤¤
¤¤ 2119 ¤¤
¤¤ 2330 ¤¤
¤¤ 2853 ¤¤
¤¤ 3063 ¤¤
¤¤ 3865 ¤¤
¤¤ 4077 ¤¤
¤¤ 4604 ¤¤
¤¤ 4870 ¤¤
¤¤ 9337 ¤¤
¤¤ 10794 ¤¤
¤¤ 11320 ¤¤

UPDATE #2: After switching pigpiod verbosity on and recording its output (see the description stated in this answer), I get this log. Please note that the display uses GPIO #17 to switch between commands and data:

pi@autoradio:~ $ grep -e spi -e gpio pigerr.log 
2018-12-07 23:06:25 gpioNotifyOpenInBand: fd=5
2018-12-07 23:06:25 gpioRead_Bits_0_31: 
2018-12-07 23:06:25 gpioSetMode: gpio=27 mode=1
2018-12-07 23:06:25 gpioSetMode: gpio=25 mode=0
2018-12-07 23:06:25 gpioNotifyBegin: handle=0 bits=02000000
2018-12-07 23:06:25 spiOpen: spiChan=0 baud=50000 spiFlags=0x3
2018-12-07 23:06:25 gpioGetMode: gpio=8
2018-12-07 23:06:25 gpioGetMode: gpio=7
2018-12-07 23:06:25 gpioGetMode: gpio=11
2018-12-07 23:06:25 gpioGetMode: gpio=9
2018-12-07 23:06:25 gpioGetMode: gpio=10
2018-12-07 23:06:25 gpioSetMode: gpio=17 mode=1
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [E0]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [00]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [28]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [08]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [C8]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [48]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [00]
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [60]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [84]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=3 [48 00 68]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [44]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=2 [00 00]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [04]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=15 [72 F6 04 2E 96 B6 A6 04 CE 96 E6 76 86 36 84]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [80]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [84]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=3 [08 00 84]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [44]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=2 [00 00]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [04]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=0
2018-12-07 23:06:29 spiWrite: handle=0 count=16 [CA EE 96 2E C6 16 04 F6 76 04 4E 86 26 96 F6 74]
2018-12-07 23:06:29 gpioWrite: gpio=17 level=1
2018-12-07 23:06:29 spiWrite: handle=0 count=1 [80]
2018-12-07 23:06:30 gpioWrite: gpio=17 level=1
2018-12-07 23:06:30 spiWrite: handle=0 count=1 [00]
2018-12-07 23:06:30 spiWrite: handle=0 count=1 [60]
2018-12-07 23:06:30 gpioWrite: gpio=17 level=0
2018-12-07 23:06:30 gpioWrite: gpio=17 level=1
2018-12-07 23:06:30 spiWrite: handle=0 count=1 [00]
2018-12-07 23:06:30 spiWrite: handle=0 count=1 [60]
2018-12-07 23:06:30 gpioWrite: gpio=17 level=0
2018-12-07 23:06:30 gpioWrite: gpio=17 level=1
2018-12-07 23:06:30 spiWrite: handle=0 count=1 [E0]
2018-12-07 23:06:30 gpioWrite: gpio=17 level=0
2018-12-07 23:06:30 spiWrite: handle=0 count=1 [80]
2018-12-07 23:06:31 gpioWrite: gpio=27 level=0
2018-12-07 23:06:32 gpioWrite: gpio=27 level=0
2018-12-07 23:06:32 spiClose: handle=0
2018-12-07 23:06:32 gpioNotifyClose: handle=0

These readings are always the same, no matter whether the VFD display the text correctly, or not.

2
  • what does this mean? .... it worked almost absolutely fine ................ there may be a bug in your code that has surfaced as a result of the migration
    – jsotola
    Commented Nov 23, 2018 at 21:29
  • Nope, the exceptions to the working-almost-fine apparently had their roots in the receiver or the lib accessing it.
    – Neppomuk
    Commented Nov 23, 2018 at 23:12

2 Answers 2

1

There should be no difference. Both the pigpiod_if2 and pigpio libraries use the same underlying C functions.

The pigpiod_if2 interface will be slower in the sense that the call and return use a socket interface each taking an additional half millisecond or so to run. Could that delay be causing the problem?

1
  • So you mean this could a timing problem in the socket interface, right?
    – Neppomuk
    Commented Dec 1, 2018 at 17:56
1

After several series of testing both with pigpiod, and without, it turned out that the display errors were absolutely erratic! No matter how you change baudrate, an no matter whether with pigpiod, or not: The errors sometimes came and sometimes not. The oscilloscope gave me the answer, though: The input voltage of the display is sometimes unstable (Vcc descreased by some –0.5 V), and then, the errors come. Unfortunately, I haven't made a video of the whole test.

UPDATE: Replacing the DC/DC converter with another (much smaller and slightly cheaper) model eradicated the stability issues almost completely.

So the cause of the trouble was simply an unstable power supply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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