stk500
Version:
Fully javascript stk500v1 programmer. Allows you to program Arduinos straight from node (or browser for that matter). No more avrdude system calls or using the arduino IDE.
52 lines (40 loc) • 1.01 kB
JavaScript
var SerialPort = require("serialport");
var intel_hex = require('intel-hex');
var Stk500 = require('../');
var fs = require('fs');
var data = fs.readFileSync('arduino-1.0.6/uno/StandardFirmata.cpp.hex', { encoding: 'utf8' });
var hex = intel_hex.parse(data).data;
var board = {
name: "Arduino Uno",
baud: 115200,
signature: new Buffer([0x1e, 0x95, 0x0f]),
pageSize: 128,
timeout: 400
};
function upload(path, done){
var serialPort = new SerialPort.SerialPort(path, {
baudrate: board.baud,
});
serialPort.on('open', function(){
Stk500.bootload(serialPort, hex, board, function(error){
serialPort.close(function (error) {
console.log(error);
});
done(error);
});
});
}
if(process && process.argv && process.argv[2])
{
upload(process.argv[2], function(error){
if(!error)
{
console.log("programing SUCCESS!");
process.exit(0);
}
});
}else
{
console.log("call with a path like /dev/tty.something");
process.exit(0);
}