I found this script to show date an time on this site: http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/

Once is running how can be it stoped? I like the idea of showing the hour when teh raspi is on, but I need to stop it at some point and I do not know hoy to do that. This raspi is runnig some scripts with cron and don´t use a keyboard so, ctrl+c is not an option. Maybe an script?

This is the script to show date and time

This is the script to show date and time

import I2C_LCD_driver import time mylcd = I2C_LCD_driver.lcd()

while True: mylcd.lcd_display_string("Time: %s" %time.strftime("%H:%M:%S"), 1) mylcd.lcd_display_string("Date: %s" %time.strftime("%m/%d/%Y"), 2)

Thanks in advance

  • So you only want the script to show the time at power on?
    – BantuTech
    Mar 9 '17 at 16:34
  • Yes but I will like to run the script again in the middle of another process. But... If the script starts on startup with some method, how can be stopped? Mar 9 '17 at 17:20
  • You are using and infinite while "loop". You need some sort of break statement to exit the loop. After startup, you could start a timer and check that time in the while loop. When it reaches lets say one minute after the start of the program, got to 'break' to get out of the while loop. Mar 9 '17 at 18:29
  • If it is the only Python script running you can use sudo killall python.
    – joan
    Mar 9 '17 at 19:47
  • Ok thanks! Will try both. Silly question, sudo killall python will stop all pythons scripts right? And the next second another script can star with no problem? Mar 9 '17 at 20:21

Did it! Thank you all. sudo killall did what I needed. Then, you forced me to read some more and find the solution I need, to stop the loop when a GPIO is on "high state" :

    while (GPIO.input(22) == 0):
       mylcd.lcd_display_string("Time: %s" %time.strftime("%H:%M:%S"), 1)
       if (GPIO.input(22) == 1):

Then the script to control GPIO 22 will send another message to the LCD. Thanks guys!

  • Well done for the research. I suggest you also add a time.sleep(0.1) to the while loop.
    – joan
    Mar 10 '17 at 13:54
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Jan 24 '20 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.