Twitterと連携するコーヒーメーカーを作った
オンラインコーヒーメーカー「萌香たん」とはじめるドキドキ☆コーヒーブレイク - mixi Engineers' Blog
ぶっちゃけこれのパクリ
結果
@palon_m コーヒー淹れるねお兄様! (15:55:45)
— コーヒーを淹れてくれるフランちゃんbot (@flandre_coffee) 2015, 2月 25
@palon_m お兄様ー、コーヒーできたよ! (16:07:48)
— コーヒーを淹れてくれるフランちゃんbot (@flandre_coffee) 2015, 2月 25
フランちゃんかわいい
使ったもの
- Raspberry Pi Model B
- Arduino Uno
- 秋月で売ってるフォトトランジスタ
- ビニールテープ(黒)
仕組み
- コーヒーメーカーの表示ランプをフォトトランジスタで読み取る。
- Arduinoに入力して一定値を超えた時点でBLEND、下回った時点でDONEのシリアル信号を出力する。
- Raspberry Piがそれを受信してTwitterにポストする。
作り方
[5V] - [抵抗] - [フォトトランジスタ] - [GND]
|_ [ANALOG 0]
- フォトトランジスタに適当に抵抗付けて分圧させとく (10kΩくらい?)
- Arduinoのアナログ0番ピンに分圧した線を刺す
- フォトトランジスタをコーヒーメーカーのランプに黒いビニールテープでくっつける
- Arduinoにスケッチを書き込む
- ArduinoとRaspberryPiをUSBでつなぐ
- RaspberryPiでrubyスクリプトを回す
使ったコード
coffee.rb
require "serialport" require "twitter" client = Twitter::REST::Client.new do |config| config.consumer_key = "" config.consumer_secret = "" config.access_token = "" config.access_token_secret = "" end now = Time.now.strftime("(%H:%M:%S)") client.update("起動しました " + now) sp = SerialPort.new('/dev/ttyACM0', 9600, 8, 1, 0) sleep 3 loop{ line = sp.gets # read now = Time.now.strftime("(%H:%M:%S)") if line.index("BLEND") client.update("@palon_m コーヒー淹れるねお兄様! " + now) elsif line.index("DONE") client.update("@palon_m お兄様ー、コーヒーできたよ! " + now) end }
coffee.ino
boolean blending = 0; int thres = 5; int count = 0; void setup() { Serial.begin(9800); pinMode(13, OUTPUT); digitalWrite(13, LOW); } void loop() { int cds = analogRead(0); if (cds > 50 && !blending){ count++; } else if (cds <= 50 && blending){ count++; } else if (count > 0) { count--; } if (count > thres){ blending = !blending; if (blending){ Serial.println("BLEND"); digitalWrite(13, HIGH); } else { Serial.println("DONE"); digitalWrite(13, LOW); } count = 0; } delay(50); }
詳細
あとで書く。