Различия
Здесь показаны различия между двумя версиями данной страницы.
Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
dev:pi:main [2016/09/02 06:43] denis |
dev:pi:main [2016/12/09 10:15] (текущий) denis [shutdown] |
||
---|---|---|---|
Строка 17: | Строка 17: | ||
user: ''pi''\\ | user: ''pi''\\ | ||
pass: ''raspberry'' | pass: ''raspberry'' | ||
+ | |||
+ | ===== static ip ===== | ||
+ | ''/etc/dhcpcd.conf'': | ||
+ | interface eth0 | ||
+ | static ip_address=192.168.2.210/24 | ||
+ | static routers=192.168.2.1 | ||
+ | static domain_name_servers=192.168.2.1 | ||
+ | |||
+ | [[https://pi-hole.net/faq/how-do-i-set-a-static-ip-address-in-raspbian-jessie-using-etcdhcpcd-conf/|src]] | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | ===== xserver start/stop ===== | ||
+ | sudo startx | ||
+ | sudo /etc/init.d/lightdm stop | ||
+ | |||
===== keyboard ===== | ===== keyboard ===== | ||
Строка 74: | Строка 91: | ||
1. Enable I2C: | 1. Enable I2C: | ||
sudo raspi-config | sudo raspi-config | ||
- | "7 Advanced Options" / "A6 I2C" | + | "Advanced Options" / "A6 I2C" |
| | ||
- | 2. Install I2C-tools: | + | 2. Sort out packages: |
- | sudo apt-get install python-smbus | + | <code bash> |
- | sudo apt-get install 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'': | ||
Строка 84: | Строка 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. Add at the end of ''/boot/config.txt'': | ||
+ | dtoverlay=i2c-rtc,ds3231 | ||
+ | |||
+ | 6. Add the line in ''/etc/rc.local'' (above “exit 0”): | ||
+ | /sbin/hwclock -s | ||
| | ||
- | 5. Update to latest packeges: | + | 7. Change in ''/etc/init.d/hwclock.sh'': |
- | sudo apt-get update | + | HWCLOCKACCESS=no |
- | sudo apt-get upgrade | + | |
- | sudo apt-get dist-upgrade | + | 8. reboot |
- | 6. reboot | + | 9. Set date/time: |
+ | <code bash> | ||
+ | sudo dpkg-reconfigure tzdata | ||
+ | sudo date -s "2 SEPTEMBER 2016 10:00:00" | ||
+ | sudo hwclock -w | ||
+ | </code> | ||
+ | | ||
+ | Done! | ||
+ | |||
+ | 14. Other info commands: | ||
+ | <code bash> | ||
+ | sudo i2cdetect -y 1 | ||
+ | sudo dmesg | grep 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]] | ||
+ | |||
+ | ===== 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> | ||