Shop OBEX P1 Docs P2 Docs Learn Events
Not able to get cog_run to run code — Parallax Forums

Not able to get cog_run to run code

JonMJonM Posts: 318
edited 2017-12-23 23:03 in Propeller 1
So, I'm attempting to create a animated display using a Parallax 96x64 OLED Display Module and a FLiP and what I would like is to be able to update the screen from a function that runs in another cog. The code I have which is written in 'C' using SimpleIDE works fine when not running in a separate cog, but when I try to run this same code using 'cog_run' or 'cogstart' the OLED update does not occur. I've added a simple blink LED code fragment in the mix and the LED on the FLiP blinks as expected even when the function is run in a separate cog butt the OLED update does not occur from 'cog_run' or 'cogstart'.

I've tried to increase the stack size and the OLED code still will not run even with a stack set to 4096.

The code and libs I am using as an example came from the following link:
https://parallax.com/downloads/96-x-64-color-oled-display-propeller-c-code

It all works just fine without trying to run in a separate cog so It just baffles me as to why the code to update the OLED does not update.

Any suggestions would be most appreciated.


This is the code I am trying to run in a separate cog.
NOTE: This was borrowed from the 'oled_shapes_examples.c' example.
#include "simpletools.h"                      // Include simple tools
#include "oledc.h"                            // oledc library

                                              // Define communication pins withing init function oledc_init().
#define SID  6                                // Serial data in.
#define SCLK 7                                // Clock
#define CS   8                                // Chip select.
#define RS   9                                
#define RST  10                                
#define SCRN_ROT 2                            // Screen rotation chosse between  0, 1, 2, 3,

unsigned int stack[512];
int *cog;
void snowBalls();

int main()                                    // Main function
{
  int i = 0;

  oledc_init(SID,SCLK,CS,RS,RST,SCRN_ROT);    //Initiate SPI communication.

  oledc_clear(0,0,oledc_getWidth(),oledc_getHeight());//Clear entire screen.

  //cogstart(snowBalls, NULL, stack, sizeof(stack));

  cog = cog_run(snowBalls, 128);  // Does not run oledc code
  
  while(1)
  {
    //snowBalls();    // Runs oledc code fine when running normally
    pause(500);
    print("Cog0 is running\n");  // This gets displayed when running 'cog_run' or 'cogstart'
  }   

  oledc_clear(0,0,oledc_getWidth(),oledc_getHeight());//Clear entire screen.
}

//Draw and fill in in circles. 
//void snowBalls(void *par)
void snowBalls()
{
  #define MAXSBS 6
  
  int aSize = 0;

  int yUpdate[MAXSBS] = {5, 8, 11, 15, 12, 10};
  
  struct sbVal {
    int x0;
    int y0;
    int r;
    int sbColor;
  };
      
    
  struct sbVal sb_vals[MAXSBS] = {
         {5, 5, 2, WHITE},
         {15, 10, 1, WHITE},
         {20, 25, 2, WHITE},
         {75, 15, 1, WHITE},
         {82, 12, 2, WHITE},
         {91, 17, 1, WHITE}
         };

  //print("In Cog1 to pring snowBalls\n");
  while(1)
  {
  
    for(int i = 0; i < MAXSBS; i++)
    {
      oledc_fillCircle(sb_vals[i].x0, sb_vals[i].y0 , sb_vals[i].r, sb_vals[i].sbColor);
    }       

    //print("In Cog1 to print snowBalls\n");
    
    high(26);                                 // LED on
    pause(100); 
    low(26);                                  // LED off
    //pause(100);
 
    pause(500);
    
    for(int i = 0; i < MAXSBS; i++)
    {
      oledc_fillCircle(sb_vals[i].x0, sb_vals[i].y0 , sb_vals[i].r, SKYBLUE);
    }

    for(int i = 0; i < MAXSBS;  i++)
    {
      if(sb_vals[i].y0 > 75)
      {
        sb_vals[i].y0 = 0;
      }else{
        sb_vals[i].y0 += yUpdate[i];
      }        
    }        
  }
}  


Comments

  • You need to init the OLED from inside the cog using it, as only a cog which itself set a pin to an output can control that pin.
  • Wuerfel_21 wrote: »
    You need to init the OLED from inside the cog using it, as only a cog which itself set a pin to an output can control that pin.

    Ah, awesome! I knew I was missing something.

    I moved "oledc_init" to the snowBalls function and it works perfectly now.

    Thanks a bunch!
Sign In or Register to comment.