[Solved]Cant use Serial.print in setup()

Post here first, or if you can't find a relevant section!
Post Reply
feel
Posts: 6
Joined: Wed Jun 16, 2021 10:44 am

[Solved]Cant use Serial.print in setup()

Post by feel »

Hi, i got issues when i try to use Serial.print func in setup(). Here the code i use

Code: Select all

void setup() {
 Serial.begin(115200);
 Serial.print("Hello, World");

}

void loop() {
  

}
I use STM32F411CEU6 Board, thank you!
by fpiSTM » Fri Jul 09, 2021 4:51 pm
Try this as stated before:

Code: Select all

void setup() {
 Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB
  }
 Serial.print("Hello, World");
}

void loop() {
}
And check that Serial is properly enumerated and you select the right COM port.
Go to full post
Last edited by feel on Sat Jul 10, 2021 8:38 am, edited 1 time in total.
User avatar
fpiSTM
Posts: 1757
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Cant use Serial.print in setup()

Post by fpiSTM »

Well with those information what did you expect ?
Which core?
Which target selected? generic? blackpill?...
Is it Hardware Serial or USB CDC ?

If Serial is the USB CDC then you have to wait after the begin.

Code: Select all

While(!Serial){};
https://www.arduino.cc/reference/en/lan ... /ifserial/
feel
Posts: 6
Joined: Wed Jun 16, 2021 10:44 am

Re: Cant use Serial.print in setup()

Post by feel »

i use this settings for my code
settings.png
settings.png (16.93 KiB) Viewed 4255 times
ag123
Posts: 1668
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: Cant use Serial.print in setup()

Post by ag123 »

can you describe your issues?
what is the serial terminal/monitor that you are using?
did you try
Serial.println("hello world") instead?
did you manage to blink the led?

have you reviewed these links?
viewtopic.php?f=2&t=3
viewtopic.php?f=2&t=301
User avatar
fpiSTM
Posts: 1757
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Cant use Serial.print in setup()

Post by fpiSTM »

Try this as stated before:

Code: Select all

void setup() {
 Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB
  }
 Serial.print("Hello, World");
}

void loop() {
}
And check that Serial is properly enumerated and you select the right COM port.
ag123
Posts: 1668
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: Cant use Serial.print in setup()

Post by ag123 »

oh and in linux modemmanager can mess with usb-serial, but describe it more as we've no idea what is wrong.

if you are using linux and you suspect modemmanager could be causing it, check the faq in the wiki
https://github.com/stm32duino/wiki/wiki ... itor-fails
feel
Posts: 6
Joined: Wed Jun 16, 2021 10:44 am

Re: Cant use Serial.print in setup()

Post by feel »

Thanks it worked! i just try to print something in setup() in my project but i found out its not working.
thank you for the support guys
User avatar
fpiSTM
Posts: 1757
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Cant use Serial.print in setup()

Post by fpiSTM »

feel wrote: Sat Jul 10, 2021 6:35 am Thanks it worked! i just try to print something in setup() in my project but i found out its not working.
thank you for the support guys
Fine. The while was the solution?
feel
Posts: 6
Joined: Wed Jun 16, 2021 10:44 am

Re: Cant use Serial.print in setup()

Post by feel »

Yeah the while was the solution, im still new to use this stm32duino so i'd need to learn much things
Post Reply

Return to “General discussion”