檢視 樹莓派用於裁線 的原始碼
←
樹莓派用於裁線
跳至導覽
跳至搜尋
由於以下原因,您無權編輯此頁面:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
==安裝樹派== #下載[https://www.raspberrypi.org/downloads/raspbian/ Raspbian Buster Lite] #下載[https://www.balena.io/etcher/ 克隆軟體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模組 ###[http://invent.module143.com/daskal_tutorial/raspberry-pi-3-wireless-pi-to-pi-python-communication-with-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 ##[https://www.youtube.com/watch?v=_68f-yp63ds 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 #將內存mount to RAMDISK ##mkdir /tmp/ramdisk ##chmod 777 /tmp/ramdisk ##mount -t tmpfs -o size=16M tmpfs /tmp/ramdisk/ ==python TTS== *[http://yhhuang1966.blogspot.com/2017/08/google-gtts-api.html 利用 Google gTTS 文字轉語音 API 讓電腦說話] *pip3 install gTTS <python> from gtts import gTTS tts=gTTS(text='生日快樂', lang='zh-tw') tts.save("\tmp\ramdisk\happybirthday.mp3") </python> *pip3 install pygame *sudo apt-get install libsdl1.2-dev *sudo apt-get install libsdl-mixer1.2 <python> from pygame import mixer mixer.init() mixer.music.load('\tmp\ramdisk\happybirthday.mp3') mixer.music.play() </python> *判斷是否下載TTS與播放 <python> from gtts import gTTS from pygame import mixer import os mixer.init() while True: msg=input("Input a string or a value:") mp3="c:\\python\mp3\\" + msg + ".mp3" if not os.path.isfile(mp3): tts=gTTS(text=msg, lang='zh-tw') tts.save(mp3) mixer.music.load(mp3) mixer.music.play() </python> ==WS2812B LED燈條== *[https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage Python Installation of NeoPixel Library] **sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel **sudo python3 -m pip install --force-reinstall adafruit-blinka **python <python> import board import neopixel pixels = neopixel.NeoPixel(board.D18, 30) pixels[0] = (255, 0, 0) </python> ==Arduino Send to Pi== *Arduino Send to Pi <c> #include <SPI.h> #include <RF24.h> #include <printf.h> RF24 rf24(A0, A1); // CE腳, CSN腳 //Arduino Send to PI const uint64_t addr = 0xF0F0F0F0E1LL; int i=0; void setup() { Serial.begin(9600); printf_begin(); rf24.begin(); rf24.setChannel(0x76); // 設定頻道編號 rf24.openWritingPipe(addr); // 設定通道位址 rf24.setPALevel(RF24_PA_MAX); // 設定廣播功率 rf24.setDataRate(RF24_1MBPS); // 設定傳輸速率 rf24.enableDynamicPayloads(); rf24.powerUp(); rf24.stopListening(); // 停止偵聽;設定成發射模式 rf24.printDetails(); } void loop(void) { const char text[] = "Hello World!"; rf24.write(&text, sizeof(text)); delay(1000); } </c> *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> ==Pi SENT TO Arduino不確認== *Pi <python> import RPi.GPIO as GPIO from lib_nrf24 import NRF24 import time import spidev #This is Pi : read & send to arduino GPIO.setmode(GPIO.BCM) pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE2],[0xF0, 0xF0, 0xF0, 0xF0, 0xE2]] # initialization radio = NRF24(GPIO, spidev.SpiDev()) radio.begin(0, 17) radio.setPayloadSize(32) radio.setChannel(0x72) radio.setDataRate(NRF24.BR_1MBPS) radio.setPALevel(NRF24.PA_MAX) radio.setAutoAck(True) radio.enableDynamicPayloads() radio.enableAckPayload() radio.openWritingPipe(pipes[0]) radio.openReadingPipe(1,pipes[1]); radio.stopListening() radio.printDetails() while True: message = list(input("Enter a message to send: ")) while len(message) < 32: message.append(0) radio.write(message) </python> *Arduino <c> #include <SPI.h> #include <RF24.h> #include <printf.h> RF24 rf24(A0, A1); // CE腳, CSN腳 //Arduino Send to PI const uint64_t addr = 0xF0F0F0F0E2LL; const uint64_t pipe = 0xE8E8F0F0E2LL; int i=0; void setup() { Serial.begin(9600); printf_begin(); rf24.begin(); rf24.setPALevel(RF24_PA_MAX); // 設定廣播功率 rf24.setChannel(0x72); // 設定頻道編號 rf24.setDataRate(RF24_1MBPS); // 設定傳輸速率 rf24.openWritingPipe(addr); // 設定通道位址 rf24.openReadingPipe(1,pipe); rf24.enableDynamicPayloads(); rf24.powerUp(); rf24.startListening(); rf24.printDetails(); } void loop(void) { if(rf24.available()){ char msg[32] = ""; rf24.read(msg, sizeof(msg)); Serial.println(msg); // 顯示訊息內容 } } </c>
返回到「
樹莓派用於裁線
」。
導覽選單
個人工具
建立帳號
登入
命名空間
頁面
討論
臺灣正體
視圖
閱讀
檢視原始碼
檢視歷史
更多
搜尋
導覽
首頁
近期變更
隨機頁面
MediaWiki說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊