Changes

Beaglebone black

9,091 bytes added, 07:56, 7 December 2019
/* Networking */
== Lam modified ==
* use 14400 as baud rate for FTDI ; on Mac: screen /dev/cu.usbserial-FTFO858O 14400115200* 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<pre>nameserver 192.168.1.2search home.hentschel.net</pre> === 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<pre>[Unit]Description=LCD Display ServiceAfter=multi-user.targetConflicts=getty@tty1.service [Service]Type=simpleExecStart=/usr/bin/python /home/pi/script/lcd/lcd.pyStandardInput=tty-force [Install]WantedBy=multi-user.target</pre> ==== BBB ====* create file '''/lib/systemd/system/lcd.service''' with following content<pre>[Unit]Description=LCD Display ServiceWants=network.targetAfter=network.targetConflicts=getty@tty1.service [Service]Type=simpleExecStart=/home/thomas/script/lcd/lcd.pyStandardInput=tty-forceRestart=alwaysRestartSec=3User=rootGroup=root [Install]WantedBy=multi-user.target</pre> ==== for all systems ==== sudo systemctl daemon-reload sudo systemctl enable lcd.service sudo systemctl start lcd.service === lcd + button script ======= Raspi ====<pre>#!/usr/bin/python import timeimport Adafruit_GPIO.SPI as SPIimport Adafruit_GPIO.GPIO as GPIOimport Adafruit_SSD1306from PIL import Imagefrom PIL import ImageDrawfrom PIL import ImageFontimport subprocessimport socketimport psutilimport os from gpiozero import CPUTemperaturefrom datetime import datetime button_off = 4gpio = 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) ) </pre> ==== BBB ====<pre>#!/usr/bin/python import timeimport Adafruit_BBIO.SPI as SPIimport Adafruit_BBIO.GPIO as GPIOimport Adafruit_SSD1306from PIL import Imagefrom PIL import ImageDrawfrom PIL import ImageFontimport subprocessimport socketimport psutilimport os from gpiozero import CPUTemperaturefrom 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) ) </pre>
Bureaucrat, administrator
963
edits