Skip to content

Instantly share code, notes, and snippets.

@daniellevass
Last active July 29, 2016 22:40
Show Gist options
  • Save daniellevass/a03b0d262261acc6562be67f3a99f1a1 to your computer and use it in GitHub Desktop.
Save daniellevass/a03b0d262261acc6562be67f3a99f1a1 to your computer and use it in GitHub Desktop.

#Punch through bean info

  1. download the arduino program to write arduino code - https://www.arduino.cc/en/Main/Software

  2. download whichever bits on here you need https://punchthrough.com/bean/guides/everything-else/downloads/

  3. I had problem trying to get the serial port to read correctly, can’t remember which magical incantation i had to do, but it was on the punchthrough forums, i can go back and look if you need it.

http://beantalk.punchthrough.com/t/heres-how-to-access-bean-serial-data-in-processing/751 this may have been it, but i'm pretty sure the npm package below fixed it too, might be useful if the npm package doesn't work.

  1. Arduino Script - you need to make sure the board is setup to be a LightBlue Bean

Info on how to get all the values etc are from here - https://punchthrough.com/bean/guides/features/temperature/


void setup() {
Serial.begin(9600); // initialize serial
}

void loop() {
    float currTemp = Bean.getTemperature();
    Serial.println(currTemp);
    Bean.sleep(10000);
}
  1. NodeJS Script (need to install moment + serialport)
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var fs = require('fs');
var moment = require('moment');


var port = new SerialPort('/dev/tty.LightBlue-Bean', {
  baudrate: 9600,
  parser: serialport.parsers.readline('\r\n')
});

port.on('open', function () {
    console.log('open!');
});

port.on('error', function (err) {
    console.log('error ' + err);
});


port.on('data', function (data) {
  console.log('Data: ' + data);
  var output = "" + moment().toISOString() + "," + data + "\n";
  var fileName = moment().format('dddd-DD-MMM');
  var filePath = fileName + ".csv" ;

  fs.appendFile(filePath, output, function(err) {
      if(err) {
          return console.log(err);
      }
  });

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment