Skip to content

Instantly share code, notes, and snippets.

@pofat
Last active April 20, 2016 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pofat/a306894c35f36ab7c1cd252914802a96 to your computer and use it in GitHub Desktop.
Save pofat/a306894c35f36ab7c1cd252914802a96 to your computer and use it in GitHub Desktop.
整合Firmata 與Express,供NDHU network lab 8 的教學說明 (2016.4.20.)

在Express中整合Firmata與socketIO

  1. 用Express生成一個新專案
  2. 整合socket.io 與UI(參考這裡)
  3. 安裝firmata npm install firmata --save
  4. 在project根目錄下,新增一檔案 firmataConnector.js
  5. 在 bin/www 裡使用 firmataConnector 與連接
/* Firmata */
var serialPort = 'YOUR_SERIAL_PORT';
var arduino = require('../firmataConnector')(serialPort);
  1. 監聽 connection 事件以確定arudino連線成功
// Arduino connected
arduino.on('connection', function() {
  debug('arduino connected');
  // do something 
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment