Serial.println() was not printing on serial monitor

sorry i forgot to inform forum that before i use ttl serial, i try to upload hid bootloader but not working, so i use ttl serial then i face this issue. ttl serial uploader success upload. is hid bootloader uploaded still there

Are you still getting serial data from later in the code, and only missing the prints in setup? If so, try a delay of 5000 immediately after Serial.begin, that will be way longer than needed, but at least let you know if it is needed. If it works, you can try smaller values to see just how long is needed.

Received: BA45FF00
Recognized as power
loop()
Received: 0
Kode Not Recognized
loop()
Received: B946FF00
Recognized as mode
loop()
Received: 0
Kode Not Recognized
loop()
Received: BC43FF00
Recognized as forward
loop()
Received: 0
Kode Not Recognized
loop()
Received: F30CFF00
Recognized as one
loop()
Received: 0
Kode Not Recognized
loop()
Received: E718FF00
Recognized as two
loop()
Received: 0
Kode Not Recognized
loop()
Received: A15EFF00
Recognized as three
loop()

  Serial.begin(115200);
  delay(5000);
  Serial.println("setup");
  Serial.println("TEST SERIAL MONITOR");
  
  IrReceiver.begin(IRpin);
  IrReceiver.enableIRIn();

STILL BLANK FOR SERIAL.PRINTLN();

in loop()

void loop()
{
  Serial.println("loop()");

  // put your main code here, to run repeatedly:
  while (IrReceiver.decode() == 0);
  unsigned long value = (IrReceiver.decodedIRData.decodedRawData);
  Serial.print("Received: ");
  **Serial.println(value, HEX);**
  IrReceiver.resume();

  kodeKu = GetKodeKu(value);

}

Serial.println(value,HEX); appeared in serial monitor. are they different?

Only other thing I can think of is to put the prints after the irreceiver function calls in setup. Should not make any difference, but I do not have the hardware for testing.

it's ok, thank you for your effort to help me ....

Could you go into details about:

  1. Exactly what board do you have ("Blue Pill", I think? Maybe post a photo?)
  2. Which "board support package" are you using in the Arduino IDE?
  3. Which "board" do you have selected?
  4. Which "board options" have you set? (See picture)
  5. Exactly how is the board connected to your computer? (Which USB Serial Adapter, if you're using one, connected to which pins of the board, etc.)
  6. Exactly how are you doing the sketch upload? Are you using the same port for both upload AND the "Serial" output you're trying to get?

(Board options (assuming ST Arduino package.)



Your board menu looks much different than mine. Can you check on the board package? It should show up in the "board manager" when you search for "ST":


and perhaps the line in your "preferences" panel:

http://dan.drown.org/stm32duino/package_STM32duino_index.json, https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json

when i checked library manager in my arduino ide does not have like yours one (my arduino library doesn't have yours one as below :
image

Well, I confirmed (reading the source code):

  1. Serial is set equal to Serial1
  2. Serial1 is PA9/PA10

So it looks like you are set up correctly to me.

Did you say that Serial.print() later in your code (when decoding the actual IR codes received IS working? That's very strange indeed.

I'm out of ideas. :frowning:

Your pictures appear to show a mismatch between the pin used for the IR receiver and the code in post #1.

Anyway, if the serial connection sometimes works, then I would begin to suspect that the IR library is some how interfering with it and start by commenting out all IR statements.
Since neither of your two posts which do show some serial output begin with the “loop()” I guess it gets stuck here before it has a chance to print anything.

1 Like

what should i do next? at this moment i just change the ide using stm32cube ide to prgram this board.

The first thing to do is to isolate the problem with Serial.print.

Does this work ?

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(1000);
  Serial.println("setup()");
}

void loop()
{
  Serial.println("loop()");
  delay( 1000) ;
}

thank you for the suggestion. i was trying it. Serial.print.ln(loop); got print on serial monitor, the Serial.println(setup); doesn't print on serial monitor

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(1000);
  Serial.println("setup()");
}

void loop()
{
  Serial.println("loop()");
  delay( 1000) ;
}

result on serial monitor:

loop()
loop()
......

Very strange. Try this and see if the loop() count starts at zero.

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(4000);
  Serial.println("setup()");
}

void loop()
{
  static uint32_t i = 0 ;
  Serial.print("loop()");  // should start at 0
  Serial.println( i++ ) ;
  delay( 1000) ;
}

setup() and loop() provide almost the equivalent environment.

This is from the STM official core: C:\Users\6v6gt\Documents\ArduinoData\packages\STM32\hardware\stm32\1.9.0\cores\arduino

/*
  main.cpp - Main loop for Arduino sketches
  Copyright (c) 2005-2013 Arduino Team.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#define ARDUINO_MAIN
#include "Arduino.h"

// Force init to be called *first*, i.e. before static object allocation.
// Otherwise, statically allocated objects that need HAL may fail.
__attribute__((constructor(101))) void premain()
{

  // Required by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html
#ifdef NVIC_PRIORITYGROUP_4
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
#endif
#if (__CORTEX_M == 0x07U)
  // Defined in CMSIS core_cm7.h
#ifndef I_CACHE_DISABLED
  SCB_EnableICache();
#endif
#ifndef D_CACHE_DISABLED
  SCB_EnableDCache();
#endif
#endif

  init();
}

/*
 * \brief Main entry point of Arduino application
 */
int main(void)
{
  initVariant();

  setup();

  for (;;) {
#if defined(CORE_CALLBACK)
    CoreCallback();
#endif
    loop();
    serialEventRun();
  }

  return 0;
}

Is this hardware that needs a loop waiting for the Serial object to be initialized? Like the Leonardo for example.

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(4000);
  Serial.println("setup()");
}

void loop()
{
  static uint32_t i = 0 ;
  Serial.print("loop()");  // should start at 0
  Serial.println( i++ ) ;
  delay( 1000) ;
}

serial monitor result did not start from zero but :
loop()1
loop()2
loop()3
.....