If I include a button in my Medusa project then my debugserial data becomes garbage

I’m still new to Medusa, but think I might have foundon a small bug that is easy to reproduce:

The code below has a commented out line that reads:

// my_button = new button(3);

While this line is commented as shown, my code runs as expected. But if I uncomment it, the serial data coming out on the Serial.println is just garbage characters.


 #include <Wire.h>
 #include <SPI.h>
 #include <Gadgeteering.h>


 #include <Mainboards/FEZMedusaS12.h>
 #include <Modules/Button.h>

using namespace gadgeteering;
using namespace gadgeteering::mainboards;
using namespace gadgeteering::modules;

button* my_button;

fez_medusa_s12 board;

void setup() {
  Serial.begin(9600);
// my_button = new button(3);
}
 
void loop() {
  Serial.println("Testing123\r\n");
  system::sleep(1000);
}

PS: I should probably add… I do not really have a button module… So there is nothing plugged into socket 3. Maybe that explains the behavior? Maybe its because an interrupt input line is floating and picking up spurious noise?

I ran the code you provided both with and without a button attached and it worked fine in both cases. What board do you have selected under Tools > Board?

Something to keep in mind that was mentioned in the release notes, the S12 and Shield boards use a lot of memory. When the device gets close to using all of it, very strange behavior happens. Usually the board begins executing random instructions due to overwriting existing memory and garbage can be outputted on the serial line. It is usually fairly deterministic, though.

One thing you can try is to switch the board declaration to fez_medusa_mini. The S12 and Shield are strict supersets of the mini, so you can always use the mini in place of them. You will still be running the code on the S12, it will just think it is actually a mini though, so you will lose sockets 5-12.

1 Like

@ John - Thank you very much for your response, John. I think I realize now what my fault was… The code was for an fez_medusa_s12, but I tried to run it on a fez_medusa_mini. After I changed it fez_medusa_mini, the code runs as expected without the garbage characters/