可以加裝人體紅外線感測器(PIR),用說的控制開關與電腦(要準備麥克風,這裡使用Logitech, Inc. QuickCam Zoom來測試)
先把UBUNTU MATE 安裝到RASPBERRY PI 3上
安裝好後點選歡迎畫面內的RASPBERRY PI資訊--> 調整檔案系統 , 讓UBUNTU可以使用完整的SD CARD 空間
重新開機後 , 執行 系統--> 管理--> SOFTWARE UPDATER --> 這要跑1,2小時以上,先喝咖啡吧! (更新完成後重新開機)
sudo apt-get install gcin --> 中文輸入法,重新開機後就可以看到
(新注音選詞音/拼音ctrl+alt+6)
開始安裝語音辨識與文字轉語音所需要的套件 python參考網站
sudo apt-get install python-pyaudio python3-pyaudio
sudo apt-get install portaudio19-dev python-all-dev python3-all-dev
sudo pip3 install --upgrade pip (memo: update python3 pip)
sudo pip3 install --upgrade pyaudio
上圖是參考網站內的說明--> 關於安裝pyaudio,這樣才能安裝到正確的pyaudio版本
sudo apt-get install flac
sudo pip3 install speechrecognition
sudo pip3 install gtts
ubuntu mate for raspberry pi 網站
================================================================
================================================================
再來 寫一小段python即可體驗語音辨識
#!/usr/bin/env python3
# NOTE: this example requires PyAudio because it uses the Microphone class
import speech_recognition as sr
import os
from gtts import gTTS
import time
import sys
import RPi.GPIO as GPIO
pin_pir = 18
stb_time = 3
pir_led = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin_pir, GPIO.IN)
GPIO.setup(pir_led, GPIO.OUT)
k=1
c=0
pir=0
def del_temp_mp3file():
try:
os.remove("test.mp3")
print("test.mp3 file deleted.")
except:
print("test.mp3 檔案不存在!")
def txt2speech(m_str):
del_temp_mp3file()
tts = gTTS(text = m_str , lang='zh-tw')
tts.save("test.mp3")
os.system('omxplayer -o local test.mp3')
txt2speech("語音服務已經就緒")
print("speechRecognition alreadt for services...")
r = sr.Recognizer()
r.energy_threshold = 4000
for i in range(0, stb_time):
print ('等候人體紅外線就緒... %d sec\r' % (stb_time - i)),
sys.stdout.flush()
time.sleep(1)
print('人體紅外線已經就緒...\n')
while k>0:
# obtain audio from the microphone
#r = sr.Recognizer()
with sr.Microphone() as source:
print("語音服務聆聽中...")
audio = r.listen(source)
if(GPIO.input(pin_pir)):
GPIO.output(pir_led,True)
print ("偵測到有人 PIR detect...\r"),
sys.stdout.flush()
pir = 1
time.sleep(3)
else:
pir = 0
GPIO.output(pir_led,False)
print ("沒有偵測到人 PIR not detect...\r")
# recognize speech using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
sr_txt = r.recognize_google(audio , language='zh_TW')
#print("語音辨識結果:==> " + r.recognize_google(audio))
if sr_txt == "停止":
txt2speech("停止執行命令")
c=0
if sr_txt == "指令":
txt2speech("請說")
c=1
if sr_txt == "結束程式" and c == 1 and pir == 1:
txt2speech("語音服務已經關閉")
k=0
if sr_txt == "打開開關控制面板" and c == 1 and pir == 1:
os.system('firefox http://192.168.1.252/relay.php')
if sr_txt == "打開風場預報顯示圖" and c == 1 and pir == 1:
os.system('firefox www.cwb.gov.tw/cwbwifi/')
if sr_txt == "連線到樹莓派終端機" and c == 1 and pir ==1:
os.system('mate-terminal -e "ssh pi@192.168.1.252"')
if sr_txt == "樹莓派連線狀況" and c == 1 and pir == 1:
os.system('ping -c 15 192.168.1.252')
if sr_txt == "重新開機" and c == 1 and pir == 1:
os.system('reboot')
if sr_txt == "打開印表機" and c == 1 and pir == 1:
os.system('mate-terminal -e " links http://192.168.1.252/openprt.php"')
time.sleep(10)
os.system('killall -9 links')
if sr_txt == "關掉印表機" and c ==1 and pir == 1:
os.system('mate-terminal -e " links http://192.168.1.252/closeprint.php"')
time.sleep(10)
os.system('killall -9 links')
if sr_txt == "顯示開關狀態" and c==1 and pir==1:
os.system('mate-terminal -e " links http://192.168.1.252/srelay.php"')
time.sleep(10)
os.system('killall -9 links')
print("語音辨識結果:==> " + sr_txt)
#txt2speech(sr_txt)
#os.system('"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" http://192.168.1.252/vcr.php')
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
memo: sudo apt-get install links 文字模式的網頁瀏覽器
Use ubuntu mate 16.04 on raspberry pi 3 輸入此文章 2016-10-04 By Kokomo Lu
2016年10月4日 星期二
2016年4月20日 星期三
Raspberry Pi 2 IR LIRC 紅外線遙控GPIO
參考來源
http://www.jamesrobertson.eu/blog/2013/may/19/installing-lirc-on-raspbian.html
再用C寫一段程式去判斷紅外線接收到什麼訊號!
http://ozzmaker.com/how-to-control-the-gpio-on-a-raspberry-pi-with-an-ir-remote/
裝好LIRC後,使用irw 測試是否可正常接收資料時,可能會發生irw完全接收不到訊號的狀況(開機時執行checkir.sh來修改gpio的in and output function,可解決此狀況)
lircd.conf
sudo killall python : This irread.py will use about 25% cpu ,so 結束這個python task,IR也可以正常使用,ps:可能是測試時安裝多種lirc,lirc_python or gpio的關係?? raspberry pi can not receve IR songal so,不小心測試到這樣的方式...
不重複執行rpi_gpio_lirc , 重複執行會造成繼電器誤動作
若沒有先執行irread.py to initial gpio ,就直接執行rpi_gpio_lirc會造成所有控制中的gpio pin 全部
輸出 '0' 則會使全部的繼電器斷電,所以在執行checkir.sh時,會用sleep 50(50 sec) 來排除繼電器全斷的問題!
http://www.jamesrobertson.eu/blog/2013/may/19/installing-lirc-on-raspbian.html
再用C寫一段程式去判斷紅外線接收到什麼訊號!
http://ozzmaker.com/how-to-control-the-gpio-on-a-raspberry-pi-with-an-ir-remote/
裝好LIRC後,使用irw 測試是否可正常接收資料時,可能會發生irw完全接收不到訊號的狀況(開機時執行checkir.sh來修改gpio的in and output function,可解決此狀況)
再依序輸入正確的namespace 與按鍵配對 lircd.conf 在配對完成後會自動產生
lircd.conf
checkir.sh
sudo killall python : This irread.py will use about 25% cpu ,so 結束這個python task,IR也可以正常使用,ps:可能是測試時安裝多種lirc,lirc_python or gpio的關係?? raspberry pi can not receve IR songal so,不小心測試到這樣的方式...
不重複執行rpi_gpio_lirc , 重複執行會造成繼電器誤動作
若沒有先執行irread.py to initial gpio ,就直接執行rpi_gpio_lirc會造成所有控制中的gpio pin 全部
輸出 '0' 則會使全部的繼電器斷電,所以在執行checkir.sh時,會用sleep 50(50 sec) 來排除繼電器全斷的問題!
irread.py
rpi_gpio_lirc.c
rpi_gpio_lirc.c
2016年4月5日 星期二
VOICE RECOGNITION SOFTWARE FOR RASPBERRY PI
http://diyhacking.com/best-voice-recognition-software-for-raspberry-pi/
http://stevenhickson.blogspot.tw/2013/06/installing-and-updating-piauisuite-and.html
Thank You
Raspberry pi wifi 無線網路自動重新連線
http://alexba.in/blog/2015/01/14/automatically-reconnecting-wifi-on-a-raspberrypi/
Thank You alexba.in
2016年3月23日 星期三
2016年3月22日 星期二
Raspberry pi 用php and python 控制GPIO 並取得GPIO狀態
建立好網頁的部分後,要在 /etc/sudoers 檔案最後加入這行 www-data ALL=(ALL) NOPASSWD: ALL
這樣php才有權限可以執行python like this:
Raspberry pi 2 , php , python , GPIO control and get GPIO status
2016年3月20日 星期日
Raspberry pi 用 python 控制GPIO
Python 2.7.9 (default, Mar 8 2015, 00:52:26)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.setmode(GPIO.BOARD)
>>> GPIO.setup(5,GPIO.OUT)
>>> GPIO.output(5,True)
>>> GPIO.output(5,False)
>>> GPIO.setup(29,GPIO.OUT) # 29 是指GPIO腳位 對應 GPIO5 ;要查看腳位表
__main__:1: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
>>> GPIO.setwarnings(False)
>>> GPIO.setup(29,GPIO.OUT)
>>> GPIO.output(29,False) # 即可控制該腳位ON-OFF
>>> GPIO.output(29,True)
可與BLYNK 同時控制GPIO腳位ON-OFF不會相衝
RASPBERRY 內建 PYTHON 2.7.9 AND GPIO MODEL
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.setmode(GPIO.BOARD)
>>> GPIO.setup(5,GPIO.OUT)
>>> GPIO.output(5,True)
>>> GPIO.output(5,False)
>>> GPIO.setup(29,GPIO.OUT) # 29 是指GPIO腳位 對應 GPIO5 ;要查看腳位表
__main__:1: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
>>> GPIO.setwarnings(False)
>>> GPIO.setup(29,GPIO.OUT)
>>> GPIO.output(29,False) # 即可控制該腳位ON-OFF
>>> GPIO.output(29,True)
可與BLYNK 同時控制GPIO腳位ON-OFF不會相衝
RASPBERRY 內建 PYTHON 2.7.9 AND GPIO MODEL
2016年1月27日 星期三
Raspberry pi GPIO 輸出電壓
Raspberry pi GPIO的輸出電壓只有3V , 不足以推動5v relay
會造成誤動作或是無動作,手邊有之前買的2個7404 IC 把他接上去 ! 就可以提升輸出到4V多,可以正常控制RELAY
會造成誤動作或是無動作,手邊有之前買的2個7404 IC 把他接上去 ! 就可以提升輸出到4V多,可以正常控制RELAY
2016年1月21日 星期四
blynk raspberry pi connect to local server at the same raspberry pi
var blynk = new Blynk.Blynk(AUTH, options = {
connector : new Blynk.TcpClient( options = { addr:"192.168.1.1", port:8442 } )
});
2016年1月10日 星期日
esp8266 韌體更新
http://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=984&extra=&highlight=%C4%C3%B5%BD&page=1
http://dominicm.com/flash-esp8266-wi-fi-module-firmware/
vcc 3.3v 使用arduino 供電進行韌體更新,須注意購買的esp8266版本
用 SSCOM 連線後 下AT COMMAND (AT COMMAND 必須為大寫!)
AT+RST
2nd boot version : 1.2
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size : 4Mbit
jump to run user1
SPI FLASH SIZE : 4Mbit (512K)不可燒錄版本大於1.0的,會有問提!
GPIO15 , GPIO0 接 GND , CH_PD 接 VCC 開啟燒錄程式後, 再接ESP8266電源,再按DOWNLOAD!
更新好韌體後,拔除電源, GPIO0 移除, 重新接電後即下AT COMMAND (SPEED:115200)
AT+GMR
AT version:0.21.0.0
SDK version:0.9.5
OK
不要更改 連線速率,改成9600 ESP8266 就不聽使喚了... (重新燒韌體即可還原)
http://dominicm.com/flash-esp8266-wi-fi-module-firmware/
vcc 3.3v 使用arduino 供電進行韌體更新,須注意購買的esp8266版本
用 SSCOM 連線後 下AT COMMAND (AT COMMAND 必須為大寫!)
AT+RST
2nd boot version : 1.2
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size : 4Mbit
jump to run user1
SPI FLASH SIZE : 4Mbit (512K)不可燒錄版本大於1.0的,會有問提!
GPIO15 , GPIO0 接 GND , CH_PD 接 VCC 開啟燒錄程式後, 再接ESP8266電源,再按DOWNLOAD!
更新好韌體後,拔除電源, GPIO0 移除, 重新接電後即下AT COMMAND (SPEED:115200)
AT+GMR
AT version:0.21.0.0
SDK version:0.9.5
OK
不要更改 連線速率,改成9600 ESP8266 就不聽使喚了... (重新燒韌體即可還原)
2016年1月3日 星期日
blynk arduino record
/**************************************************************
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
*
* This example shows how to use Arduino Ethernet shield (W5100)
* to connect your project to Blynk.
* Feel free to apply it to any other example. It's simple!
*
**************************************************************/
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include
#include
#include
#include
#include
#define dht_dpin 12
dht DHT;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
//Blynk.begin(auth);
// You can also specify server.
// For more options, see BoardsAndShields/Arduino_Ethernet_Manual example
Blynk.begin(auth, "192.168.1.252", 8442);
//Blynk.begin(auth, IPAddress(192,168,1,100), 8888);
//sensors.begin();
timer.setInterval(1000,readTemp);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
}
// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;
}
}
void loop()
{
Blynk.run();
timer.run();
// sensors.requestTemperatures();
// Serial.println(sensors.getTempCByIndex(0));
// delay(2000);
}
void readTemp()
{
// sensors.requestTemperatures();
// float floatTempC = sensors.getTempCByIndex(0);
//Serial.println(floatTempC);
//char t_buffer[15];
//dtostrf(floatTempC,8,9,t_buffer);
DHT.read11(dht_dpin);
Blynk.virtualWrite(0,String(DHT.temperature).substring(0,4)+"℃"); //dht11
Blynk.virtualWrite(1,String(DHT.humidity).substring(0,2)+"%"); //dht11
Blynk.virtualWrite(2,DHT.temperature);
// Blynk.virtualWrite(3,DHT.humidity); //dht11
//Blynk.virtualWrite(6,t_buffer); //ds18b20
//Serial.println (t_buffer);
}
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
*
* This example shows how to use Arduino Ethernet shield (W5100)
* to connect your project to Blynk.
* Feel free to apply it to any other example. It's simple!
*
**************************************************************/
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include
#include
#include
#include
#include
#define dht_dpin 12
dht DHT;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
//Blynk.begin(auth);
// You can also specify server.
// For more options, see BoardsAndShields/Arduino_Ethernet_Manual example
Blynk.begin(auth, "192.168.1.252", 8442);
//Blynk.begin(auth, IPAddress(192,168,1,100), 8888);
//sensors.begin();
timer.setInterval(1000,readTemp);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
}
// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;
}
}
void loop()
{
Blynk.run();
timer.run();
// sensors.requestTemperatures();
// Serial.println(sensors.getTempCByIndex(0));
// delay(2000);
}
void readTemp()
{
// sensors.requestTemperatures();
// float floatTempC = sensors.getTempCByIndex(0);
//Serial.println(floatTempC);
//char t_buffer[15];
//dtostrf(floatTempC,8,9,t_buffer);
DHT.read11(dht_dpin);
Blynk.virtualWrite(0,String(DHT.temperature).substring(0,4)+"℃"); //dht11
Blynk.virtualWrite(1,String(DHT.humidity).substring(0,2)+"%"); //dht11
Blynk.virtualWrite(2,DHT.temperature);
// Blynk.virtualWrite(3,DHT.humidity); //dht11
//Blynk.virtualWrite(6,t_buffer); //ds18b20
//Serial.println (t_buffer);
}
缺少的地方登入後編輯文件, use html 即可看到
訂閱:
文章 (Atom)