How to read Serial.print() messages on OSX? [SOLVED]

Hi there!

I’m trying to debug some code on my Spark Core and I see a lot of use of the Serial port for this type of thing, however I can’t figure out where I’m supposed to be reading these messages?

I have my Spark Core hooked up to a USB port on my Macbook Pro. I have CoolTerm installed but I cannot see any Serial ports called ‘usb…’ in there, just 4 starting with the word ‘Bluetooth’ so I haven’t been able to see anything in CoolTerm either.

Any suggestions? Thanks in advance!

Cheers,
Annie

@codefrenzy,

Did you use Serial.begin(9600); in your setup() code?

Once the plug in the core to USB, it should show up somehow :smiley:

Check the COM port maybe to see if the core is listed.

I don’t own a core (on my buying list) so we have to wait for all the MAC pros :smiley:

Hi @kennethlimcp,

Yup, I do have Serial.begin(9600); in the setup() method… Still nothing :frowning:

I have seen in other posts that the Spark Core needs to be in ‘listening’ mode for apps like CoolTerm to pick it up as a port. I’m not sure how you’re supposed to have your Spark Core running code but also be in listening mode at the same time…

Thanks for your help anyway :smile:

Nope. Listening mode is only during the setup of Wifi Credentials.

Having said that…You can attempt to put your core in listening mode and see how it appears on your mac.

Simple hold down the MODE button for 4 seconds till it starts blinking blue. See what appears on your Mac.

Once that is done…hit RESET to restart the core :wink:

Yup, putting the Spark Core into listening mode has made it show up in the list of serial ports in CoolTerm. Now I have the 4 Bluetooth ones that always show up as well as one called usbmodemfd131… Hmm!!

And as expected, hitting the RESET button to restart the core makes that serial port disappear… :frowning:

Ok great! So with Serial.begin() the core should also show up in the list :smile:

usbmodemfd131 doesn’t look right :smiley:

Can you paste your code in gist so that i can take a look why Serial.begin() isn’t working?

Sure!

Aha!

So the trick is to set the Spark Core to ‘listening mode’, select that usbmodem… port as the one to connect to in CoolTerm, hit the reset button on the Spark Core and then connect to this port in CoolTerm. Now I’m seeing some values coming through… :smile:

I’m not sure that this is the way it’s supposed to work but it works for me now and hopefully will help me debug the other issues I’m having!

Thanks for your help!!

Cheers,
Annie

1 Like

I scratched my head for a minute… :stuck_out_tongue:

The code looks really simple and works for me.

Let’s wait for the MAC PROS (i’m getting jealous over all the mac owners :D)

Yeah, I would like to know if this little trick of setting the Spark to ‘listening mode’ is really what you’re supposed to do or whether there’s another way - hopefully another Mac user can let us know!!

Cheers,
Annie

Nope. Like i mentioned, you don’t need listening mode to use Serial.

Serial works on normal code as well.

I listen to serial messages from the Spark Core from the command line all the time. Do you have screen installed? You can find out by typing screen --version in Terminal.

How i use screen:

  • Make sure sketch has Serial.begin
  • Boot Spark Core, let serial interface initialize for a bit (some seconds, you will find out)
  • run this command in Terminal: screen /dev/tty.usbmodemfa131 9600
    • usbmodemfa131 is just an example, you need to change it:
    • if you type the above command in Terminal, hit Tab when you have entered tty., it should then autocomplete to a correct tty.
    • It’s a different letter/number combination for different USB ports!
  • You should see your serial output in Terminal.
  • You can repeat older terminal commands by pressing several times. Super useful if you have closed a screen session and would like to start another.
4 Likes

Yes! That works! Thank you so much @akrusen! I knew there would be another way to look at these debug messages, just didn’t know where to look.

Great, mystery solved. Thanks all for your help :smile:

Cheers,
Annie

1 Like

Happy to help, glad you could use it! :smile:

Hi @akrusen
When I end my debug session (either by resetting the core, or powering it down) the terminal is in a weird state. Anything I type in the console window is not echo’d back and new lines are just linefeeds. Any suggestions? I typically close the shell because it is unusable but I would like to keep it open and reuse it.

@mtnscott you might want to exit screen by pressing Ctrl + A + k (first ctrl+a - then k)

if its a screwed up terminal input/ouput, executing

$ reset

will reset its current state.

happy debugging! :sunflower:

3 Likes