Различия

Здесь показаны различия между двумя версиями данной страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
dev:pi:main [2016/09/20 17:39]
denis [rtc ds3231]
dev:pi:main [2016/12/09 10:15] (текущий)
denis [shutdown]
Строка 91: Строка 91:
 1. Enable I2C: 1. Enable I2C:
   sudo raspi-config   sudo raspi-config
-  "Advanced Options"​ / "A6 I2C"+  "​Advanced Options"​ / "A6 I2C"
   ​   ​
-2. Install I2C-tools:+2. Sort out packages: 
 +<code bash>
   sudo apt-get install python-smbus i2c-tools   sudo apt-get install python-smbus i2c-tools
 +  sudo apt-get purge fake-hwclock ntp
 +  sudo apt-get install ntpdate # TODO: not found
 +
 +  sudo apt-get update
 +  sudo apt-get upgrade
 +  sudo apt-get dist-upgrade
 +</​code>​
   ​   ​
 3. Check Pi starts I2C automatically in ''/​etc/​modules'':​ 3. Check Pi starts I2C automatically in ''/​etc/​modules'':​
Строка 100: Строка 108:
   ​   ​
 4. Check user has group (change ''​pi''​ to required): 4. Check user has group (change ''​pi''​ to required):
 +<code bash>
   sudo adduser pi i2c   sudo adduser pi i2c
-   +</​code>​
-5. Update to latest packeges: +
-  sudo apt-get update +
-  sudo apt-get upgrade +
-  sudo apt-get dist-upgrade+
  
-6. reboot +5. Add at the end of ''/​boot/​config.txt'': ​
- +
-7. Check RTC appears on channel 68: +
-  sudo i2cdetect -y 1 +
- +
-8. Add at the end of ''/​boot/​config.txt'': ​+
   dtoverlay=i2c-rtc,​ds3231   dtoverlay=i2c-rtc,​ds3231
 +
 +6. Add the line in ''/​etc/​rc.local''​ (above “exit 0”):
 +  /​sbin/​hwclock -s
   ​   ​
-9Don't need hwclock ​and ntp: +7Change in ''/​etc/​init.d/​hwclock.sh''​
-<code bash> +  ​HWCLOCKACCESS=no
-  ​sudo apt-get purge fake-hwclock +
-  sudo apt-get purge ntp +
-  sudo apt-get install ntpdate +
-</​code>​+
   ​   ​
-10. Set date/time:+8. reboot 
 + 
 +9. Set date/time: 
 +<code bash>
   sudo dpkg-reconfigure tzdata   sudo dpkg-reconfigure tzdata
   sudo date -s "2 SEPTEMBER 2016 10:​00:​00"​   sudo date -s "2 SEPTEMBER 2016 10:​00:​00"​
   sudo hwclock -w  ​   sudo hwclock -w  ​
 +</​code>​
   ​   ​
-11. Add the line in ''/​etc/​rc.local''​ (above “exit 0”): +
-  /​sbin/​hwclock -s +
-   +
-12. Change in ''/​etc/​init.d/​hwclock.sh'':​ +
-  HWCLOCKACCESS=no +
-   +
-13. reboot+
  
 Done! Done!
  
 14. Other info commands: 14. Other info commands:
 +<code bash>
 +  sudo i2cdetect -y 1
   sudo dmesg | grep rtc   sudo dmesg | grep rtc
   sudo cat /​proc/​driver/​rtc   sudo cat /​proc/​driver/​rtc
 +</​code>​
   ​   ​
 Compiled from: [[https://​elementztechblog.wordpress.com/​2015/​08/​08/​real-time-clock-rtc-interfacing-with-raspberrypi/​|src1]] [[https://​trick77.com/​adding-ds3231-real-time-clock-raspberry-pi-3/​|src2]] Compiled from: [[https://​elementztechblog.wordpress.com/​2015/​08/​08/​real-time-clock-rtc-interfacing-with-raspberrypi/​|src1]] [[https://​trick77.com/​adding-ds3231-real-time-clock-raspberry-pi-3/​|src2]]
Строка 145: Строка 145:
  
  
 +===== shutdown =====
  
 +{{:​dev:​pi:​rpi_shutdown_scheme.png|}}
  
-  ​+''/​home/​pi/​softshut/​softshut.py'':​ 
 +<code python>​ 
 +#​!/​usr/​bin/​python 
 +import time 
 +from subprocess import call 
 +import RPi.GPIO as gpio
  
 +pinBt=19
 +pinAC=21
 +pinLed=23
  
 +dlyShutdownBt = 5
 +dlyShutdownAC = 10
 +
 +dlyLedOk = 1
 +dlyLedFast = 0.1
 +
 +
 +def loop():
 +  hasBt = False
 +  hasAC = False
 +  timeBt = 0
 +  timeAC = 0
 +  dlyLed = dlyLedOk
 +  terminated = False
 +
 +  while gpio.input(pinBt)>​0 or gpio.input(pinAC)>​0:​
 +    for i in range(0,3):
 +      gpio.output(pinLed,​ True)
 +      time.sleep(dlyLedFast)
 +      gpio.output(pinLed,​ False)
 +      time.sleep(dlyLedFast)
 +    time.sleep(dlyLedOk)
 +
 +  while not terminated:
 +
 +    if gpio.input(pinBt)==0:​
 +      if timeBt > 0:
 +        print "Bt OK"
 +        timeBt = 0
 +    else:
 +      if timeBt == 0:
 +        print "Bt failed"​
 +        timeBt = time.time()
 +      else:
 +        if time.time() - timeBt > dlyShutdownBt:​
 +          print "Bt shutdown"​
 +          doShutdown()
 +          terminated = True
 +
 +
 +    if gpio.input(pinAC)==0:​
 +      if timeAC > 0:
 +        print "AC OK"
 +        timeAC = 0
 +    else:
 +      if timeAC == 0:
 +        print "AC failed"​
 +        timeAC = time.time()
 +      else:
 +        if time.time() - timeAC > dlyShutdownAC:​
 +          print "AC shutdown"​
 +          doShutdown()
 +          terminated = True
 +
 +
 +
 +    if (timeAC > 0  or  timeBt > 0) and dlyLed == dlyLedOk:
 +      dlyLed = dlyLedFast
 +    elif timeAC == 0  and  timeBt == 0  and  dlyLed != dlyLedOk:
 +      dlyLed = dlyLedOk
 +
 +    gpio.output(pinLed,​ True)
 +    time.sleep(dlyLed)
 +    gpio.output(pinLed,​ False)
 +    time.sleep(dlyLed)
 +
 +
 +
 +def eventButton(pin):​
 +  print "​Button shutdown"​
 +  doShutdown()
 +
 +def doShutdown():​
 +#  call('​halt',​ shell=False)
 +  print "​SHUTDOWN!!!"​
 +
 +
 +gpio.setmode(gpio.BOARD)
 +gpio.setup(pinBt,​ gpio.IN)
 +gpio.setup(pinAC,​ gpio.IN)
 +gpio.setwarnings(False)
 +gpio.setup(pinLed,​ gpio.OUT)
 +loop()
 +gpio.cleanup()
 +</​code>​
 +
 +
 +''/​etc/​rc.local'':​
 +<code bash>
 +# add this line before "exit 0"
 +python /​home/​pi/​softshut/​softshut.py &
 +</​code>​
  
  
dev/pi/main.1474382346.txt.gz · Последние изменения: 2016/09/20 17:39 — denis
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0