Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d453fe5
Basic implementation of BasicMotor types
Dec 6, 2019
4af1d3d
Added autosubscribe when adding eventlisteners
Dec 7, 2019
8ffc60b
attachedDevices now a map
Dec 7, 2019
93a1369
Basic code for passing messages through to the device
Dec 9, 2019
d382c3d
Basic ColorDistanceSensor and TachoMotor handling
Dec 9, 2019
a02249f
Implemented basic lights, device busy-ness
Dec 9, 2019
f9cea9a
Yay, port object is no longer a thing
Dec 9, 2019
7fdc754
Start of hub refactor
Dec 9, 2019
5c03e5c
More refactoring
Dec 9, 2019
1793eb0
Removing commented code
Dec 9, 2019
6beeda5
Implemented methods for retrieving hubs and devices
Dec 11, 2019
6a7c489
Added more motor types
nathankellenicki Dec 15, 2019
198d637
Renamed devices
nathankellenicki Dec 16, 2019
81cbdac
Merge branch 'feature/devices' of github.com:nathankellenicki/node-po…
Dec 16, 2019
31ac932
Motion and tilt sensor
Dec 16, 2019
2a67242
Removed some commented code from hubs
Dec 16, 2019
023b141
Better handling of device initialisation, implemented more modes
Dec 17, 2019
37be7f8
Rename
Dec 17, 2019
406e9e9
Rename again
Dec 17, 2019
225f331
Better directory structure
Dec 17, 2019
df70d8a
Renamed devices
nathankellenicki Dec 17, 2019
04b79ad
Renamed devices
nathankellenicki Dec 17, 2019
388bce1
Mapping of events to modes
Dec 17, 2019
36c34a9
Exported device ModeMap
Dec 17, 2019
ffd3cce
Exported hub PortMap
Dec 17, 2019
364089b
Power to speed when rotating by angle
Dec 18, 2019
de4feb0
Added functions to wait for port attachments
Dec 18, 2019
c1b8697
VoltageSensor
Dec 18, 2019
2e06a17
CurrentSensor
Dec 18, 2019
6d23179
PUPRemoteButton
Dec 18, 2019
195c0d5
HubLED and MoveHubTiltSensor
Dec 18, 2019
6e77d69
Control+ (Technic Medium Hub) sensors
Dec 19, 2019
a5a9b2e
Control+ (Technic Medium Hub) devices, renamed hubs to be more inline…
Dec 19, 2019
705fbd3
writeDirect function on device
Dec 19, 2019
bc644c8
Duplo motors and sensors
Dec 19, 2019
0350176
Bug fixes, hubs now wait for hub properties before being connected
Dec 19, 2019
2dabedd
More WeDo 2.0 devices
Dec 20, 2019
579f823
Device events now emit on hub too
nathankellenicki Dec 23, 2019
9113d22
Named internal ports on hubs
nathankellenicki Dec 23, 2019
c5146bd
Renamed button to remoteButton on RC
nathankellenicki Dec 24, 2019
290f469
Device events emit value objects
nathankellenicki Dec 27, 2019
077a737
WeDo 2.0 unsubscribing
Jan 6, 2020
9f087e3
Merge branch 'feature/devices' of github.com:nathankellenicki/node-po…
nathankellenicki Jan 7, 2020
673f5ff
Start of port combining
Jan 8, 2020
afa7c74
Merge branch 'feature/devices' of github.com:nathankellenicki/node-po…
Jan 8, 2020
875293a
Fixed linting errors and removed namespaces
Jan 8, 2020
bf721ed
Virtual port attachment and detachment
Jan 8, 2020
b43b59e
Virtual ports tested
Jan 9, 2020
f7e86d3
Added setSpeed, virtual port multiparam options
Jan 9, 2020
74be8a7
Initial absolute motor support
Jan 10, 2020
56eaa7c
Fixed parts of absolute angle
nathankellenicki Jan 10, 2020
63f1c10
Servo calibration and reset
Jan 10, 2020
5fde49c
Adding power and brightness ramping back in
Jan 13, 2020
ea20b1b
Can not retrieve human readable device type from devices. Updated web…
Jan 13, 2020
dfd22b1
Can not retrieve human readable device type from devices. Updated web…
Jan 13, 2020
0c3ff8b
Devices now cache notified values for easy retrieval without events
Jan 13, 2020
225b60f
Devices now cache notified values for easy retrieval without events
Jan 13, 2020
d329ce6
Added support for Spike Prime motors
Jan 13, 2020
ef31567
Added support for Technic Color Sensor and Technic Distance Sensor (S…
Jan 15, 2020
407acce
Added Technic Force Sensor (Spike Prime)
Jan 15, 2020
c6f8015
Added example of slow speed train control with a Medium Linear Motor …
Jan 29, 2020
e34eea9
Removed examples with old API
Jan 29, 2020
c0009f8
Updated vernie sample, added braking style
Feb 7, 2020
e721e0f
Updated docs, readme, version
nathankellenicki Feb 10, 2020
a34c422
Added announement to readme
nathankellenicki Feb 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@

# **node-poweredup** - A Javascript module to interface with LEGO Powered Up components.

### Announcements

*Important*: v6.0.0 is a complete re-architecting of this library. Improvements include proper device and mode support through an external Device object, correct handling of firmware features, and promise-based functionality for interfacing with device attachments. Although many new features were added, existing code will almost surely break upon upgrade.

### Introduction

LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO WeDo 2.0 released in 2016, LEGO Boost released in 2017, LEGO Powered Up released in 2018, and LEGO Technic CONTROL+ released in 2019. It also includes the 2018 Duplo App-Controlled Train sets.
LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges - starting with LEGO Education WeDo 2.0 released in 2016, LEGO Boost released in 2017, LEGO Powered Up released in 2018, LEGO Technic CONTROL+ released in 2019, and LEGO Education SPIKE Prime released in 2020. It also includes the 2018 Duplo App-Controlled Train sets.

This library allows communication and control of Powered Up devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth.

### Node.js Installation

Node.js v8.0 required.
Node.js v8.0+ required.

```javascript
npm install node-poweredup --save
```

node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are [certain dependencies which may need installed first](https://github.com/noble/noble#prerequisites).

Note: node-poweredup has been tested on macOS 10.13 and Debian/Raspbian on the Raspberry Pi 3 Model B.
Note: node-poweredup has been tested on macOS 10.15 and Debian/Raspbian on the Raspberry Pi 3 Model B.

### Compatibility

Expand All @@ -36,6 +40,12 @@ While most Powered Up components and Hubs are compatible with each other, there
| Powered Up LED Lights | <a href="https://brickset.com/sets/88005-1/">88005</a> | Light | Yes | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
| Control+ Large Motor | 22169 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
| Control+ XLarge Motor | 22172 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
| SPIKE Prime Medium Motor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Large Motor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Color Sensor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Distance Sensor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Force Sensor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |


In addition, the Hubs themselves have certain built-in features which this library exposes.

Expand All @@ -56,6 +66,8 @@ In addition, the Hubs themselves have certain built-in features which this libra

* When used with the Boost Move Hub, the Control+ Motors do not currently accept commands.

* The SPIKE Prime Hub does not use Bluetooth Low Energy, so is not supported via this library. It is recommended you use MicroPython and Bluetooth Classic to develop for this Hub.

### Documentation

[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
Expand All @@ -69,17 +81,22 @@ const poweredUP = new PoweredUP.PoweredUP();
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
console.log(`Discovered ${hub.name}!`);
await hub.connect(); // Connect to the Hub
const motorA = hub.waitForDeviceAtPort("A"); // Make sure a motor is plugged into port A
const motorB = hub.waitForDeviceAtPort("B"); // Make sure a motor is plugged into port B
console.log("Connected");
await hub.sleep(3000); // Sleep for 3 seconds before starting

while (true) { // Repeat indefinitely
console.log("Running motor B at speed 75");
hub.setMotorSpeed("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
motorB.setPower("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
console.log("Running motor A at speed 100 for 2 seconds");
await hub.setMotorSpeed("A", 100, 2000); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
motorA.setPower("A", 100); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
await hub.sleep(2000);
motorA.setPower("A", 0);
await hub.sleep(1000); // Do nothing for 1 second
console.log("Running motor A at speed -50 for 1 seconds");
await hub.setMotorSpeed("A", -50, 1000); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop
console.log("Running motor A at speed -50 for 1 second");
motorA.setPower("A", -50); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop
hub.sleep(1000);
motorA.setPower("A", 0);
await hub.sleep(1000); // Do nothing for 1 second
}
});
Expand Down
Loading