title: Confusing Arduino Output with Basic Code
body: <p>thanks in advance for your answers!</p>
  
  <p>I am attempting to build a Poor Man's Oscilloscope using an Arduino Mega 2560. Assuming I have wired everything correctly, I need some help understanding the code involved and the output.</p>
  
  <p>Here is the code uploaded to the Arduino:</p>
  
  <pre><code>#define ANALOG_IN 0
  
  void setup() {
    Serial.begin(9600); 
    //Serial.begin(115200); 
  }
  
  void loop() {
    int val = analogRead(ANALOG_IN);                                              
    Serial.write( 0xff );                                                         
    Serial.write( (val &gt;&gt; 8) &amp; 0xff );                                            
    Serial.write( val &amp; 0xff );
  }
  </code></pre>
  
  <p>The Arduino is measuring the voltage at the output of a basic 555 timer. When viewing the serial monitor, this is what I receive:</p>
  
  <pre><code>ÿ ÿ!ÿ!ÿÿ_ÿ]ÿ^ÿ^ÿ^ÿ]ÿ\ÿ\ÿ[ÿ\ÿZÿZÿYÿYÿYÿYÿZÿZÿZÿZÿYÿXÿYÿSÿPÿXÿXÿWÿUÿMÿRÿXÿWÿUÿMÿOÿWÿWÿUÿ_ÿ\ÿdÿeÿcÿaÿYÿ]ÿcÿbÿ_ÿXÿYÿbÿ`ÿ^ÿXÿVÿ]ÿ_ÿ]ÿ[ÿSÿYÿ^ÿ\ÿZÿRÿSÿ\ÿZÿYÿSÿPÿWÿYÿXÿGÿ@ÿFÿKÿJÿIÿAÿCÿLÿKÿJÿEÿBÿLÿLÿLÿJÿBÿHÿNÿLÿKÿCÿEÿNÿ\ÿZÿUÿRÿZÿZÿYÿXÿOÿTÿYÿXÿVÿNÿPÿYÿWÿUÿOÿMÿTÿUÿTÿRÿJÿQÿTÿSÿQÿIÿKÿTÿRÿQÿKÿIÿ@ÿCÿCÿAÿ9ÿ@ÿEÿDÿCÿ;ÿ=ÿGÿEÿDÿ?ÿ=ÿFÿFÿFÿDÿ=ÿCÿHÿGÿFÿ&gt;ÿOÿWÿVÿTÿOÿLÿTÿUÿTÿRÿJÿOÿTÿSÿQÿIÿKÿTÿRÿPÿKÿHÿOÿQÿPÿNÿFÿLÿPÿOÿMÿEÿGÿPÿNÿMÿ8ÿ6ÿ=ÿ@ÿ?ÿ&gt;ÿ6ÿ=ÿBÿAÿ@ÿ8ÿ;ÿCÿBÿAÿ&lt;ÿ:ÿCÿDÿCÿAÿ:ÿ@ÿEÿDÿQÿIÿKÿTÿRÿQÿKÿHÿPÿQÿPÿNÿFÿKÿPÿOÿMÿEÿGÿPÿNÿMÿGÿEÿKÿMÿLÿJÿBÿIÿMÿKÿIÿAÿDÿLÿ&lt;ÿ;ÿ5ÿ4ÿ;ÿ=ÿ=ÿ;ÿ4ÿ:ÿ?ÿ?ÿ=ÿ5ÿ8ÿAÿ@ÿ?ÿ9ÿ8ÿ@ÿAÿAÿ?ÿ7ÿKÿQÿPÿNÿFÿHÿQÿOÿMÿGÿEÿMÿNÿMÿJÿCÿHÿMÿLÿJÿBÿDÿMÿKÿIÿCÿAÿHÿJÿIÿGÿ?ÿFÿJÿHÿFÿ&gt;ÿ2ÿ;ÿ:ÿ9ÿ3ÿ2ÿ&lt;ÿ;ÿ;ÿ9ÿ2ÿ8ÿ=ÿ&lt;ÿ;ÿ3ÿ6ÿ&gt;ÿ&gt;ÿ&lt;ÿ7ÿ6ÿ&gt;ÿ?ÿ?ÿKÿDÿIÿNÿMÿKÿCÿEÿNÿKÿJÿDÿCÿJÿJÿJÿGÿ@ÿGÿJÿIÿGÿ?ÿAÿJÿHÿFÿ@ÿ?ÿFÿGÿFÿDÿ=ÿCÿFÿEÿ6ÿ-ÿ0ÿ9ÿ8ÿ7ÿ2ÿ1ÿ:ÿ9ÿ9ÿ7ÿ1ÿ6ÿ;ÿ;ÿ9ÿ2ÿ4ÿ=ÿ&lt;ÿ;ÿ5ÿ4ÿ=ÿKÿKÿIÿAÿFÿKÿJÿHÿ@ÿBÿKÿIÿGÿAÿ@ÿGÿGÿGÿEÿ=ÿDÿGÿFÿDÿ&lt;ÿ?ÿGÿEÿDÿ&gt;ÿ&lt;ÿCÿEÿCÿAÿ:ÿ1ÿ5ÿ5ÿ3ÿ,ÿ/ÿ7ÿ7ÿ5ÿ0ÿ/ÿ8ÿ8ÿ7ÿ5ÿ/ÿ5ÿ:ÿ9ÿ8ÿ0ÿ3ÿ;ÿ:ÿ9ÿ3ÿAÿIÿIÿHÿFÿ?ÿDÿHÿGÿFÿ=ÿ@ÿIÿGÿEÿ?ÿ=ÿEÿEÿEÿBÿ;ÿBÿDÿDÿBÿ:ÿ&lt;ÿDÿCÿBÿ;ÿ:ÿAÿBÿAÿ0ÿ)ÿ0ÿ4ÿ4ÿ3ÿ+ÿ.ÿ6ÿ5ÿ4ÿ.ÿ.ÿ7ÿ6ÿ6ÿ4ÿ.ÿ4ÿ8ÿ8ÿ6ÿ.ÿ1ÿ:ÿ9ÿFÿ@ÿ?ÿGÿGÿFÿCÿ&lt;ÿBÿFÿEÿCÿ;ÿ&gt;ÿFÿDÿBÿ&lt;ÿ;ÿCÿCÿBÿ?ÿ9ÿ@ÿBÿAÿ@ÿ7ÿ:ÿBÿAÿ?ÿ9ÿ8ÿ?ÿ0ÿ1ÿ.ÿ(ÿ/ÿ3ÿ3ÿ1ÿ*ÿ,ÿ5ÿ4ÿ3ÿ-ÿ-ÿ6ÿ5ÿ5ÿ2ÿ,ÿ3ÿ7ÿ6ÿ5ÿ-ÿ0ÿGÿEÿDÿ=ÿ=ÿDÿDÿCÿ@ÿ:ÿ?ÿDÿBÿAÿ9ÿ;ÿDÿAÿ@ÿ:ÿ9ÿ@ÿ@ÿ@ÿ=ÿ7ÿ&gt;ÿ@ÿ?ÿ=ÿ5ÿ8ÿ@ÿ&gt;ÿ=ÿ6ÿ'ÿ.ÿ0ÿ0ÿ-ÿ'ÿ.ÿ2ÿ1ÿ0ÿ(ÿ,ÿ4ÿ3ÿ2ÿ,ÿ,ÿ5ÿ4ÿ4ÿ1ÿ+ÿ2ÿ6ÿ5ÿBÿ;ÿ&gt;ÿFÿDÿBÿ&lt;ÿ;ÿCÿCÿBÿ?ÿ9ÿ&gt;ÿBÿAÿ@ÿ7ÿ:ÿCÿ@ÿ?ÿ9ÿ8ÿ?ÿ?ÿ?ÿ;ÿ5ÿ=ÿ?ÿ&gt;ÿ&lt;ÿ4ÿ7ÿ?ÿ=ÿ-ÿ'ÿ'ÿ.ÿ/ÿ/ÿ-ÿ'ÿ.ÿ2ÿ1ÿ0ÿ(ÿ+ÿ4ÿ2ÿ1ÿ+ÿ+ÿ4ÿ4ÿ3ÿ0ÿ+ÿ1ÿCÿCÿAÿ9ÿ&lt;ÿEÿBÿAÿ:ÿ:ÿAÿAÿ@ÿ=ÿ7ÿ=ÿ@ÿ?ÿ&gt;ÿ5ÿ8ÿAÿ&gt;ÿ=ÿ6ÿ6ÿ=ÿ=ÿ=ÿ9ÿ4ÿ;ÿ=ÿ&lt;ÿ:ÿ2ÿ5ÿ/ÿ.ÿ,ÿ&amp;ÿ&amp;ÿ1ÿ/ÿ/ÿ,ÿ'ÿ.ÿ1ÿ0ÿ/ÿ(ÿ+ÿ3ÿ2ÿ1ÿ*ÿ+ÿ4ÿ3ÿ3ÿ0ÿ9ÿ@ÿCÿAÿ@ÿ8ÿ;ÿCÿAÿ?ÿ8ÿ8ÿ@ÿ?ÿ?ÿ;ÿ5ÿ;ÿ?ÿ&gt;ÿ&lt;ÿ4ÿ7ÿ?ÿ=ÿ;ÿ5ÿ5ÿ&lt;ÿ&lt;ÿ;ÿ8ÿ2ÿ:ÿ&lt;ÿ;ÿ*ÿ#ÿ&amp;ÿ/ÿ-ÿ,ÿ&amp;ÿ&amp;ÿ0ÿ.ÿ.ÿ+ÿ&amp;ÿ.ÿ1ÿ0ÿ/ÿ'ÿ+ÿ2ÿ1ÿ0ÿ*ÿ*ÿ3ÿ2ÿAÿ=ÿ8ÿ&gt;ÿAÿ@ÿ&gt;ÿ6ÿ9ÿBÿ?ÿ&gt;ÿ7ÿ7ÿ?ÿ&gt;ÿ=ÿ:ÿ4ÿ:ÿ&gt;ÿ=ÿ;ÿ3ÿ6ÿ&gt;ÿ&lt;ÿ;ÿ4ÿ4ÿ;ÿ;ÿ:ÿ6ÿ1ÿ9ÿ,ÿ+ÿ*ÿ#ÿ&amp;ÿ/ÿ-ÿ,ÿ&amp;ÿ&amp;ÿ0ÿ.ÿ.ÿ+ÿ&amp;ÿ-ÿ1ÿ0ÿ/ÿ'ÿ*ÿ2ÿ1ÿ0ÿ)ÿ*ÿBÿ@ÿ?ÿ&lt;ÿ6ÿ=ÿ@ÿ?ÿ=ÿ5ÿ8ÿ@ÿ&gt;ÿ&lt;ÿ5ÿ5ÿ&gt;ÿ=ÿ&lt;ÿ8ÿ3ÿ9ÿ=ÿ;ÿ9ÿ1ÿ5ÿ&lt;ÿ:ÿ9ÿ2ÿ2ÿ:ÿ9ÿ8ÿ5ÿ!ÿ)ÿ,ÿ+ÿ*ÿ"ÿ&amp;ÿ.ÿ-ÿ,ÿ%ÿ&amp;ÿ0ÿ.ÿ.ÿ+ÿ&amp;ÿ-ÿ0ÿ/ÿ.ÿ'ÿ*ÿ2ÿ1ÿ0ÿ7ÿ8ÿAÿ?ÿ&gt;ÿ:ÿ5ÿ;ÿ?ÿ&gt;ÿ;ÿ4ÿ7ÿ?ÿ&lt;ÿ;ÿ4ÿ4ÿ=ÿ;ÿ:ÿ7ÿ1ÿ:ÿ;ÿ:ÿ8ÿ0ÿ3ÿ;ÿ9ÿ8ÿ1ÿ1ÿ9ÿ8ÿ)ÿ&amp;ÿ!ÿ)ÿ,ÿ+ÿ*ÿ"ÿ&amp;ÿ.ÿ,ÿ,ÿ%ÿ&amp;ÿ0ÿ.ÿ-ÿ*ÿ&amp;ÿ-ÿ0ÿ/ÿ.ÿ'ÿ*ÿ@ÿ?ÿ=ÿ6ÿ6ÿ?ÿ=ÿ=ÿ9ÿ4ÿ:ÿ&gt;ÿ&lt;ÿ:ÿ2ÿ6ÿ=ÿ;ÿ:ÿ2ÿ3ÿ;ÿ:ÿ9ÿ5ÿ0ÿ9ÿ:ÿ8ÿ7ÿ/ÿ2ÿ:ÿ8ÿ6ÿ/ÿ0ÿ)ÿ)ÿ)ÿ%ÿ!ÿ)ÿ+ÿ+ÿ)ÿ"ÿ&amp;ÿ.ÿ,ÿ+ÿ$ÿ%ÿ0ÿ-ÿ-ÿ)ÿ%ÿ,ÿ/ÿ.ÿ-ÿ4ÿ8ÿ?ÿ=ÿ&lt;ÿ4ÿ5ÿ&gt;ÿ&lt;ÿ;ÿ7ÿ2ÿ9ÿ&lt;ÿ;ÿ9ÿ1ÿ5ÿ&lt;ÿ:ÿ8ÿ1ÿ1ÿ:ÿ9ÿ8ÿ4ÿ/ÿ8ÿ9ÿ8ÿ6ÿ.ÿ2ÿ9ÿ6ÿ'ÿ ÿ!ÿ)ÿ)ÿ)ÿ%ÿ!
  </code></pre>
  
  <p>I have double checked all my baud rates are at 9600, and that the analog pin works. I wrote a more basic script to read off the analog input, and they output correctly to the serial monitor.</p>
  
  <p>Because I didn't write this code, and I'm not very familiar with C, I was hoping I could get some feedback on what might be wrong. Thanks!</p>