neo-matrix-creator-framework
v1.0.2
Published
Neo is a Framework that makes it easy to set up your own Matrix Creator project using Node.js.
Downloads
5
Maintainers
Readme
Neo (Matrix Creator Framework)
Neo is a framework that makes it easy to set up your own Matrix Creator project using Node.js.
You can use this framework to ...
- access the GPIO Pins (Setup and Read Input and Output Pins)
- control the Everloop (Fade and Switch LEDs by using a Light Array)
- read and configure the Humidity, IMU, Uv and Pressure sensors
- stream the microphone input to Google Cloud Speech to get a speech to text result
To use this Framework you need ...
- a Matrix Creator Board
- a Raspberry PI where Node.js is installed.
- to install the Matrix Core Software (you can find a documentation on how to do this here).
Dependencies
- This framework is using ZMQ, make sure you follow the instructions on how to install ZMQ on your computer.
- If you want to use the SpeechToText module you need to have SOX installed. See the node-record-lpcm16 documentation
Installation
Install via npm
npm i neo-matrix-creator-framework
Setting up a config file
To create the config file .neoconfig.json
where all the ports and the IP of the Matrix Creator are stored use following command:
npx neo create-config
This will guide you to the process of creating the config file and saves it to your project folder.
You're now ready to start coding your own project.
Quickstart
To use this package require it at the top of your project file.
const neo = require('neo-matrix-creator-framework');
All single modules you want use need to be initialized:
const everloop = new neo.Everloop();
const gpio = new neo.Gpio();
Optionally you can define custom options. For example the pingInterval:
const gpio = new neo.Gpio({
pingInterval: 1000
});
You can detail information about the available options for each module in the docs folder:
Using the single modules
Every module comes with an integrated event emitter to receive data.
The following example shows how to use the GPIO module to toggle the Everloop LEDs. First you need to define an button. Afterwards you can listen on events emitted by this button. To toggle the Everloop every time you click the button you need to get the state of the LEDs.
// Define pin0 as a button with the name 'light-switch'
gpio.button({
pin: 0,
name: 'light-switch'
});
// listen to events form light-switch
gpio.on('light-switch', state => {
if (everloop.state === 'off') {
// Switch Everloop on
everloop.fadeLight(everloop.generateGradient([
{ red: 0, green: 0, blue: 50, white: 0 },
{ red: 0, green: 50, blue: 10, white: 0 }
]));
} else {
// Switch Everloop off
everloop.fadeLight(everloop.generateDefaultLight(0, 0, 0, 0));
}
});
// listen to errors
gpio.on('error', err {
console.log(err);
});
You can detail information about this in the docs
Multiple config-files on different devices
You might want to run the software on your computer and the Raspberry PI. But every time you want to run the software on the Raspberry Pi you have to change the IP. By using two different .neoconfig.json
files for the Raspberry PI and your computer you don't have to change your code when deploying. The config on the Raspberry PI can hold the local IP (127.0.0.1
) and the config file on your computer stores the IP of the Raspberry PI.
You can do this by running the npx neo create-config
command on both systems and adding the .neoconfig.json
to the gitignore.
Deployment Process
For me the most easy way to deploy my project onto the Raspberry PI is to use GIT. After cloning my project repository to the raspberry PI, I'm able to pull the current version of the software by just using git pull
. Because of the two different config files on the devices I didn't need to make any customizations after pulling the software.
License
The MIT License (MIT) Copyright (c) 2018 Mathis Keller.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.