Hi Peter, > > Can you attach the output of > > > > diff -u working.py broken.py > > > > where you've done some simple change which breaks it, e.g... > > I can't do that because every time it fails I back it out to the > working code.
I don't see why that means you can't have two files, one of which is a copy of the faulty code before you back up to the working code. > Attached is the Python with the Logger code inserted. It also > contains the Ultrasonic detection and action [Distance() and > us_act()]. So I'm assuming this is the faulty code. > Perhaps I don't know where to find the debug_log.txt. It will be in the current directory when you run your program. If you want it somewhere specific, make it '/tmp/debug_log.txt' in the code. You should find that file given your first debug() call as those lines work for me here. $ cat >peter.py import logging logging.basicConfig(filename='debug_log.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') logging.debug('This is a log message.') $ $ python peter.py $ cat debug_log.txt 2021-01-29 09:42:35,195 - DEBUG - This is a log message. $ > def distance(): > logger.debug('Start distance sampling') > > # set Trigger to HIGH > GPIO.output(GPIO_TRIGGER, True) > > # set Trigger after 0.01ms to LOW > time.sleep(0.00001) > GPIO.output(GPIO_TRIGGER, False) > > StartTime = time.time() > StopTime = time.time() > > # save StartTime > while GPIO.input(GPIO_ECHO) == 0: > StartTime = time.time() What if that loop takes a very long time to exit? > # save time of arrival > while GPIO.input(GPIO_ECHO) == 1: > StopTime = time.time() Or that one. I'd add extra logic to limit both to either a number of iterations or an amount of time. If the limit is reached then that's a fault to log as you don't expect it. -- Cheers, Ralph. -- Next meeting: Online, Jitsi, Tuesday, 2021-02-02 20:00 Check to whom you are replying Meetings, mailing list, IRC, ... http://dorset.lug.org.uk New thread, don't hijack: mailto:dorset@mailman.lug.org.uk