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 Terminal.app (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:
Contents of the AppleScript:
Contents of the Python script:
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
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 Terminal.app (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:
Code:
set scriptPath to (POSIX path of (path to me)) & "Contents/Resources/Scripts/Teensy3Monitor.py"
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
activate
end tell
else
tell application "Terminal"
do script with command scriptPath
activate
end tell
end if
end tell
Contents of the Python script:
Code:
#!/usr/bin/python
from os import system
from os.path import exists
from subprocess import call
path = '/dev/tty.usbmodem12341'
start_waiting_now = True
call(['killall', 'SCREEN'])
system('clear')
while True:
if exists(path):
call(['screen', path])
start_waiting_now = True
else:
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
Attachments
Last edited: