Following the advice I was given in another post, I have successfully piped Arduino generated data into HiFi JS:
My brainwaves being streamed into HiFi - further work is needed to get cleaner signals, but it works
I thought if might be useful to others if I put up a quick outline of the process. (@LaeMing - this may be useful for your exercise bike / rowing machine project)
Prerequisits
- A connected and functioning Arduino board (see getting started with Arduino)
- A method of producing data from the Arduino board (could be external hardware or a signal generating sketch)
- The Processing 2 software sketchbook application (details here, download here)
- Websocketd (download here)
Once you have connected up your Arduino, configured it to emit data and verified that the data is being posted to the serial monitor display you are ready.
The data path
The basic steps are as follows:- Create a standalone program from your Arduino sketch using Processing 2
- Start websocketd and tell it about your program
- Receive data in a HiFi webwindow via the websocket .onmessage event hander
- Send the data to a regular JS script using EventBridge.emitWebEvent
This data path will get simpler when @thoys websockets for JS files PR goes through, as this will enable websocketd and JS to communicate directly.
Step 1
Once you have finished your Arduino sketch using the regular Arduino IDE, save the .ino file and reopen in Processing 2.
Then, from the Processing 2 -> File menu, select ‘Export application’.
Step 2
Start a websocket from the command line (with a devconsole for text output) passing the name of your new program as a parameter. For me, this was:
websocketd --port=8080 --devconsole BrainGrapher
where BrainGrapher is the name of my exported program. The command window will then display any debug info and errors.
Step 3
Fire up Interface and load a new JS / HTML file pair with a [code]body onload='loaded()'[/code] function and a script section with your loaded() function. Then create a new websocket and event handler: [code] function loaded() { var ws = new WebSocket('ws://dave-pc:8080/'); ws.onmessage = function(event) {
// do something with event.data
}
}
[/code]
This data can then be passed to regular JS in the normal way (sending via EventBridge.emitWebEvent in the html file and receiving via WebWindow.eventBridge.webEventReceived.connect in the JS file)
For reference, here is my HTML / JS file pair:
https://s3-us-west-2.amazonaws.com/davedub/high-fidelity/walkTools/html/walkToolsEEGDisplay.html
https://s3-us-west-2.amazonaws.com/davedub/high-fidelity/walkTools/walkTools/walkToolsEEGDisplay.js
Step 4
Turn everything on and data should start to arrive. Use the data to drive anything you can imagine!
- davedub