[SOLVED] Incomprehensible serial monitor outputs after running this code.

Hello! My professor and I are doing research that requires us to make an inexpensive Multi-channel analyzer. A component of the MCA is the Arduino Uno, which we want to turn into an ADC. The Uno, however, is too slow so we turned to an instructable for the Sketch that's supposed to increase the frequency at which the Uno reads analog signals. However, when we try to run the code (with minor changes) the serial monitor outputs data that makes no sense. The original code can be found http://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/, and is titled Girino.7z. Here are the changes we made;

  • When we download the Girino code and turn on debugging (by setting DEBUG=1 in Girino.h), we get the expected output:
# setup()
Girino ready
# ADCCounter: 0
# stopIndex: 65535
# wait: 0
# freeze: 0
101111
0
# ADCCounter: 0
# stopIndex: 65535
# wait: 0
# freeze: 0
101111
0
// repeats
  • However if I add a single print statement in the setup() function, then that print statement is repeatedly executed (strange) and the output is garbled.
void setup ()
{
.....
    Serial.println("Girino ready");
        Serial.println(" X1 We're outside the loop!! XD"); //This is the line we added.
    //printStatus();
}

........

Here is our output;

Girino ready
X# setup()
Girino# setup()
Girino : etup(# setup()
Girino read# setup()
Girino# setup()
...
Girino #######....//pounds forever.

So as you can see the setup is printed repeatedly which should only happen once.

Any help is appreciated. here are my system & software specs: MacBook Pro, 12-inch, Early 2011 Processor 2.3 GHz Intel Core i5 Memory 4 GB 1333 MHz DDR3 Graphics Intel HD Graphics 3000 384 MB

We are using Arduino Uno SMD edition, software version 1.0.5 Software OS X 10.9.3 (13D65)

Thanks!

What is the baud rate in the code and serial monitor?

I was thinking in the same that HazardsMind. So, what de program do if it works normally, without adding anything. What it will do if after it is started you press 't' or 'd' or 'w'?

I downloaded that code some time ago to see how it achieves the high speed. I never tried to run it.

It's pretty complicated - and long. It would probably take someone several hours to figure out an answer to your question unless you are lucky and someone else here has already had to figure it put for himself.

Is there any option to email the author?

...R

However if I add a single print statement in the setup() function

Serial.println(F( "Girino ready"));
        Serial.println(F(" X1 We're outside the loop!! XD"));

etc Is what I'd start with

The nature of the garbled output makes me suspect memory corruption, most likely because you've run out of SRAM. If you build it with a recent version IDE it will tell you how much memory is left for stack and heap data. What does it tell you?

Thank you everyone! The problem has been resolved. PeterH's suggestion to check the SRAM led us to discovering that our multitude of print statements used too much SRAM. We found three methods of finding out the SRAM, all detailed here: http://www.leonardomiliani.com/en/2012/come-sapere-loccupazione-di-ram-del-proprio-sketch/. The fastest way for us was to directly manipulate our Sketch with this code:

int freeRam () {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}
void setup () {
.....
    Serial.println(freeRam()); // This prints the amount of UNUSED SRAM in Kb
}

void loop () {}
The result will be something like:

[memCheck]
84

Found at this site: http://jeelabs.org/2011/05/22/atmega-memory-use/.

To reduce the amount of storage needed by the print statements, we used the function suggestion given by AWOL.

Thank you for all of your help!

Very good, congrats! Can you please change the subject of the first post to "[SOLVED]..."?