Линукс конфигурация на платката. Бих постнал и QT5 проекта за emmc, но там ми се върти логото на 3Д на дисплея, а аз обичам да съм в сянка.
Сега се сещам, бая си играхме на 125 мегахерца spi дисплей да завъртим 3Д лого при стартъп. Все пак трябваше да бъде платка за 50 долара изцедено.
1. Format the SD Card with "SD Card Formatter" Application
2. Download the Rasian OS - Raspberry Pi OS with desktop
https://www.raspberrypi.org/software/operating-systems/ #Raspberry Pi OS with desktop
3. Extract the *.iso from the *.zip and upload it to the SD Card with "win32DiskImager" Application
4. After writing open the SD Card from the PC and create a empty file called - ssh.txt on the /boot drive to enable SSH
4. Configure LCD if is awailable:
#Download the LCD Driver:
git clone
https://github.com/waveshare/LCD-show.git cd LCD-show/
chmod +x LCD4C-show
./LCD4C-show
#If orentation is incorrect:
./LCD4C-show 0[90/180/270]
5. Enable USB on CM4
sudo nano /boot/config.txt
dtoverlay=dwc2,dr_mode=host
6. Plug the SD Card connect Mouse, Keyboard and LAN Cable and connect the power
7. Go to configs and enable VNC, SSH (If not), I2C, SPI, GPIO, OW
sudo raspi-config
Interfacing Options
...VNC, SSH (If not), I2C, SPI, GPIO, OW
#Enable 1-Wire:
sudo raspi-config
Interfacing Options
1-Wire <YES>
I2C <YES>
SPI <YES>
GPIO <YES>
VNC <YES>
8. Configure serial port:
'''
#allow serial port permissions:
sudo chmod 666 /dev/ttyUSB0
'''
#Stop Kernel messages to Serial port:
sudo raspi-config
Interfacing Options -> Serial:
Kernel messages <NO>
Enable UART <YES>
9. Install libraries
sudo apt-get install python3-pyside2.qt3dcore python3-pyside2.qt3dinput python3-pyside2.qt3dlogic python3-pyside2.qt3drender python3-pyside2.qtcharts python3-pyside2.qtconcurrent python3-pyside2.qtcore python3-pyside2.qtgui python3-pyside2.qthelp python3-pyside2.qtlocation python3-pyside2.qtmultimedia python3-pyside2.qtmultimediawidgets python3-pyside2.qtnetwork python3-pyside2.qtopengl python3-pyside2.qtpositioning python3-pyside2.qtprintsupport python3-pyside2.qtqml python3-pyside2.qtquick python3-pyside2.qtquickwidgets python3-pyside2.qtscript python3-pyside2.qtscripttools python3-pyside2.qtsensors python3-pyside2.qtsql python3-pyside2.qtsvg python3-pyside2.qttest python3-pyside2.qttexttospeech python3-pyside2.qtuitools python3-pyside2.qtwebchannel python3-pyside2.qtwebsockets python3-pyside2.qtwidgets python3-pyside2.qtx11extras python3-pyside2.qtxml python3-pyside2.qtxmlpatterns python3-pyside2uic
sudo apt-get install python3-pyside2.qtmultimedia
sudo apt-get install libqt5multimedia5-plugins qml-module-qtmultimedia
sudo apt-get install qml-module-qtquick*
sudo apt-get install qtdeclarative5-dev
sudo apt-get install qml-module-qtquick-virtualkeyboard
sudo apt-get install python3-psutil
sudo apt-get install python3-numpy
sudo apt-get install python3-pygame
sudo apt-get install libqt5qml5
sudo apt-get install python3-pyftdi
sudo apt-get install python3-pyserial
sudo apt-get install python3-serial
sudo apt-get install libftdi-dev
sudo apt-get install python3-can
sudo apt-get install owfs python-ow ow-shell
sudo apt-get install python3-owfs
sudo apt-get install python3-pyownet
sudo apt-get install pyownet
sudo apt-get install python3-ow
sudo apt-get install owpython
sudo apt-get install python3-owpython
sudo apt-get install owserver
sudo apt-get install python3-onewire
sudo apt-get install python-onewire
sudo apt-get install libow-dev
sudo apt-get install python3-ownet
sudo apt-get install putty -y
python3 -m pip install pyinstaller
python3 -m pip install minimalmodbus
python3 -m pip install modbus_tk
python3 -m pip install onewire
python3 -m pip install pyownet
python3 -m pip install ownet
python3 -m pip install mcp9600
10. Configure MCP2515 CAN Chip in /boot/config.txt write:
# Make TestUtility direcotory in the desktop
sudo mkdir /home/pi/Desktop/TestUtility
sudo mkdir /home/pi/Desktop/Services
sudo nano /boot/config.txt
dtoverlay=mcp2515-can2[0/1/3],oscillator=8000000,interrupt=26
dtoverlay=spi1-1cs
#If the MCP2515 is on SPI1, CS1,2,3.. go to, to download additional dtoverlays:
http://www.industrialberry.com/quad-can ... -canberry/ http://www.industrialberry.com/wp-conte ... verlay.zip #to download the overlays for SPI1.0 - can2 and SPI1.1 - can3
#Extract the archive and copy the two files in /boot/overlays folder
sudo cp mcp2515-can2.dtbo /boot/overlays/mcp2515-can2.dtbo
sudo cp mcp2515-can3.dtbo /boot/overlays/mcp2515-can3.dtbo
#Restart your PI and write
dmesg
#to cmd
#to check are the MCP2515 configured correctly. There should be line like this:
[20.248951] CAN device driver interface
[20.499256] mcp251x spi1.0 can2: MCP2515 successfully initialized.
11. Configure the CAN interface and link:
sudo ip link set can0 up type can bitrate 125000
sudo ifconfig can0 up
sudo ifconfig
# There should be somethink line this:
#can0: flags=193<UP,RUNNING,NOARP> mtu 16
# unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
# RX packets 18 bytes 144 (144.0 B)
# RX errors 0 dropped 4 overruns 0 frame 0
# TX packets 11 bytes 82 (82.0 B)
# TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#To automatically bring up the interface on boot, edit your /etc/network/interfaces file and add the following:
sudo nano /etc/network/interfaces
# Write at the end
auto can0
iface can0 can static
bitrate 125000
# See the interface in FS
ls /sys/bus/spi/devices/spi0.0
#net ...
ls /sys/bus/spi/devices/spi0.0/net/
#can0
ls /sys/bus/spi/devices/spi0.0/net/can0/
#[params]...
# Testing with can utilities
sudo apt-get install can-utils
# Send data
cansend can0 456#43414e2054657374
# Receive
candump can0
12. Test CAN Interface in Python:
import sys, os, can, socket
bus = can.interface.Bus(channel = "can0", bustype = "socketcan_native", bitrate = 50000)
prt = can.Printer()
ntf = can.Notifier(bus, [prt])
# Send
msg = can.Message(arbitration_id = 0x34, data = [1,5,7], is_extended_id = False)
bus.send(msg)
# OR
# Receive
#bus.recv(10.0)
13. Configure the FT Chip used for Modbus(RS485):
#To evade errors make sure that the line: dtoverlay=dwc2,dr_mode=hos is in /boot/config.txt
#Go to:
https://github.com/richardeoin/ftx-prog #and follow instructions
#Configuration is as follows:
CBUS2 - TXDEN
CBUS3 - PWREN
#Steps:
sudo apt-get install build-essential gcc make libftdi-dev
git clone
https://github.com/richardeoin/ftx-prog.git cd ftx-prog/
make
sudo ./ftx_prog --dump
sudo ./ftx_prog --cbus 2 TXDEN
sudo ./ftx_prog --cbus 3 PWREN
sudo ./ftx_prog --dump
14. Test RS485 Interface in Python:
import serial, sys, os
# Openserial port
ser = serial.Serial("/dev/ttyUSB0", 115200, timeout=5)
# readbytes in the serial buffer
n = ser.in_waiting
ser.read(n)
ser.read(ser.in_waiting)
# Send bytes to the serial
wr_str = 'Test123'
ser.write(wr_str.encode())
ser.write(b'Test123')
15. Configure One Wire Interface:
#Instructions:
https://raspberrypi.stackexchange.com/q ... rature-sen i2cdetect -y 1
#Has to have address - 0x18 - DS2482
#Edit config file:
sudo nano /etc/owfs.conf
! server: server = localhost:4304
server: device = /dev/i2c-1
mountpoint = /mnt/1wire
allow_other
http: port = 2121
ftp: port = 2120
server: port = localhost:4304
#Run server:
sudo systemctl enable owserver.service
sudo owfs -C -uall -m /mnt/1wire --allow_other
15. Test OneWire Interface with Pyton:
from pyownet import protocol
owproxy = protocol.proxy(host = 'localhost', port = 4304, flags = protocol.FLG_UNCACHED)
# Find devices
owproxy.dir("")
#['/28.FF857A941605/']
# Find parameters
owproxy.dir("/28.FF857A941605")
#['/28.FF857A941605/address', '/28.FF857A941605/alias', '/28.FF857A941605/crc8', '/28.FF857A941605/errata/', '/28.FF857A941605/family', '/28.FF857A941605/fasttemp', '/28.FF857A941605/id', '/28.FF857A941605/latesttemp', '/28.FF857A941605/locator', '/28.FF857A941605/power', '/28.FF857A941605/r_address', '/28.FF857A941605/r_id', '/28.FF857A941605/r_locator', '/28.FF857A941605/scratchpad', '/28.FF857A941605/temperature', '/28.FF857A941605/temperature10', '/28.FF857A941605/temperature11', '/28.FF857A941605/temperature12', '/28.FF857A941605/temperature9', '/28.FF857A941605/temphigh', '/28.FF857A941605/templow', '/28.FF857A941605/tempres', '/28.FF857A941605/type']
owproxy.read("/28.FF857A941605/type")
#b'DS18B20'
owproxy.read("/28.FF857A941605/temperature")
#b' 25.875'
14. Configure RTC:
i2cdetect -y 1
#Has to have address - 0x68 - DS3231
#Install RTC Python Lib
git clone
https://github.com/switchdoclabs/RTC_SDL_DS3231.git 15. Test RTC with Python:
cd RTC_SDL_DS3231/
python3
import sys
import time
import datetime
import random
import SDL_DS3231
ds3231 = SDL_DS3231.SDL_DS3231(1, 0x68);
# Write current time to the RTC
ds3231.write_now();
# Read DateTime from the RTC
print(ds3231.read_datetime());
# Get RTC Temperature
print(ds3231.getTemp())
16. Test the Relaywith Python:
from gpiozero import LED
import time
relay_gpio = 6;
relay = LED(relay_gpio);
relay.off();
time.sleep(2);
relay.on();
time.sleep(2);
relay.off();
17. Configure CPU Cooling Fan:
# Update pigpio to latest verssion from git
wget
https://github.com/joan2937/pigpio/archive/master.zip unzip master.zip
cd pigpio-master
make
sudo make install
# Run the pigpio deamon
sudo pigpiod
# Create the script
cd /home/pi
sudo mkdir Scripts
# Copy script from Desktop to Scripts folder
sudo cp /home/pi/Desktop/CpuCoolingFanControl.py /home/pi/Scripts/CpuCoolingFanControl.py
# Create cpu-fan.service
cd /lib/systemd/system
sudo touch cpu-fan.service
sudo nano cpu-fan.service
# Place this service code inside
[Unit]
Description=CPU PWM Fan Control
After=multi-user.target
[Service]
User=root
ExecStart=/usr/bin/python3 /home/pi/Scripts/CpuCoolingFanControl.py
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
# Commands are enable,disable,start,stop
sudo systemctl enable cpu-fan.service
sudo systemctl start cpu-fan.service
18. Test CPU Cooling Fan with Pyton:
import pigpio
gpio = 12;
# 0 (Off) to 10000 (10kHz) max
pwm_freq = 5000;
# 0 - Off, 500000 - min, 1000000 - max
pwm_duty = 0;
pi = pigpio.pi();
#pwm_freq := 0 (off) or 1-125M (1-187.5M for the BCM2711).
#pwm_duty := 0 (off) to 1000000 (1M)(fully on).
pi.hardware_PWM(gpio, pwm_freq, pwm_duty);
17. Test USB OTG:
#TODO
18. Configure Bluetooth:
#TODO
19. Test Bluetooth using Python:
#TODO
20. Test All Using CMHunter Test Utility:
#TODO
21. Test Ethernet/WiFi connection:
#For speedtest
https://www.speedtest.net/ #For packetloss test go to
https://packetlosstest.com/22. Start Test Utility on startup
# Make an autostart directory for the current user:
mkdir -p ~/.config/autostart
# Create a .desktop file which runs your script:
cat > ~/.config/autostart/cm_hunter_app.desktop << EOF
[Desktop Entry]
Type=Application
Exec=/usr/bin/python3 /home/pi/Desktop/TestUtility/main.py
EOF
Exec=/home/pi/TestUtility/main
reboot
Notes:
sudo apt-get install qtdeclarative5-qtmultimedia-plugin
sudo apt-get install libqt5multimedia5-plugins qml-module-qtmultimedia
sudo apt-get install python3-pyside2.qtmultimedia
# Check Raspberry model
import subprocess
subprocess.check_output(['sudo', './home/pi/Desktop/ftx_prog', '--dump']).decode();
subprocess.check_output(['cat', '/proc/device-tree/model']).decode()
subprocess.check_output(['cat', '/etc/os-release']).decode()
# Check CPU Temperature
import psutil
psutil.sensors_temperatures(fahrenheit=False)