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

Thread: Teensy3Monitor: Terminal-based Teensy 3.0 Serial Monitor App for OS X

  1. #1

    Teensy3Monitor: Terminal-based Teensy 3.0 Serial Monitor App for OS X

    Hi, thought I'd share a little utility I put together to ease monitoring serial output from the Teensy 3.0. One thing that really bugs me about the built-in Arduino serial monitor is that it constantly needs to be re-opened, and likewise it doesn't continue to display output if the Teensy is reset. I wanted a stand-alone, persistent window that would display serial output across resets. This is what I ended up with, which works well, except for a few caveats.

    Basically, this is an AppleScript routine and a Python script contained inside in an OS X app wrapper. Running the app executes the AppleScript, which in turn opens (if it's not open already) and executes the Python script. The Python script kills any existing instances of the screen process, then enters a loop in which it checks for the presence of /dev/tty.usbmodem12341 (the Teensy 3.0). If it exists, it starts a screen session to monitor the Teensy. If it doesn't exist (indicating the Teensy is disconnected or off), it prints a waiting message.

    In practice, this has worked reasonably well for me. However, there are a few caveats, which I'd love to address if anyone has feedback about how to do so:

    • If Teensy3Monitor is running, the Teensy won't auto-upload new code from the Arduino IDE, and the button on the device needs to be pressed each time.
    • Serial output history can't be scrolled back in the Terminal window. I believe this is due to the use of the screen process.
    • Every once in a while (rarely), Teensy3Monitor misses the occurance of a reset. Cycling power (of the Teensy) seems to force detection.
    • Teensy3Monitor can't be used to send serial data to the Teensy. It's for monitoring the Teensy's serial output only.

    Contents of the AppleScript:

    set scriptPath to (POSIX path of (path to me)) & "Contents/Resources/Scripts/"
    tell application "System Events"
    	if (count (every process whose name is "Terminal")) is 0 then
    		tell application "Terminal"
    			do script with command scriptPath in window 1
    		end tell
    		tell application "Terminal"
    			do script with command scriptPath
    		end tell
    	end if
    end tell
    Contents of the Python script:

    from os import system
    from os.path import exists
    from subprocess import call
    path = '/dev/tty.usbmodem12341'
    start_waiting_now = True
    call(['killall', 'SCREEN'])
    while True:
    	if exists(path):
    		call(['screen', path])
    		start_waiting_now = True
    		if start_waiting_now:
    			print '\033[J' + '\033[1;31m' + '\nWaiting for ' + path + '\033[0m'
    			start_waiting_now = False
    The app package itself is downloadable as an attachment to this post.

    Let me know if you have any problems or thoughts about potential improvements. -Dan
    Attached Files Attached Files
    Last edited by loglow; 02-02-2013 at 09:25 PM.

Tags for this Thread

Posting Permissions

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