I'm using Arduino IDE 2.3.2 and I'm taking lessons for it on Udemy and the sketch that I'm working on is a do_a_calc sketch. I'm using an Arduino Uno, and I can upload to the Arduino Uno with no trouble. When I upload the sketch and open the Serial Monitor it gives the correct answer. However there is a lot of square type characters that appear in the Serial Monitor. I have a screenshot of this but I don't seem to figure out how to upload pics here. I have looked up the problem and the same answer keeps appearing on having the baud rate set right in the IDE and Serial Monitor. Yes the baud is all set to the same number - 9600. I have tried to use a different Uno and had the same problem. I ran two example sketches from the Example menu option (DigitalReadSerial.ino and AnalogReadSerial) and it does the same thing with the squares. It seems to be woking good but a bit annoying. I will be grateful for any help.
Use the Upload icon above the message edit window
![]()
Please post your sketch, using code tags when you do. This prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
int do_a_calc(int number_2); //Prototype
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial)
; //Sets up infinite loop until Serial object is instantiated
Serial.println("Simple Calculation Using Functions");
//int first_number = 5;
int second_number;
second_number = 6;
Serial.println(do_a_calc(second_number));
}
void loop() {
// put your main code here, to run repeatedly:
}
int do_a_calc(int number_2) {
int result = first_number + number_2;
return result;
}
`
That sketch does not even compile
Based on your screen shot, it worked. You just had a bunch of serial 'trash' in the first line, before the "Simple..." line.
Does it appear after every upload?
Oh, yea, fix your code. first_number can't be commented out.
Yes it appears every time I upload. I will try yo figure it out
You can add a delay(2000) in setup before the printing; it might solve the issue. If not, play a little with the delay value.
It's a known issue, issue report here: Spurious output in Serial Monitor after upload · Issue #927 · arduino/arduino-ide · GitHub
And its scope needs to be right too
Problem is, it's good in the screenshot, but in the posted code they omitted the good line, left in the commented-out incorrectly-placed line.
This fixed the problem right away
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
