On an Arduino Mega 2560:
I have two sketches. The .ino file in each is the same. However, one has a bunch of other .cpp and .h files in the same folder. They both do one simple thing:
Serial.begin(9600);
delay(1000);
Serial.print("DEADBEEF");
The Test sketch (just the .ino file) works fine: DEADBEEF is printed to the Serial console. However, the MinePlusPlus sketch (.ino plus a bunch of .cpp files) prints garbage, like:
⸮⸮xr5⸮VM⸮Rcrrgz``Dl@bF4⸮B⸮⸮bcza``⸮⸮xrb⸮h⸮⸮F⸮LNCH_z⸮⸮y⸮"⸮sW⸮
In case your browser doesn't handle that well, here it is in hex:
e2 b8 ae e2 b8 ae 78 72 35 e2 b8 ae 03 56 4d e2 b8 ae 05 52 63 72 03 72 67 7a 60 60 44 6c 40 62 46 34 e2 b8 ae 13 42 e2 b8 ae e2 b8 ae 01 62 63 7a 61 60 60 e2 b8 ae e2 b8 ae 78 72 62 e2 b8 ae 68 e2 b8 ae e2 b8 ae 46 e2 b8 ae 4c 0f 4e 43 48 5f 7a 05 e2 b8 ae 00 e2 b8 ae 79 e2 b8 ae 00 22 e2 b8 ae 73 57 e2 b8 ae
Some things I've tried:
I have tried two cables, both about 0.6m (2ft) long. My baud rate is set correctly in the Serial console. I have tried both IDEs. I have also tried a terminal Serial viewer (minicom). The problematic sketch takes up about 17kB in flash, which is a very small portion of the Mega's storage.
For reference, here is the full program (almost everything is commented out, but included just in case?):
//VERSION: storage development version
//#include "includes.h"
bool selectedGenerateButton = false;
void setup() {
//iostream.init(9600);
Serial.begin(9600);
delay(1000);
Serial.print("DEADBEEF");
/*cout << prefix << F("\n\nCommunication Channel(s) Initialized") << endl;
uint16_t table [8] {
1100, 1200,
32 , 500 ,
2000, 4095,
501 , 1000
};
storage.printTable();
cout << F("Free space: ") << storage.getFreeSpace() << endl;
world.setTickRate(10);
#ifdef PRESET_SEED
randomSeed(PRESET_SEED);
#endif
#ifndef PRESET_SEED
randomSeed(analogRead(A15));
#endif
cout << prefix << F("Initializing Display") << endl;
GLCD.Init();
cout << prefix << F("\tComplete") << endl;
#ifndef GENERATE_ON_START
screen.renderBitmap(Bitmaps::UI::loadIcon, 16, 2, 31, 23);
screen.renderBitmap(Bitmaps::UI::generateIcon, 16, 2, 79, 23);
screen.renderBitmap(Bitmaps::UI::upArrow, 8, 1, 35, 40);
#endif*/
}
void loop() {
/*if (world.isRunning)
worldLoop();
else {
#ifdef GENERATE_ON_START
GLCD.ClearScreen();
world.isRunning = true;
world.generate(Default);
#endif
if (leftButton.read()) {
selectedGenerateButton = false;
GLCD.ClearScreen();
screen.renderBitmap(Bitmaps::UI::loadIcon, 16, 2, 31, 23);
screen.renderBitmap(Bitmaps::UI::generateIcon, 16, 2, 79, 23);
screen.renderBitmap(Bitmaps::UI::upArrow, 8, 1, 35, 40);
}
if (rightButton.read()) {
selectedGenerateButton = true;
GLCD.ClearScreen();
screen.renderBitmap(Bitmaps::UI::loadIcon, 16, 2, 31, 23);
screen.renderBitmap(Bitmaps::UI::generateIcon, 16, 2, 79, 23);
screen.renderBitmap(Bitmaps::UI::upArrow, 8, 1, 83, 40);
}
if (jumpButton.read()) {
GLCD.ClearScreen();
if (selectedGenerateButton) {
world.isRunning = true;
world.generate(Default);
} else {
world.isRunning = true;
storage.load(0);
}
}
}*/
}
void worldLoop() {
/*#ifdef COMMANDS_ENABLED
if (Command::runCommands())
screen.renderWorld();
#endif
if (world.tryUpdate())
screen.renderWorld();
if (leftButton.read(Normal, PLAYER_SPEED) && !rightButton.read()) {
CoordPair newCoords {player.getCoords(-1)};
if (newCoords.x >= -xLimit) {
player.move(newCoords);
screen.renderWorld();
}
}
if (rightButton.read(Normal, PLAYER_SPEED) && !leftButton.read()) {
CoordPair newCoords {player.getCoords(1)};
if (newCoords.x <= xLimit) {
player.move(newCoords);
screen.renderWorld();
}
}
if (jumpButton.read(Normal, PLAYER_SPEED)) {
CoordPair newCoords {player.getCoords(0, 1)};
if (newCoords.y <= yLimit) {
player.move(newCoords);
screen.renderWorld();
}
}
if (leftMouseButton.read(Normal, PLAYER_SPEED)) {
CoordPair newCoords {player.getCoords(0, -1)};
if (newCoords.y >= 0) {
player.move(newCoords);
screen.renderWorld();
}
}
if (rightMouseButton.read()) {
GLCD.ClearScreen();
storage.save();
exit(0);
}
screen.updateAnimations();*/
}