Easy enough when you know how, but stopping desktop Windows from timing out has long been a problem. There are good security, power saving and other reasons why a desktop computer should time-out, but the behaviour is wrong when the computer is logging. Linux and Apple support no-timeout because they started as servers, designed to run non-stop, and the desktop is an add-on. Windows-Server stays awake too, but not cheap or easy, spartan, and not good at running desktop applications.
Good news: I see a new Windows application makes staying awake easier to do on a desktop. Can’t try it because my main Windows laptop broke last month and I’ve lent the spare out. However, the app is PowerTools Awake and it seems straightforward. Or, you can achieve what’s needed by ploughing through the windows control settings as described here. Stop here If only Windows is available.
I prefer RaspberryPi for logging. The Pi3 is fast enough, small, naturally air cooled, uses tiny power compared with a laptop, and runs headless (ie no need for a keyboard, mouse or screen.) ‘Stay awake’ is fully supported – the program keeps going if the user logs out.
Example:
dave@condor:~/devel/python$ nohup python3 serialread.py > logfile.txt &
Gobbledygook explained:
dave@condor:~/devel/python$ – means I’m logged in on the command line as dave on a computer called ‘condor’ and I’m working in the folder “devel/python”.
nohup – Run COMMAND ignoring hangup signals
python3 serialread.py is the COMMAND that nohup keeps running (serialread.py was written by me. It reads the default USB serial port used by Arduino Nano and copies whatever arrives to standard output. System commands work the same way – putty, cutecom, or another terminal emulators might well be preferred.)
> logfile.txt defines standard output to be the file “logfile.txt”
& tells the computer to run the whole job in background, i.e. no screen or keyboard. The user gets the command line back so more commands can be issued, thus multiple nanos can be logged.
Once running, the user can walk away, and can even log out. Nothing times-out, and when he logs back in, he will find serialread.py is still chugging away. The logfile will be bigger…
Last time I tried, Apple worked in exactly the same way as Linux, but it was at least 5 years ago. Doubt it’s changed.
There’s always a booby trap! Here, the operating system buffers output, and nothing appears in the logfile until something flushes the buffer. As buffers can store a lot of data, it might appear that logging has failed, when actually the data is accumulating in a private queue. Be patient.
Dave
PS. Just read Stuart and John’s posts. They’re right that plugging USB in and out resets the Arduino. It’s because the Arduino assumes USB being plugged in mid-flight means the programmer is updating the firmware, and it switches into that mode. However, that’s not wanted when the program is finished. Fortunately the cure is simple – connecting a 10uF capacitor from RESET to GND as described by John, fools the firmware loader, allowing the USB to be plugged in willy-nilly. Don’t forget to unplug the capacitor next time firmware is upgraded though – as Duncan says “but will I remember? Probably not, I’ll waste another hour or so working out what is going on.“.
Duncan describes a different problem I think: “All worked very nicely as long as I was doing something else on the PC, but if I went away for more than 15 minutes, the PC went to sleep, and when I woke it up the minutes count always began again at 1. It appears that the PC waking up resets the arduino. It might be that going to sleep does likewise, can’t tell. This is despite having the 7805 source of 5v continuously. Solution is simple, tell the PC never to go to sleep“. I think he’s right “tell the PC never to go to sleep“.
No harm done fitting a capacitor, provided one remembers it’s there. And as it’s easier to plug in a 10uF cap than mess with Windows, well worth trying first, or as well. Though the capacitor value isn’t critical, 10uF seems reliable.
Setting up a second SerialPort is an alternative to the capacitor, but it’s hardware and software fuss.