樹莓派用於裁線
安裝樹派
- 下載Raspbian Buster Lite
- 下載克隆軟體balenaEtcher
- Raspberry Pi設定
- 預設帳密 帳號: pi 密碼: raspberry
- 設定指令sudo raspi-config
- 變更密碼->1 Change User PW->
- 設定時區I2->Change Timezone->Asia->Taipei
- 設定WIFI國別->I4 Change Wi-fi Country->TW Taiwan
- 設定WIFI帳密->2 Network Options->N2 Wi-fi->輸入WIFI的SSID->輸入WIFI密碼
- 設定鍵盤 Layout->4 Localisation Options->I3 Change Keyboard Layout->Generic 104-Key PC->US->English (US)->No AltGr Key->Left Logo Key
- 啟動SSH->5 Interfacing Options->P2 SSH->YES
- 設定auto login->Boot options
- 查詢ip->ip a
- 切換python 2.7->3.7
- sudo ln -f -s /usr/bin/python3.7 /usr/bin/python
- 安裝pip
- sudo apt-get install python3-pip
- 安裝distutils
- sudo apt-get install python3-distutils
- sudo apt-get install python3-dev
- 安裝pyserial
- sudo pip3 install pyserial
- 修改/boot/cmdline.txt
- dwc_otg.lpm_enable=0 console=ttyAMA0,9600 kgdboc=ttyAMA0,9600 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
- 樹莓派串口通信開發環境
- pip3 install RPi.GPIO
- 安裝git
- sudo apt-get update
- sudo apt-get install git
- nRF24L01模組
- Wireless Pi to Pi Python Communication with NRF24L01+
- sudo raspi-config
- 5.Interfacing options->P4 SPI Enable->restart
- On my Pi in python I use that : pipes = [0xF0F0F0F0E1, 0xF0F0F0F0D2] && And On my Arduino Nano : const uint64_t addresses[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
- nRF24L01模組2 py-nrf24
- pip3 install nrf24
- https://github.com/bjarne-hansen/py-nrf24
- nRF24L01模組3 Syrex-o/lib_nrf24
- enable SPI in raspi-config
- wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
- unzip master.zip
- rm master.zip
- cd ./py-spidev-master
- sudo python3 setup.py install
- mkdir /home/pi/NRF24L01
- cd /home/pi/NRF24L01
- git clone https://github.com/Syrex-o/lib_nrf24
- cd ./lib_nrf24/
- cp lib_nrf24.py /home/pi/NRF24L01/
- sudo apt-get install python3-rpi.gpio -y
- nRF24L01模組4
- enable SPI
- sudo apt-get update
- sudo apt-get install python-dev python3-dev
- wget https://github.com/doceme/py-spidev/archive/master.zip
- unzip master.zip
- cd py-spidev-master
- sudo python setup.py install
- sudo python3 setup.py install
- cd Desktop
- mkdir NRF24L01
- cd NRF24L01
- git clone https://github.com/BLavery/lib_nrf24
- cd lib_nrf24/
- cp lib_nrf24.py ~Desktop/NRF24L01
Pi4
- hdmi無法顯示時
- hdmi_drive=2
- hdmi_group=2
- hdimi_mode=42
Arduino to pi
- pi read from Arduino
<python> import RPi.GPIO as GPIO from lib_nrf24 import NRF24 import time import spidev
- This is Pi & read from arduino
GPIO.setmode(GPIO.BCM)
pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE1],[0xF0, 0xF0, 0xF0, 0xF0, 0xE1]]
- initialization
radio = NRF24(GPIO, spidev.SpiDev()) radio.begin(0, 17)
radio.setPayloadSize(32) radio.setChannel(0x76) radio.setDataRate(NRF24.BR_1MBPS) radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True) radio.enableDynamicPayloads() radio.enableAckPayload()
radio.openReadingPipe(1, pipes[1])
- radio.openWritingPipe(pipes[1])
radio.printDetails() radio.startListening()
- message = list(input("Enter a message to send: "))
while True:
while not radio.available(0):
time.sleep(1/100)
receiveMessage = []
radio.read(receiveMessage, radio.getDynamicPayloadSize())
print("received: {}".format(receiveMessage))
print("Translating our received Message into unicode characters...")
string = ""
for n in receiveMessage:
if (n>=32 and n<=126):
string += chr(n)
print("Our received message decodes to: {}".format(string))
</python>