SuperCritical
SuperCritical

Reputation: 1

Confusing Arduino Output with Basic Code

thanks in advance for your answers!

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.

Here is the code uploaded to the Arduino:

#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 >> 8) & 0xff );                                            
  Serial.write( val & 0xff );
}

The Arduino is measuring the voltage at the output of a basic 555 timer. When viewing the serial monitor, this is what I receive:

ÿ ÿ!ÿ!ÿÿ_ÿ]ÿ^ÿ^ÿ^ÿ]ÿ\ÿ\ÿ[ÿ\ÿ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ÿ>ÿ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ÿ=ÿ@ÿ?ÿ>ÿ6ÿ=ÿBÿAÿ@ÿ8ÿ;ÿCÿBÿAÿ<ÿ:ÿ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ÿ<ÿ;ÿ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ÿ>ÿ2ÿ;ÿ:ÿ9ÿ3ÿ2ÿ<ÿ;ÿ;ÿ9ÿ2ÿ8ÿ=ÿ<ÿ;ÿ3ÿ6ÿ>ÿ>ÿ<ÿ7ÿ6ÿ>ÿ?ÿ?ÿ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ÿ=ÿ<ÿ;ÿ5ÿ4ÿ=ÿKÿKÿIÿAÿFÿKÿJÿHÿ@ÿBÿKÿIÿGÿAÿ@ÿGÿGÿGÿEÿ=ÿDÿGÿFÿDÿ<ÿ?ÿGÿEÿDÿ>ÿ<ÿ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ÿ:ÿ<ÿ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ÿ<ÿBÿFÿEÿCÿ;ÿ>ÿFÿDÿBÿ<ÿ;ÿ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ÿ>ÿ@ÿ?ÿ=ÿ5ÿ8ÿ@ÿ>ÿ=ÿ6ÿ'ÿ.ÿ0ÿ0ÿ-ÿ'ÿ.ÿ2ÿ1ÿ0ÿ(ÿ,ÿ4ÿ3ÿ2ÿ,ÿ,ÿ5ÿ4ÿ4ÿ1ÿ+ÿ2ÿ6ÿ5ÿBÿ;ÿ>ÿFÿDÿBÿ<ÿ;ÿCÿCÿBÿ?ÿ9ÿ>ÿBÿAÿ@ÿ7ÿ:ÿCÿ@ÿ?ÿ9ÿ8ÿ?ÿ?ÿ?ÿ;ÿ5ÿ=ÿ?ÿ>ÿ<ÿ4ÿ7ÿ?ÿ=ÿ-ÿ'ÿ'ÿ.ÿ/ÿ/ÿ-ÿ'ÿ.ÿ2ÿ1ÿ0ÿ(ÿ+ÿ4ÿ2ÿ1ÿ+ÿ+ÿ4ÿ4ÿ3ÿ0ÿ+ÿ1ÿCÿCÿAÿ9ÿ<ÿEÿBÿAÿ:ÿ:ÿAÿAÿ@ÿ=ÿ7ÿ=ÿ@ÿ?ÿ>ÿ5ÿ8ÿAÿ>ÿ=ÿ6ÿ6ÿ=ÿ=ÿ=ÿ9ÿ4ÿ;ÿ=ÿ<ÿ:ÿ2ÿ5ÿ/ÿ.ÿ,ÿ&ÿ&ÿ1ÿ/ÿ/ÿ,ÿ'ÿ.ÿ1ÿ0ÿ/ÿ(ÿ+ÿ3ÿ2ÿ1ÿ*ÿ+ÿ4ÿ3ÿ3ÿ0ÿ9ÿ@ÿCÿAÿ@ÿ8ÿ;ÿCÿAÿ?ÿ8ÿ8ÿ@ÿ?ÿ?ÿ;ÿ5ÿ;ÿ?ÿ>ÿ<ÿ4ÿ7ÿ?ÿ=ÿ;ÿ5ÿ5ÿ<ÿ<ÿ;ÿ8ÿ2ÿ:ÿ<ÿ;ÿ*ÿ#ÿ&ÿ/ÿ-ÿ,ÿ&ÿ&ÿ0ÿ.ÿ.ÿ+ÿ&ÿ.ÿ1ÿ0ÿ/ÿ'ÿ+ÿ2ÿ1ÿ0ÿ*ÿ*ÿ3ÿ2ÿAÿ=ÿ8ÿ>ÿAÿ@ÿ>ÿ6ÿ9ÿBÿ?ÿ>ÿ7ÿ7ÿ?ÿ>ÿ=ÿ:ÿ4ÿ:ÿ>ÿ=ÿ;ÿ3ÿ6ÿ>ÿ<ÿ;ÿ4ÿ4ÿ;ÿ;ÿ:ÿ6ÿ1ÿ9ÿ,ÿ+ÿ*ÿ#ÿ&ÿ/ÿ-ÿ,ÿ&ÿ&ÿ0ÿ.ÿ.ÿ+ÿ&ÿ-ÿ1ÿ0ÿ/ÿ'ÿ*ÿ2ÿ1ÿ0ÿ)ÿ*ÿBÿ@ÿ?ÿ<ÿ6ÿ=ÿ@ÿ?ÿ=ÿ5ÿ8ÿ@ÿ>ÿ<ÿ5ÿ5ÿ>ÿ=ÿ<ÿ8ÿ3ÿ9ÿ=ÿ;ÿ9ÿ1ÿ5ÿ<ÿ:ÿ9ÿ2ÿ2ÿ:ÿ9ÿ8ÿ5ÿ!ÿ)ÿ,ÿ+ÿ*ÿ"ÿ&ÿ.ÿ-ÿ,ÿ%ÿ&ÿ0ÿ.ÿ.ÿ+ÿ&ÿ-ÿ0ÿ/ÿ.ÿ'ÿ*ÿ2ÿ1ÿ0ÿ7ÿ8ÿAÿ?ÿ>ÿ:ÿ5ÿ;ÿ?ÿ>ÿ;ÿ4ÿ7ÿ?ÿ<ÿ;ÿ4ÿ4ÿ=ÿ;ÿ:ÿ7ÿ1ÿ:ÿ;ÿ:ÿ8ÿ0ÿ3ÿ;ÿ9ÿ8ÿ1ÿ1ÿ9ÿ8ÿ)ÿ&ÿ!ÿ)ÿ,ÿ+ÿ*ÿ"ÿ&ÿ.ÿ,ÿ,ÿ%ÿ&ÿ0ÿ.ÿ-ÿ*ÿ&ÿ-ÿ0ÿ/ÿ.ÿ'ÿ*ÿ@ÿ?ÿ=ÿ6ÿ6ÿ?ÿ=ÿ=ÿ9ÿ4ÿ:ÿ>ÿ<ÿ:ÿ2ÿ6ÿ=ÿ;ÿ:ÿ2ÿ3ÿ;ÿ:ÿ9ÿ5ÿ0ÿ9ÿ:ÿ8ÿ7ÿ/ÿ2ÿ:ÿ8ÿ6ÿ/ÿ0ÿ)ÿ)ÿ)ÿ%ÿ!ÿ)ÿ+ÿ+ÿ)ÿ"ÿ&ÿ.ÿ,ÿ+ÿ$ÿ%ÿ0ÿ-ÿ-ÿ)ÿ%ÿ,ÿ/ÿ.ÿ-ÿ4ÿ8ÿ?ÿ=ÿ<ÿ4ÿ5ÿ>ÿ<ÿ;ÿ7ÿ2ÿ9ÿ<ÿ;ÿ9ÿ1ÿ5ÿ<ÿ:ÿ8ÿ1ÿ1ÿ:ÿ9ÿ8ÿ4ÿ/ÿ8ÿ9ÿ8ÿ6ÿ.ÿ2ÿ9ÿ6ÿ'ÿ ÿ!ÿ)ÿ)ÿ)ÿ%ÿ!

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.

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!

Upvotes: 0

Views: 571

Answers (1)

Christian Ternus
Christian Ternus

Reputation: 8492

It's probably working fine - your receiving end just isn't interpreting the output correctly. You're receiving a lot of numeric input and printing it as characters.

It might help to know that ÿ is 0xff. Also, if val is low, val & 0xff will almost always be 0xff, or... ÿ. That's why you're getting ÿ-(some character)-ÿ.

Look into the itoa function if you want to convert from integers to strings -- you should do this either on your sending end or your receiving end if you want it to display properly.

Upvotes: 1

Related Questions