From Hentschel
Jump to: navigation, search

Lam modified

  • use 14400 as baud rate for FTDI; on Mac:
  screen /dev/cu.usbserial-FTFO858O 115200
  • default login is debian:
  debian:temppwd
  • P9 header is off by one, counting from 1. There is a extra GND row in position 3-4 ?

Time

  • change time zone: sudo timedatectl set-timezone America/Los_Angeles
  • install ntp: sudo apt-get install ntp

Networking

  • the ethernet interfaces don't appear to work. Using Edimax wifi
  • set manually
 sudo ifconfig eth0 192.168.1.16 netmask 255.255.255.0
  • permanent in in /etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet static
   address 192.168.1.16
   netmask 255.255.255.252
   network 192.168.1.0
   gateway 192.168.1.1
   dns-nameserver 192.168.1.2
   dns-search home.hentschel.net
   wpa-ssid hentschel
   wpa-psk bb78bbaa6a8425255774e5d49b51b4038d55c0c3e493334abbecec31c27096b6
  • disable and remove connman, use standard resolv.conf
 sudo systemctl disable connman
 sudo systemctl stop connman
 sudo apt remove connman

resolv.conf

nameserver 192.168.1.2
search home.hentschel.net

reset switch

  • BBB:
 P8, GPIO 67 <-> GND
  • RasPi
 GPIO 4 <-> GND

install software

Raspberry Pi

 sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
 sudo pip install Adafruit_GPIO
 sudo pip install Adafruit_SSD1306
 sudo apt-get install python-pil
 sudo pip install gpiozero
 sudo pip install psutil

also enable i2c in /boot/config.txt

 dtparam=i2c_arm=on

BBB

 sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
 sudo pip install Adafruit_GPIO
 sudo pip install Adafruit_SSD1306
 sudo apt-get install python-pil
 sudo pip install gpiozero
 sudo apt-get install psutil

enable systemd service

Raspberry Pi

  • create file /lib/systemd/system/lcd.service with following content
[Unit]
Description=LCD Display Service
After=multi-user.target
Conflicts=getty@tty1.service

[Service]
Type=simple
ExecStart=/usr/bin/python /home/pi/script/lcd/lcd.py
StandardInput=tty-force
 
[Install]
WantedBy=multi-user.target

BBB

  • create file /lib/systemd/system/lcd.service with following content
[Unit]
Description=LCD Display Service
Wants=network.target
After=network.target
Conflicts=getty@tty1.service

[Service]
Type=simple
ExecStart=/home/thomas/script/lcd/lcd.py
StandardInput=tty-force
Restart=always
RestartSec=3
User=root
Group=root
 
[Install]
WantedBy=multi-user.target

for all systems

 sudo systemctl daemon-reload
 sudo systemctl enable lcd.service
 sudo systemctl start lcd.service

lcd + button script

Raspi

#!/usr/bin/python

import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_GPIO.GPIO as GPIO
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import subprocess
import socket
import psutil
import os

from gpiozero import CPUTemperature
from datetime import datetime

button_off = 4
gpio = GPIO.get_platform_gpio()

while True:
  try:
    gpio.setup(button_off, GPIO.IN, GPIO.PUD_UP)
    button_oldstate = gpio.input(button_off)
    #
    RST = 0
    #
    disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
    disp.begin()
    disp.clear()
    disp.display()
    #
    width = disp.width
    height = disp.height
    #
    image1 = Image.new('1', (width, height))
    draw = ImageDraw.Draw(image1)
    draw.rectangle((0,0,width,height), outline=0, fill=0)
    #
    padding = -2
    top = padding
    #
    bottom = height-padding
    x = 0
    font = ImageFont.load_default()
    #
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("192.168.1.1", 80))
    hostname = socket.gethostname()
    ip = s.getsockname()[0]
    firstline = ip + " " + hostname
    #
    while True:
      time.sleep(1)
      #
      image1 = Image.new('1', (width, height))
      draw = ImageDraw.Draw(image1)
      draw.rectangle((0,0,width,height), outline=0, fill=0)
      cputemp = CPUTemperature()
      memstr = '{0: >5}'.format(str(int(psutil.virtual_memory().percent))) + "%|" 
      statvfs = os.statvfs('/')
      disktotal = statvfs.f_frsize * statvfs.f_blocks     # Size of filesystem in bytes
      diskfree = statvfs.f_frsize * statvfs.f_bavail     # Number of free bytes that ordinary users
      diskpercent = round((disktotal - diskfree) * 100.0 / float(disktotal),0)
      diskstr = 'SD:' + '{0: >3}'.format(str(int(diskpercent))) + "%" 
      now = datetime.now()
      tempstr ='{0: >5}'.format(str(round(cputemp.temperature,))) + u"\u00b0" + "C|"
      cpustr = '{0: >6}'.format(str(round(psutil.cpu_percent(),1))) + "%"
      secondline = "CPU:" + tempstr + cpustr
      thirdline = "MEM: " + memstr + diskstr
      fourthline = now.strftime("%d/%m/%Y %H:%M:%S")
      disp.clear()
      draw.text((x, top),       firstline,  font=font, fill=255)
      draw.text((x, top+8),     secondline, font=font, fill=255)
      draw.text((x, top+16),    thirdline,  font=font, fill=255)
      draw.text((x, top+25),    fourthline, font=font, fill=255)
      disp.image(image1)
      disp.display()
      #
      # 
      button_state = gpio.input(button_off)
      if( button_state != button_oldstate ):
        if( button_state ):
          print("Button OFF")
        else:
          print("Button ON -> reboot")
          disp.clear()
          image1 = Image.new('1', (width, height))
          draw = ImageDraw.Draw(image1)
          draw.rectangle((0,0,width,height), outline=0, fill=0)
          draw.text((x, top + 8), "Rebooting...",  font=font, fill=255)
          disp.image(image1)
          disp.display()
          os.system("reboot now")
          # exit()
        button_oldstate = button_state
      # 
      # 
  except Exception as e:
    print("LCD Error: %s"  % str(e) )

BBB

#!/usr/bin/python

import time
import Adafruit_BBIO.SPI as SPI
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import subprocess
import socket
import psutil
import os

from gpiozero import CPUTemperature
from datetime import datetime


button_off = "P8_8"

while True:
  try:
    GPIO.setup(button_off, GPIO.IN, GPIO.PUD_UP)
    button_oldstate = GPIO.input(button_off)
    # BBB
    RST = 'P9_12'
    disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2)
    # Raspi
    # RST = 0
    # disp = Adafruit_SSD1306.SSD1306_128_32(rst=None)
    disp.begin()
    disp.clear()
    disp.display()
    #
    width = disp.width
    height = disp.height
    #
    image1 = Image.new('1', (width, height))
    draw = ImageDraw.Draw(image1)
    draw.rectangle((0,0,width,height), outline=0, fill=0)
    #
    padding = -2
    top = padding
    bottom = height-padding
    x = 0
    font = ImageFont.load_default()
    #
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("192.168.1.1", 80))
    hostname = socket.gethostname()
    ip = s.getsockname()[0]
    firstline = ip + " " + hostname
    #
    while True:
      time.sleep(1)
      # 
      image1 = Image.new('1', (width, height))
      draw = ImageDraw.Draw(image1)
      draw.rectangle((0,0,width,height), outline=0, fill=0)
      # cputemp = CPUTemperature()
      memstr = '{0: >5}'.format(str(int(psutil.virtual_memory().percent))) + "%|" 
      statvfs = os.statvfs('/')
      disktotal = statvfs.f_frsize * statvfs.f_blocks     # Size of filesystem in bytes
      diskfree = statvfs.f_frsize * statvfs.f_bavail     # Number of free bytes that ordinary users
      diskpercent = round((disktotal - diskfree) * 100.0 / float(disktotal),0)
      diskstr = 'SD:' + '{0: >3}'.format(str(int(diskpercent))) + "%" 
      now = datetime.now()
      # tempstr ='{0: >5}'.format(str(round(cputemp.temperature,))) + u"\u00b0" + "C|"
      tempstr = "       |"
      cpustr = '{0: >6}'.format(str(round(psutil.cpu_percent(),1))) + "%"
      secondline = "CPU:" + tempstr + cpustr
      thirdline = "MEM: " + memstr + diskstr
      fourthline = now.strftime("%d/%m/%Y %H:%M:%S")
      disp.clear()
      draw.text((x, top),       firstline,  font=font, fill=255)
      draw.text((x, top+8),     secondline, font=font, fill=255)
      draw.text((x, top+16),    thirdline,  font=font, fill=255)
      draw.text((x, top+25),    fourthline, font=font, fill=255)
      disp.image(image1)
      disp.display()
      #
      # 
      button_state = GPIO.input("P8_8")
      if( button_state != button_oldstate ):
        if( button_state ):
          print("Button OFF")
        else:
          print("Button ON -> reboot")
          disp.clear()
          image1 = Image.new('1', (width, height))
          draw = ImageDraw.Draw(image1)
          draw.rectangle((0,0,width,height), outline=0, fill=0)
          draw.text((x, top + 8), "Rebooting...",  font=font, fill=255)
          disp.image(image1)
          disp.display()
          os.system("reboot now")
          # exit()
        button_oldstate = button_state
      # 
      # 
  except Exception as e:
    print("LCD Error: %s"  % str(e) )