Skip to content

Commit e18de72

Browse files
author
Shishir Ramam
committed
open sourcing the dadaconf code
1 parent d46e166 commit e18de72

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

Readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# brainy
2+
A simple node server that interfaces the [muse](http://www.choosemuse.com/) brain sensing band to an [arduino](https://www.arduino.cc/) board.
3+
4+
Built as part of [dadaconf 0](http://dadaconf.com/)
5+
6+
Things external to this package.
7+
1. Connecting node to an arduino board.
8+
2. Install the muse [developer kit](http://www.choosemuse.com/developer-kit/)
9+
10+
11+
# How it works
12+
- The muse connects over bluetooth with it's driver.
13+
- The driver then transmits signals using [OSC] (http://opensoundcontrol.org/introduction-osc)
14+
- It needs to be configured to talk to our node.js server (configure the UDP port))
15+
- Adjust any arduino ports you might want to interface to.
16+
- Depending on what you are controlling, may you have happy endings!
17+

index.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
var osc = require("osc");
2+
var ArduinoFirmata = require('arduino-firmata');
3+
var arduino = new ArduinoFirmata();
4+
5+
arduino.connect(); // use default arduino
6+
arduino.connect('/dev/cu.usbserial-A403IN4Y');
7+
8+
9+
// Create an osc.js UDP Port listening on port 57121.
10+
var udpPort = new osc.UDPPort({
11+
localAddress: "0.0.0.0",
12+
localPort: 5013
13+
});
14+
15+
var map = {
16+
alpha: 9,
17+
beta: 10,
18+
theta: 11,
19+
delta: 12,
20+
gamma: 13
21+
}
22+
23+
24+
var avgs = {
25+
alpha: 0,
26+
beta: 0,
27+
theta: 0,
28+
delta: 0,
29+
gamma: 0
30+
};
31+
32+
33+
var analog_limit = 11;
34+
var turnOn = function(band, val) {
35+
36+
var motor_scale = 2;
37+
var led_scale = 4;
38+
var ch = map[band];
39+
var avg = (val[1] + val[2])/2;
40+
if(!avg) {
41+
avg = 0;
42+
}
43+
avgs[ch] = avg;
44+
var motor_intensity = parseInt(avg * motor_scale * 255);
45+
var led_intensity = parseInt(avg * led_scale * 255);
46+
avgs['led_intensity'] = led_intensity;
47+
console.log(JSON.stringify(avgs));
48+
if (ch <= analog_limit) {
49+
arduino.analogWrite(ch, motor_intensity, function() {
50+
console.log('pin ' + ch + ' turned on ' + motor_intensity);
51+
});
52+
} else {
53+
if (motor_intensity === 0) {
54+
arduino.digitalWrite(ch, false, function() {
55+
console.log('pin ' + ch + ' turned on');
56+
});
57+
} else {
58+
arduino.digitalWrite(ch, true, function() {
59+
console.log('pin ' + ch + ' turned on');
60+
});
61+
}
62+
}
63+
var led_on = 128 < led_intensity;
64+
arduino.digitalWrite(ch-7, led_on, function() {
65+
console.log('pin ' + ch-7 + ' turned on');
66+
});
67+
}
68+
69+
// Listen for incoming OSC bundles.
70+
udpPort.on("message", function (oscBundle) {
71+
switch(oscBundle.address) {
72+
case '/muse/elements/alpha_relative': {
73+
turnOn('alpha', oscBundle.args);
74+
break;
75+
}
76+
case '/muse/elements/beta_relative': {
77+
turnOn('beta', oscBundle.args);
78+
break;
79+
}
80+
case '/muse/elements/theta_relative': {
81+
turnOn('theta', oscBundle.args);
82+
break;
83+
}
84+
case '/muse/elements/delta_relative': {
85+
turnOn('delta', oscBundle.args);
86+
break;
87+
}
88+
case '/muse/elements/gamma_relative': {
89+
turnOn('gamma', oscBundle.args);
90+
break;
91+
}
92+
}
93+
});
94+
95+
96+
// Open the socket.
97+
udpPort.open();

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "brainy",
3+
"version": "1.0.0",
4+
"description": "A node module to interface the muse to a arduino",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Shishir Ramam",
10+
"license": "Apache 2",
11+
"dependencies": {
12+
"arduino-firmata": "^0.3.2",
13+
"osc": "^1.1.2"
14+
}
15+
}

0 commit comments

Comments
 (0)