Printing out on Serial Monitor - Solution

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BlackWhiteFang
 
Posts: 59
Joined: Wed Oct 21, 2020 11:33 am

Printing out on Serial Monitor - Solution

Post by BlackWhiteFang »

This is more of a Posted Solution. I finally discovered why I could not print out to the Serial Monitor from my sketches. The problem was that I selected the wrong data rate in the sketch to "talk" to the Serial Monitor. I was using 9600, which was wrong for my system and Serial Monitor.

I changed the 9600 to 115200 and the Serial Monitor printed out as instructed from my sketch.

See attached sketch:

//###################################################################
//###################################################################
//
// This sketch works on 1-25-22
//
// Comm Port: COM2
//
//###################################################################
//###################################################################

#include <Adafruit_ILI9341.h>

int count = 0;

void setup() {

Serial.begin(115200); // ***** Note this is the Serial Monitor data rate

// Serial.begin(9600); This data rate was incorrect

delay(1000);
}

void loop() {
Serial.print("count = "); Serial.println(count++);
delay(500);
}

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: Printing out on Serial Monitor - Solution

Post by dastels »

Yes, it's a basic fact of serial asynchronous communications: both sides have to be running at the same rate. 9600 and 115200 seem to be the most common for Arduino sketches. Frustratingly there doesn't seem to be a agreed upon standard. I suspect that's because of the older Arduino boards simply not being able to manage the higher rate. That's just a hunch, I haven't looked for a correlation between sketches using 9600 baud and those written in the ATMega328 era.

Dave

User avatar
adafruit_support_bill
 
Posts: 88144
Joined: Sat Feb 07, 2009 10:11 am

Re: Printing out on Serial Monitor - Solution

Post by adafruit_support_bill »

The Atmega328's could easily handle 57600. Most could do 115200 as well, but could get interrupt-bound if there was too much output in a tight loop.

Early versions of the Arduino IDE, the Serial Monitor defaulted to 9600, so most of the sketches from that era were written that way.

User avatar
BlackWhiteFang
 
Posts: 59
Joined: Wed Oct 21, 2020 11:33 am

Re: Printing out on Serial Monitor - Solution

Post by BlackWhiteFang »

dastels wrote:Yes, it's a basic fact of serial asynchronous communications: both sides have to be running at the same rate. 9600 and 115200 seem to be the most common for Arduino sketches. Frustratingly there doesn't seem to be a agreed upon standard. I suspect that's because of the older Arduino boards simply not being able to manage the higher rate. That's just a hunch, I haven't looked for a correlation between sketches using 9600 baud and those written in the ATMega328 era.

Dave

User avatar
BlackWhiteFang
 
Posts: 59
Joined: Wed Oct 21, 2020 11:33 am

Re: Printing out on Serial Monitor - Solution

Post by BlackWhiteFang »

Thank you for the likely reason for this problem. I am a seasoned newbie with enough knowledge to be dangerous as I take on larger sketches.

Best wishes,

BlackWhiteFang

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”