littlebits-arduino

control LittleBits Arduino module with Firmata protocol

Usage no npm install needed!

<script type="module">
  import littlebitsArduino from 'https://cdn.skypack.dev/littlebits-arduino';
</script>

README

littlebits-arduino

control LittleBits Arduino module with Firmata protocol. Extended arduino-firmata.

Install

% npm install littlebits-arduino

Requirements

  • LittleBits Arduino module
  • Install Standard Firmata
    • Arduino IDE -> [File] -> [Examples] -> [Firmata] -> [StandardFirmata]
    • set board-type Arduino Leonardo

Usage

littlebits

Setup

Connect, Read and Write

var LittleBitsArduino = require('littlebits-arduino');

var arduino = new LittleBitsArduino();
arduino.connect(); // use default Arduino
// arduino.connect('/dev/tty.usb-device-name');

arduino.on('connect', function(){
  setInterval(function(){
    var d0 = arduino.d0; // true or false
    var a0 = arduino.a0; // 0~1023 analog input
    var a1 = arduino.a1; // 0~1023 analog input

    console.log([d0, a0, a1]);

    arduino.d1 = d0;   // digital output
    arduino.d5 = a0/4; // 0~255 analog output
    arduino.d9 = a1/4; // 0~255 analog output
  }, 100);
});

Reset

arduino.reset(callback);

Close

arduino.close(callback);

Also digitalRead, analogRead, sysex and on "analogChange", on "digitalChange" are available.

Test

% npm install
% npm test