I am working on a temperature measuring project. I already flashed the firmware to the Electron successfully but having trouble to see the data it gathered on Terminal.
After flashed the code, I ran the command ls /dev/tty.*, found the serial port, then screen /dev/tty.usbserial-A700eWEe 9600. First time Terminal generated a “1.screen” window and I could see all the data that printed out! Yay! But then I closed the Terminal, plugged out the Electron, and ran the same commands again (flash codes -> screen the data) but it didn’t work! The error was “Couldn’t find PTY”. I tried to look up online but nothing helpful. I’ve been stumped for hours. Does anyone know what’s going on? Thank you for your help in advance!
I am using Macbook (Sierra, Version 10.12.1) and iTerm2 (Build 3.0.15).
Sorry I forgot to mention I plugged them back on haha. I plugged them out to turn them off, then plugged them back, flashed the code again, ran the two commands to find the serial port and screen again, like how I did the first time! But could never see the data from Terminal again T-T
BTW this is my forth day learning particle and first time posting my question and already feeling the love from the particle community! Thank you! You guys are lit!!
Using the Mac built in Terminal program, I sometimes get an error of “Sorry, could not find a PTY”. This happens if the Photon is already running, and plugged into USB before I launch the Terminal window and send the screen /dev/tty.usbserial* command. If I launch the Terminal window first, restart the Photon (or reset it), then send the screen command, it does find the PTY.
@nrobinson2000, I’ve always used /dev/tty.usbserial* on my iMac (Sierra10.12.6 and older versions), but /dev/cu.usbserial* also works for me.
Using the Particle CLI, my favorite in Terminal is just to do:
particle serial monitor --follow
If you hit the reset, it will automatically reconnect and continue displaying output.
The only drawback with this is do not disconnect the USB before control-C’ing out of this command. It will lock up the Terminal. If you do, you can plug it back in and then Ctrl-C. If you need to force it to shutdown, you will have to put it into the background Ctrl-Z and then kill the background process. Usually: kill -9 %1
%1 being the 1st background job. You can find out using the jobs command.
It is displaying data on 1.screen on iTerm right now but I am having trouble to kill it - control-c doesn’t work, and I can’t even type anything. I also tried what @cermak said and whatever I googled but the thing is I can’t type D:::
How can I kill the process on 1.screen window without closing Terminal, and get back to the 1.bash window? Thank you!!
@manlin - I am not sure if you actually wanted to send information to your device. I tried a few different screen options and could not get the automatic CR/LF working properly when you pressed return/enter on the Mac. I had to build it into the code.
There is timer in there to produce output every 15 seconds on top of being just echoing the characters back to the screen. The “>” is not necessary, but I needed to determine if the echo was actually coming from the Serial and not being produced by screen.
Sample code:
/*
* Project twoWaySerial
* Description: Test two way communication using Serial interface
* and screen in MacOSX.
* Author: Rob Cermak
* Date: 2017-10-11
*/
void print_counter()
{
static int count = 0;
Serial.println(count++);
}
Timer timer(15000, print_counter);
// setup() runs once, when the device is first turned on.
void setup() {
// Put initialization like pinMode and begin functions here.
Serial.begin(9600);
timer.start();
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// The core of your code will likely live here.
}
// Read input from the Serial port, you will
// need to add more code to actually perform
// an action based on provided input.
// Right now, everything read here will be
// echo'ed back to you.
void serialEvent()
{
char c = Serial.read();
if (c == 13) {
// When using screen, we have to convert CR to CR/LF
Serial.println();
} else {
Serial.printf(">%c",c);
}
}
Screen command (match the baud rate and determine the serial port):
$ particle serial list
Found 1 device connected via serial:
/dev/cu.usbmodem1421 - Photon
$ screen /dev/cu.usbmodem1421 9600