Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Output to Serial from functions in .cpp file

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    3

    Output to Serial from functions in .cpp file

    How can I reference and use Serial defined in main module in .cpp functions?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,500
    #include <Arduino.h>

    Then you can use any Arduino functions.

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    3
    Quote Originally Posted by PaulStoffregen View Post
    #include <Arduino.h>

    Then you can use any Arduino functions.
    Thank you. Still unpredictably hangs ( like
    Code:
    int Show()
    { 
      Serial.print("*");
    is ok but
    Code:
    int Show()
    { 
      Serial.print("***");
    hangs forever o.O

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,420
    did you even do Serial.begin() before calling that?

  5. #5
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,723
    Quote Originally Posted by tonton81 View Post
    did you even do Serial.begin() before calling that?
    not needed for Serial (is usb serial)

  6. #6
    Junior Member
    Join Date
    Oct 2017
    Posts
    3
    Code:
    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);  
    }
    
    // the loop routine runs over and over again forever:
    void loop() {
      Show();

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,500
    Nobody can meaningfully help you resolve these problems when you don't post your complete code. Since you're not using Arduino, you must also post a clear description of how you've building the code (eg, a makefile, script, exact compiler commands, etc). We have the "Forum Rule" at the top of every page for exactly this reason, to help give you the best possible help with your problem. If your program is too large or contains secret or proprietary info, the expectation is you can trim it to only a small sample which demonstrate the issue without disclosing anything confidential.

    Please, follow the Forum Rule. It saves everyone a lot of time, and it really does result in much better help for you.

  8. #8
    Quote Originally Posted by PaulStoffregen View Post
    ] We have the "Forum Rule" at the top of every page for exactly this reason, to help give you the best possible help with your problem.
    I'm amazed at ho many times you have to say this, and yet, people still do not post their code! Off topic, but perhaps you should change the forum CSS to format that message in huge bold type with a yellow background.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,500
    Yeah, messages lacking essential info are an ongoing problem, but compared to other forums we actually do pretty well here. And the most important part, we usually do figure out issues when photos & code are posted.

    I've actually considered extra css or javascript tricks on the new topic page. Maybe someday...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •