Arduino -> HiFi JS data path (Windows only)


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)


  • 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:
  1. Create a standalone program from your Arduino sketch using Processing 2
  2. Start websocketd and tell it about your program
  3. Receive data in a HiFi webwindow via the websocket .onmessage event hander
  4. 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


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:

Step 4

Turn everything on and data should start to arrive. Use the data to drive anything you can imagine!

  • davedub


Oh cool! so WebSockets do work :smiley: Awesome, i have been planing a project to do with them for a while now. More details later.


As more folks flock to HiFi each week, I’m bumping this on principle alone. :smile: There are important key concepts here that go beyond a simple, “well that’s a neat hack” This is one of the core fundamentals High Fidelity allows over other platforms. Open expansion and compatibility from a modular standpoint.

As long as someone can perform the actions needed to make said signals UDP compatible, I think there’s a real chance. :smiley:


@thoys, did this PR finalize?

I decided to point websocketd at Interface and then attempt to SEND from the Console…

var ws = new WebSocket("ws://localhost:8080/");
        ws.onopen = function() {
         ws.send("this_is_a_test");   print("onopen");
        ws.onerror = function(a) {
        ws.onmessage = function(a) {

and this is the result:

So, as far as I can tell, I’m able to run the WebSocket server locally and open it from within and it DOES open, but then it errors out. I was pointing websocketd AT Interface.exe and not pointing it AT a different application.


Hi @AlphaVersionD,

Tell me more about the server you’re trying to connect to. Is is hosted on port 8080 and is it using websockets or (secure-websockets).

The PR is finished a long time ago.

Are you able to run the same code in a webpage? Change the prints to console.log’s ofcourse :smile: