2019年3月27日 星期三

街機製作



為了懷舊,也為了重溫同時畫面簡單但是好玩的街機遊戲,所以構思動手自己做一台

主要零件:

樹莓派 Raspberry 3B+

日本三和搖桿

15" 4:3 1024X768 IPS LCD(故意選4:3螢幕,這樣遊戲才不會被切成黑邊)

15W功率擴大器 + 全音域 SPEAK

框體選用 12mm 的樺木合板

採用CNC加工,配合手工收尾


先來看實際的成品



















後記:
  • 自己動手真的很累,如果可以花錢買一台滿意的我一定直接去買
  • 三和的搖桿跟按鈕,手感真的很棒
  • 覺得這是一項很棒的DIY專案,綜合 Linux / Raspberry / 木工的技能驗收
  • 可以玩20年前遊戲的感覺很棒

2018年4月22日 星期日

居家保全系統

# 目標

  • 每次開關門的事件,都會以 Line 通知,並且用 webcam 拍下當時的照片,傳送到手機上
  • 偵測節點可以擴充
  • 可以像保全系統一樣,開啟保全&解除保全
  • 每次的告警事件,都會存在主機的資料庫上供日後查詢

# DEMO VIDEO

#架構












  • 每個門窗的節點用 nodeMcu(esp8266),使用 Arduino IDE 開發
  • 中控台使用 raspberry pi3,程式以 python3撰寫
  • 中文語音和合成使用 syn7318 晶片
  • Line 的訊息傳遞,使用 IFTTT 的服務
  • python 使用到的重要的模組有 bottle(web框架),pygame , pymysql , pyserial

# 原理

  • 中控台的 raspberry 運行 python 的 bottle web 框架,等於是一台微型的 web server
  • 擔任節點的 nodemcu 偵測到異常事件時,向中控台發出對應的 http request 
  • 中控台收到 nodemcu 的 http request 時,做後續的處理,判斷,拍照,發出警告,發 line ,寫入資料庫

# Python & Arduino Code




2018年4月18日 星期三

(Personal memo notes) using python to implement Chinese speech recognition

let's see the demo first



#Required components

   1. Execute python computer, I use iMac 27, python3 version can support unicode
   2. SYN7318 Chinese Speech Recognition Chip
   3. A piece of Arduino UNO to verify that python can control on/off of GPIO on                 Arduino through firmata protocol

#Architecture principle

    1.  iMac(Python 3) <==> (pySerial) <==> SYN7318
    2.  iMac(Python 3) <==> (firmata)  <==> Arduino



    
    
       
   
    
    
    
    

    
    
    
        
    

2018年4月14日 星期六

(個人備忘筆記) 用 Python 實現透過 Google API 將 Arduino + SHT10 傳回的溫濕度資料 寫到 google sheets

#1. 在 Google Cloud Consel 要啟用 Google Sheet API ,並且將產生的 json 檔案存放到 pythont 程式的相同目錄

#2. 在 Google Sheets的工作表上要新增共享權限到剛剛啟用的 Google Sheet API 的 service account

#3. 安裝 python 的 google-api-python-client 模組
      pip3 install --upgrade google-api-python-client

#4. 安裝 python 的 pygsheets 模組
     pip3 install pygsheets








========= python 端程式 ===========

#coding:utf-8

import serial
import sys
import time
import pygsheets

port = "/dev/tty.usbmodem1421"

serialArduino = serial.Serial(port, 9600)

serialArduino.flushInput()

#google API
gc = pygsheets.authorize(service_file='pythongoogle.json')
sh = gc.open('pythontest')
wks = sh[0]
rowCount = 2



while True:
       
        input = serialArduino.readline()
        temp = str(input[0:5],'utf-8')
        humi = str(input[-7:-2],'utf-8')
        now = time.strftime("%Y/%m/%d %H:%M:%S")
        print(now + ' > ' + 'Temperature: ' + temp + '°C  ,Humidity: ' + humi + '%')
        # proc cells
        try:
            rowCount=int(wks.get_value('A1'))
            if rowCount > 998 :
                print("google sheet row is full , exit the process")
                sys.exit()
         
            wks.update_cell((rowCount,1), now)
            wks.update_cell((rowCount,2), temp)
            wks.update_cell((rowCount,3), humi)
            print("writen " + str(rowCount-2) + " records in sheets")
            rowCount = rowCount + 1
            wks.update_cell((1,1), rowCount)
        except Exception as exec:
            print('update the google sgeet is fail, pls check the networking connect ....')
            sys.exit()

===============================

=============================== Arduino 程式 ===============
#include <SHT1x.h>

// Specify data and clock connections and instantiate SHT1x object
#define dataPin  10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);

void setup()
{
   Serial.begin(9600); // Open serial connection to report values to host
   // Serial.println("Starting up");
}

void loop()
{
  float temp_c;
  float temp_f;
  float humidity;

  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  // Print the values to the serial port
  
  Serial.print(temp_c, DEC);
  Serial.print(",");
  Serial.println(humidity);
  

  delay(300000);
}



2018年2月2日 星期五

中文語音辨識系統

中文語音辨聲控系統

1. 前言

進入Arduino 的領域兩個多月後,終於做出一個像樣的東西來了,就是我一直想要做的"智慧語音聲控系統"。可以用說話控制燈光的開啟,在晚上睡前躺在床上有閱讀習慣的我,是一件很重要的事情。

雖然Apple 的Siri 搭配 HomeKit 也可以達到同樣的效果,但是一來配件價錢貴,二來下命令時還要用iPhone啟動Siri下命令,個人覺得不夠直覺


廢話不多說,先來看Demo




這個Project 使用元件如下:

1.  MCU: NodeMcu-32S
2. 中文語音辨識晶片
3. 溫濕度感應器 DHT11
4. 使用NodeMcu-32S 內建的 RTC 時鐘

2. 原理

語音辨識晶片是靠TTL與MCU通訊,所以基本上只要用RX, TX , GND三隻腳位與 NodeMcu-32S連接即可。每家語音辨識晶片,都有他規定的資料結構,大部分都是16進位資料

下面是通訊的範例




3. Arduino Code










2017年12月31日 星期日

自己的喇叭自己做

一直想要有一台自製的藍芽喇叭,在家搞了一天,終於成功了,效果也非常的棒



所需零件:

(1)藍芽晶片: BK8000L

(2)功率放大器:  Yamaha YDA-138



下面是製作過程,看圖說故事不多說廢話










2017年12月17日 星期日

用ESP8266(ESP-01)上傳溫濕度資料到ThingSpeak

之前有利用Arduino UNO + ESP8266 做過同樣的功能,但其實ESP8266是很強悍的晶片,能完全取代Arduino UNO的功能,小小的一片晶片不但體積縮小,也比較省電,接下來就看圖說故事,不多作解釋

<只需要esp01 就可以運作,不再需要Arduino的板子>


<USB to FTDI只是為了燒錄程式到ESP01, 燒錄成功後可以拆下來,記得燒錄時GPIO 0 必須接到GND>

<在Arduino IDE ,開發板記得選ESP8266,序列阜也要選FTDI的那個 port>



<都沒問題的話,從 ThingSpeak就可以看到上傳的資料>

Assembly List

LabelPart TypeProperties
DHT1DHT11 Humitidy and Temperature Sensor
LED1Red (633nm) LED套件 1206 [SMD]; 顏色 Red (633nm)
R1220Ω Resistor接腳間隔 400 mil; 套件 THT; bands 4; tolerance ±5%; 電阻 220Ω
U1ESP8266 WiFi Modulevariant variant 1; part number ESP8266
元件1FTDI Basic Programmer類型 Basic; 電壓 5V


程式碼

#include "ESP8266WiFi.h"
#include <dht11.h>
dht11 DHT11;
#define LED 0 


const char* ssid = "ssid";
const char* password = "wifipassword";
const byte dataPin = 2;
const char* host = "api.thingspeak.com";


void setup() {
  // put your setup code here, to run once:
  pinMode(0,OUTPUT);
  Serial.begin(115200);
  
  WiFi.begin(ssid,password);
  
  while (WiFi.status() != WL_CONNECTED) {
    
    delay(500);
    Serial.print(".");
  }

  digitalWrite(LED,HIGH);
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println(WiFi.localIP());
 

}

void loop() {
  int chk = DHT11.read(dataPin);
  
  // put your main code here, to run repeatedly:
  Serial.print("Connecting to  " );
  Serial.println(host);
  // usage WiFiClient
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection fialed");
    return;
  }
  client.print(String("GET /") + "update?api_key=thingspeakapikey=" + String(DHT11.temperature) + "&field2=" + String(DHT11.humidity) + "\r\n\r\n");
  Serial.println("溫度:"+String(DHT11.temperature)+" ===  "+"濕度: "+String(DHT11.humidity));
  
  
  delay(100);
  while (client.available()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
    for (int i=1 ; i<12; i++) {
      digitalWrite(LED,HIGH);
      delay(300);
      digitalWrite(LED,LOW);
      delay(300);
      digitalWrite(LED,HIGH);
    }
  }
  Serial.println();
  Serial.println("closing connection");
  delay(300000);
}