Coder Social home page Coder Social logo

hx-node-bbc-microbit's Introduction

hx-node-bbc-microbit

Control a BBC micro:bit from Node.js using BLE and Haxe

These are the Haxe node.js externs from https://github.com/sandeepmistry/node-bbc-microbit and follows the api

The Micro Bit (also referred to as BBC Micro Bit, stylised as micro:bit) is an ARM-based embedded system designed by the BBC for use in computer education in the UK.

The board is 4 cm ร— 5 cm and has an ARM Cortex-M0 processor, accelerometer and magnetometer sensors, Bluetooth and USB connectivity, a display consisting of 25 LEDs, two programmable buttons, and can be powered by either USB or an external battery pack.[2] The device inputs and outputs are through five ring connectors that are part of the 23-pin edge connector.

wikipedia

Haxe?

Read more about Haxe

Installation Haxe/NPM

Make sure to follow the instructions for noble too.

2. install dependencies with npm

npm install

3. install haxelib

haxelib git bbc-microbit https://github.com/MatthijsKamstra/hx-node-bbc-microbit

Haxelib

use this repo locally

haxelib dev bbc-microbit path/to/folder/src

or this git repo

haxelib git bbc-microbit https://github.com/MatthijsKamstra/hx-node-bbc-microbit

don't forget to add it to your build file

-lib bbc-microbit

Visual Studio Code

I would suggest to us Visual Studio Code, it's a very nice editor and lets you set breakpoints in your js file

But other code-editors may work as well!

Haxe niceties

create a (LED)pattern from an array

var X = [
	1, 0, 0, 0, 1,
	0, 1, 0, 1, 0,
	0, 0, 1, 0, 0,
	0, 1, 0, 1, 0,
	1, 0, 0, 0, 1,
];
var buffer = new Buffer(new Pattern().createLedMatrixBuffer(X));

// follow example "LedPatternHx"
// or use a default Pattern
var buffer = new Buffer(new Pattern().createLedMatrixBuffer(Pattern.HEART));

Use string to listen to or EventName

import BBCMicrobit;

// strings will work
microbit.on('buttonAChange', function(value) {
	console.log('\ton -> button A change');
});

// prevent spelling mistakes with EventName
microbit.on(EventName.BUTTON_A_CHANGE, function(value) {
	console.log('\ton -> button A change');
});

Use the fixed values for AccelerometerPeriod Period

import BBCMicrobit;

// numbers will work
microbit.writeAccelerometerPeriod(160, function(err) {
	console.log('\taccelerometer period set');
});

// prevent using wrong value use Period
microbit.writeAccelerometerPeriod(Period.NR_160, function(err) {
	console.log('\taccelerometer period set');
});

Difference

  • UART doesn't work: check api
  • Light sensor doesn't work: it works with a trick read more but with this node.js code unable to access.
  • The code is not written on the micro:bit, remove power (switch off) and the code is gone
  • EventListeners examples doesn't work: the code is not uploaded to NPM yet (but if you want to use it read this)

Fix EventListener

After installing the dependencies via npm install.
You need to update the node_modules/bbc-microbit folder with two files:

And that will make that work.

I have created an issue "microbit.subscribeEvents" but it's not fixed yet.

Examples

most examples from https://github.com/sandeepmistry/node-bbc-microbit are "redone" in Haxe

Blink

Source

hx-node-bbc-microbit's People

Contributors

matthijskamstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.