Raspberry Pi

install raspbian

https://www.raspberrypi.org/documentation/installation/installing-images/linux.md

df -h
sudo umount /dev/sdb1
sudo dd bs=4M if=2015-11-21-raspbian-jessie.img of=/dev/sdb
sudo dd bs=4M if=/dev/sdb of=from-sd-card.img
truncate --reference 2015-11-21-raspbian-jessie.img from-sd-card.img
diff -s from-sd-card.img 2015-11-21-raspbian-jessie.img
sync

initial setup

sudo raspi-config

user: pi
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

src

xserver start/stop

sudo startx
sudo /etc/init.d/lightdm stop

keyboard

/etc/default/keyboard:

XKBLAYOUT="us"

temperature

#!/bin/bash
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$(($cpuTemp2 % $cpuTemp1))
 
echo CPU temp"="$cpuTemp1"."$cpuTempM"'C"
echo GPU $(/opt/vc/bin/vcgencmd measure_temp)

wifi

sudo iwlist wlan0 scan|more

sudo nano /etc/network/interfaces

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
  ssid="YOURSSID"
  psk="YOURPASSWORD"
}
sudo ifdown wlan0
sudo ifup wlan0

jdk

http://www.rpiblog.com/2014/03/installing-oracle-jdk-8-on-raspberry-pi.html

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

download jdk-8-linux-arm-vfp-hflt.tar.gz for Linux ARM v6/v7 Hard Float ABI

sudo tar zxvf jdk-8-linux-arm-vfp-hflt.tar.gz -C /opt
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0/bin/java 1
sudo update-alternatives --config javac
sudo update-alternatives --config java
java -version
javac -version

rtc ds3231

1. Enable I2C:

sudo raspi-config
"Advanced Options" / "A6 I2C"

2. Sort out packages:

  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

3. Check Pi starts I2C automatically in /etc/modules:

i2c-dev

4. Check user has group (change pi to required):

  sudo adduser pi i2c

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

7. Change in /etc/init.d/hwclock.sh:

HWCLOCKACCESS=no

8. reboot

9. Set date/time:

  sudo dpkg-reconfigure tzdata
  sudo date -s "2 SEPTEMBER 2016 10:00:00"
  sudo hwclock -w  

Done!

14. Other info commands:

  sudo i2cdetect -y 1
  sudo dmesg | grep rtc
  sudo cat /proc/driver/rtc

Compiled from: src1 src2

shutdown

/home/pi/softshut/softshut.py:

#!/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()

/etc/rc.local:

# add this line before "exit 0"
python /home/pi/softshut/softshut.py &
dev/pi/main.txt · Последние изменения: 2016/12/09 10:15 — denis
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0