Debugging via serial

General

ragnarok93

3 weeks ago

Hello, how can I debug via serial port? I want to print on serialport values of variables. Tried doing it like this -


#include <Gamebuino-Meta.h> 

int number; 

void setup () 
{ 
  number = 0; 
  gb.begin (); 
  Serial.begin (9600); 
} 

void loop () 
{ 
  while (! gb.update ()); 
  gb.display.clear (); 

  gb.display.print (number); 
  Serial.println (number); 
  number ++; 
  delay (1000); 
}



But it dont works :(. It just crashes Gamebuino :(. Someone knows how to do this properly ?

jicehel

NEW 3 weeks ago

Just look hee: https://gamebuino.com/fr/community/topic/serial-print-not-working?page=1   ;)  I think it's will help. One thing, don't put a space betwwen function and (. For example, write: Serial.println(number); and not Serial.println (number); For me, your delay(1000); is useless as you are in a loop done 5 times / s.  Use a counter if you want something initaliszed to 0 in setup (compt for example) after you write something like :

void loop () 
{ 
  while (! gb.update ()); 
 compt++
  if(compt>=25) {
      gb.display.clear (); 
     gb.display.print (number); 
     Serial.println (number); 
     number ++;
     compt = 0;
   }
}

ripper121

NEW 3 weeks ago

You need to use "SerialUSB.print" instead of "Serial.print"

ragnarok93

NEW 3 weeks ago

Thanks for help ;). It works with SerialUSB.print :D.

Sorunome

NEW 2 weeks ago

Please note that with SerialUSB the `while(!SerialUSB);` will actually freeze the sketch until you open the serial monitor on the IDE

NoName

NEW 3 days ago

can you somehow use serial when running programs from the SD-card?

edit:  i tried to do so, and i first thought it worked, but then i changed the test program to get some real debug info and found out it just spits out the same stuff it did when running the test program via upload program.  

jicehel

NEW 2 days ago

Did you use "SerialUSB.print" instead of "Serial.print" ?

NoName

2 days ago

yes

NoName

NEW 2 days ago

jicehel jicehel

yes

NoName

NEW 2 days ago

first i wrote something like this:

#include <Gamebuino-Meta.h>

//more stuff

void setup() {
  gb.begin();
  //more stuff
  SerialUSB.begin(9600);
}

void loop() {
  while(!gb.update());
  gb.display.clear();
  SerialUSB.println("yay it works");
  //muuuuuuuch more stuff
}

, uploaded the code and got this:

Then I exported the compiled binary of the same code, copied it to the SD-card, started the program with the Gamenuino plugged into the computer, found the right serial monitor and got the same as above. After that I changed the code:

#include <Gamebuino-Meta.h>

#define DEBUG true   //toggle debug info

//more stuff

void setup() {
  gb.begin();
  //more stuff
  if (DEBUG)
  {
    SerialUSB.begin(9600);
    while (!SerialUSB)
    {
      gb.display.setCursor(0,0);
      gb.display.print("please open seril monitor");
      gb.display.clear();
    }
  }
  SerialUSB.println("-------------Serial successfully started-------------");
}

void loop() {
  while(!gb.update());
  gb.display.clear();
  //muuuuuuuch more stuff
  // \/ inside some func
  if (DEBUG)
  {
    SerialUSB.println([my debug info]);
  }
}

I compiled the code, copied it to the SD-card and got the same Serial output as in the vid above - only when I press the home-menu button the utput stops.

Sorunome

2 days ago

Are you sure you loaded the bin from the sd card? as in, exit to the loader, navigate to the game, and flash it


Sorunome

NEW 2 days ago

NoName NoName

Are you sure you loaded the bin from the sd card? as in, exit to the loader, navigate to the game, and flash it


You must be logged in in order to post a message on the forum

Log in