Peggy 2 Code help

Home Evil Mad Scientist Forums LED Matrix Kits Peggy 2 Code help

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #20383
    rcj10
    Participant

    I am working on a project to display server data to a Peggy 2.1 I have. I have python code on the servers collecting data and telnetting to a cc3000 shield running on a Uno that then will eventually I2C the values to the display. I am getting stuck on the display. This is at generating changing char strings to update the display. Right now to simplify things they are static and I am just jumping from one to another. it will run for five minutes then crash. If I reduce the update time it will crash in less time. This tells me I have some sort of overrun error after so many updated frames. Any advise would be gladly be accepted. Thanks,

    rick
    /* Simple example code for Peggy 2.0, using the Peggy2 and PeggyWriter libraries
    */

    #include <Peggy2.h>
    #include <PeggyWriter.h>

    Peggy2 frame1;         // Make a frame buffer object, called frame1
    PeggyWriter myWriter1;  // Make a PeggyWriter object
    PeggyWriter myWriter2;  // Make a PeggyWriter object
    PeggyWriter myWriter3;  // Make a PeggyWriter object
    PeggyScroller comp1;   // Make a PeggyScroller object
    PeggyScroller comp2;
    PeggyScroller comp3;
    char scrollerSelect = 1;
    char* data1 = ” TEST 1 “;
    char* data2 = ”   TEST 2 “;
    char* data3 = ”      TEST 3 “;
    int j = 0;
    char mF1;
    char mF2;
    char mF3;
    int k = 0;
    int l = 0;
    String s1, s2, s3;

    void setup()
    {
      frame1.HardwareInit();
      comp2.init(&frame1, &myWriter1, 7, data2);
      comp3.init(&frame1, &myWriter2, 14, data3);
      comp1.init(&frame1, &myWriter3, 1, data1); 


    void loop()
      long delayCount = 0;

      mF1 = comp1.scrollLeft();
      mF2 = comp2.scrollLeft();
      mF3 = comp3.scrollLeft();

      // Refresh Peggy lots of times while we kill time.

      // switch messages if one has completed. 
      if (mF1 == 0){
        data1 = ”  COMP 1 ? “;
        comp1.init(&frame1, &myWriter1, 1, data1);
      }
      if (mF2 == 0){
        data2 = ” COMP 2 ? “;
        comp2.init(&frame1, &myWriter2, 7, data2);
      }
      if (mF3 == 0){
        data3 = ” COMP 3 ? “;
        comp3.init(&frame1, &myWriter3, 14, data3);
      }
      while (delayCount < 150)
      {
        frame1.RefreshAll(1);
        delayMicroseconds(50);
        delayCount++;
      }
      delayCount = 0;
    }
    • This topic was modified 2 years, 4 months ago by Windell Oskay.
    #21945
    Windell Oskay
    Keymaster

    Can you please say exactly what is is that is “crashing” and by what mechanism? I wouldn’t expect either an Uno or a Peggy 2 to be able to “crash,” so I’m a bit confused.

    Separately, the “PeggyWriter” is a useful example, but it *is* a user-contributed example that we do not have much experience using.  In a quick look, it appears that the example codes for PeggyWriter use a single instance of PeggyWriter, but multiple instances of PeggyScroller. You might consider trying that approach, to see if it works better.
    #21946
    rcj10
    Participant

    Sorry for not getting back to you quicker. I was having password issues. 

    The display will stop scrolling. The display will drop the frame rate to half or more. 
    I am guessing the ram is filling up? 
    #21947
    rcj10
    Participant

    When trying the one Writer approach it seems to last longer:

    /* Simple example code for Peggy 2.0, using the Peggy2 and PeggyWriter libraries
    */

    #include <Peggy2.h>
    #include <PeggyWriter.h>

    Peggy2 frame1;         // Make a frame buffer object, called frame1
    PeggyWriter myWriter1;  // Make a PeggyWriter object
    PeggyScroller comp1;   // Make a PeggyScroller object
    PeggyScroller comp2;
    PeggyScroller comp3;
    char scrollerSelect = 1;
    char* data1= ” TEST 1 “;
    char* data2 = ”   TEST 2 “;
    char* data3 = ”      TEST 3 “;
    int delayCount = 0;
    int j = 0;
    char mF1;
    char mF2;
    int n = 0;
    char mF3;
    int a=1;     //declaring integer
    char b[2];   //declaring character array
    String str;  //declaring string
    //int k = 0;
    //int l = 0;
    //String s1, s2, s3;

    void setup()
    {
      frame1.HardwareInit();
      comp2.init(&frame1, &myWriter1, 7, data2);
      comp3.init(&frame1, &myWriter1, 14, data3);
      comp1.init(&frame1, &myWriter1, 1, data1); 


    void loop()
      long delayCount = 0;

      mF1 = comp1.scrollLeft();
      mF2 = comp2.scrollLeft();
      mF3 = comp3.scrollLeft();

      // Refresh Peggy lots of times while we kill time.

      // switch messages if one has completed. 
      if (mF1 == 0){
        n=n+1;
        //str=String(n); //converting integer into a string
        //str.toCharArray(data1,1); //passing the value of the string to the character array
        data1 = ” Comp 1 ? “;
        comp1.init(&frame1, &myWriter1, 1, data1);
      }
      if (mF2 == 0){
        data2 = ” COMP 2 ? “;
        comp2.init(&frame1, &myWriter1, 7, data2);
      }
      if (mF3 == 0){
        data3 = ” COMP 3 ? “;
        comp3.init(&frame1, &myWriter1, 14, data3);
      }
      while (delayCount < 50)
      {
        frame1.RefreshAll(1);
        delayMicroseconds(10);
        delayCount++;
      }
      delayCount = 0;
      
    }
    #21948
    Windell Oskay
    Keymaster

    It looks like using the “init” command multiple times may be the issue.  It allocates new memory each time that it is called, with malloc.  

    That shouldn’t be an issue (and isn’t unless called in a loop!), but there doesn’t appear to be any process for freeing up the memory that is allocated.  You might be able to add a command to free up the memory: http://www.gnu.org/software/libc/manual/html_node/Freeing-after-Malloc.html
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.