(In messing around with the code I appear to have solved my question ‘rubber ducking’ style. Nonetheless, I’ll post it here in case anyone else should run into this.)
I have a panTilt hat that will be used in a time lapse. At the moment just as a swivel head to position the camera at the proper angle.
The actual shots I intended to be taken from a shell script, but AFAIK that cannot control the panTilt hat. So, I wrote a python script that positions the panTilt in the proper angle regularly in case something misaligned it.
Thing was, that setting the angles in a script ran from a crontab did not work while running the same script from Thonny worked just fine. The ‘crontabbed’ script wrote all the files I told it to but did no panning or tilting.
Solution was to give the script some time after the pan-tilt lines. Thonny apparently does that on its own but the crontab appears to sever all connections to the still running servos once the script reaches its last line thus stopping the servos. The last sleep(2) from the script below solved it.
Before I had that in there, I occasionally notices a short buzz from the servos, but never long enough to actually position them properly.
OK, so no question. Am curious though as to what the difference between Thonny and the crontab is. I suppose they both just run the script more or less the same way?
* * * * * /usr/bin/python3 /home/pi/Documents/pantilt/set_position.py
The python script including generating file based output for testing purposes
import datetime import pantilthat import random from time import sleep from picamera import PiCamera camera = PiCamera() dt_date = datetime.datetime.now() fname = dt_date.strftime('%d-%m-%y %I:%M %S %p') + ".txt" path = "/home/pi/Documents/" f = open(path + fname, "w") f.write("Now the file has more content!") f.close() camera.start_preview() sleep(2) pantilthat.pan(-4) pantilthat.tilt(-15) camera.capture(path+fname+'.jpg') sleep(2)