Tuesday 26 March 2013

Pinguino CDC debugging


I always got kinda put off by not having sussed out the CDC feature,while others said to work well... And this is here the rWINdows comes with its tantrums... I found out !!
It is better if you turn it off first, restart the board if needed( I'm using the vs X.3 of the IDE ) and VOILA : there it is !!



/*
 Blink a LED
 Increment counter to delay; 
 CDC display debugging
*/

 u16 a=0;
 
void setup()
{              
 // initialize the digital pin 13 as an output.
 pinMode(13, OUTPUT);     
}

void loop(){

    if (a==100)
    {
        a=0;
    }
    a++;
    toggle(13);   // alternate ON and OFF
    delay(a);  // wait for a second
    //CDC.printf( "cntr \"%d\"\r\n", a);
    CDC.printf( "\n\r Dec cntr --- " ); CDC.print( a, DEC   );  
    delay(1);
}



The WIKI also explains how to install the driver for the CDC feature...

 "Prepare the connection to the pinguino device by installing the driver from: HERE 
You will have a COMx connection when you plug the usb cable to the computer.
Step 2: Write the following in the Pinguino IDE
void setup() {
  // put your setup code here, to run once:
 
}
 
void loop() {
  // put your main code here, to run repeatedly: 
  CDC.println("\n\r Hello World!!!");
}
Step 3: Compile and upload the code.
Step 4: Select Menu->Pinguino->Debug Mode->USB CDC And on the bottom section the port x on which the device is connected and there you go:
Hello World!!!"
PS: (22/07/13) Regis, from Pinguino Forum, explained it in a quite concise way,,,:
"... if you want to send strings : 
CDC.write(char c) ; // send one char at a time 
CDC.printf(const char *format, arg1, arg2, ...) ; // send formatted string see http://wiki.pinguino.cc/index.php/CDC.printf and http://wiki.pinguino.cc/index.php/Serial.printf for supported formats description. If you want to get strings : CDC.read(char *buffer); //buffer's length must be 64 bytes long (usb max packet size) return number of chars actually read see http://wiki.pinguino.cc/index.php/CDC.read"

Reference : http://wiki.pinguino.cc/index.php/CDC.print
            PINGUINO COMMUNITY @ Google
            Pinguino WIKI

4 comments:

  1. CDC.printf( "\n\r Dec cntr --- " ); CDC.print( a, DEC );

    or simply :

    CDC.printf( "Dec cntr --- %d\n\r", a);

    ReplyDelete
  2. hello, how are you? fine i hope...
    i triyed to run your samples with pinguino2550 (8bits device) and linux ubuntu, but wont works :(
    i dont know if compiler have some nasty bugs, but i spent some hours and change it to work in my system. how you have shared friendly your code (thanks!), i would like to share my code too. maybe it will help someone.

    here is...
    first example:
    /*
    original at:
    http://dubworks.blogspot.com.br/2013/03/pinguino-cdc-debugging.html
    changed by Ozzy, to run at pinguino2550(8bit device)
    open at linux terminal with:
    minicom -o -D /dev/ttyACM0
    */
    void setup() {
    // put your setup code here, to run once:
    pinMode(10,OUTPUT);
    digitalWrite(10,HIGH);
    }
    void toggle()
    {
    digitalWrite(10,HIGH);
    delay(500);
    digitalWrite(10,LOW);
    delay(20);
    }
    void loop() {
    // put your main code here, to run repeatedly:
    toggle(); //alternate ON and OFF
    CDC.print("\n\r Hello World!!!",17);
    }




    second example:
    /*
    Blink a LED, Increment counter to delay, CDC display debugging
    original at:
    http://dubworks.blogspot.com.br/2013/03/pinguino-cdc-debugging.html
    changed by Ozzy, to run at pinguino2550(8bit device)
    open at linux terminal with:
    minicom -o -D /dev/ttyACM0
    */
    u8 a=0,cent=0,dez=0,uni=0;
    int number;
    char chaine[5]={'T','E','S','T',0};
    //ascii values
    char ze[10]={'0','1','2','3','4','5','6','7','8','9'};
    void setup()
    {
    pinMode(10, OUTPUT); //initialize the digital pin 10 as an output.
    delay(5000);
    }
    void reset_counter()
    {
    a=0;
    CDC.print("\n\r",2);
    delay(5);
    CDC.print("Ozzy Says:\r\n",12);
    delay(5);
    CDC.print("Again!\r\n",8);
    delay(5);
    CDC.print("\n\r",2);
    delay(5);
    }
    void toggle()
    {
    digitalWrite(10,HIGH);
    delay(500);
    digitalWrite(10,LOW);
    delay(20);
    }
    void teste()
    {
    cent=(a/100);
    dez=((a%100)/10);
    uni=((a%100)%10);
    chaine[4]=ze[uni];
    chaine[3]=ze[dez];
    chaine[2]=ze[cent];
    chaine[1]=0;
    chaine[0]=0;
    CDC.print(chaine,5);
    delay(5);
    CDC.print("\n\r",2);
    delay(5);
    }
    void loop(){
    if (a==12)
    {
    reset_counter();//reset counter
    }
    a++; //update counter
    toggle(); //alternate ON and OFF
    teste(); //print actual value of the counter
    delay(1);
    }

    ReplyDelete
  3. wow, i forgot! :D
    at the linux minicom terminal, the result was something like this:

    001
    002
    003
    004
    005
    006
    007
    008
    009
    010
    011
    012

    Ozzy Says:
    Again!

    001
    002

    ReplyDelete

Feel free to contact me with any suggestions, doubts or requests.

Bless