r/Clojure • • May 29 '25

Working towards BCI (Brain-Computer Interface) apps in Clojure!

This post is a follow up to this post from about two months ago.

For those who don’t know me, I’m an aspiring Clojure programmer and brain-computer interface (BCI) enthusiast. I’ve been exploring ways to build novel applications with OpenBCI using Clojure — and I’m especially interested in making it easier for other Clojure developers to get started with this kind of work, even if you’ve never touched neuroscience or hardware before.

I am currently excited to be working on a novel extension to BrainFlow, written in Clojure to make BCI development accessible even to developers who have no prior experience with neuroscience or hardware. By wrapping the BrainFlow logic in idiomatic, high-level Clojure abstractions. The plan is to build a toolkit that allows developers to treat classified "wave-signatures" almost like enums - enabling expressive and composable BCI programming without the traditional complexity.

To demonstrate this , I’m working on a Pong game controlled via live eeg data. While the game and extension aren’t ready for release just yet, I just reached what I think is a somewhat significant milestone: Clojure developers can now install all necessary BrainFlow 5.16.0 components with a single script. This tool automatically installs the full brainflow-jar-with-dependencies.jar as well as all required native libraries into ~/.brainflow-java/5.16.0/. It’s designed to work across Windows, macOS, and Linux — although I’ve only tested it on Windows so far. Linux testing is in progress, and I’d love help from any macOS users willing to test and provide feedback.

Also I am actually rather far in my Clojure API, and would be excited to share it with anyone interested (as a sort of alpha) and even collaborate if anyone wants to help. I recently did a talk for the SciCloj community about BrainFlow that is now up on youtube here: https://www.youtube.com/watch?v=MfA8Tyt7Rgk and I also did a talk at "reClojure" in London just this past Monday - the video for that should be coming out in the coming weeks.

Here is the link to the brainflow downloader for clojure: https://github.com/TheFakeLorLyons/brainflow-java - all you have to do to include it in a clojure project and get started using brainflow with Clojure-Java interop is to include this wrapper as a dependency in a deps.edn file like this:

{:deps
 {com.github.thefakelorlyons/brainflow-java {:mvn/version "1.0.004"}
 :aliases
 {:dev {:jvm-opts ["--add-opens=java.base/java.net=ALL-UNNAMED"]}}}

Just to be clear - this only imports the java code and is not a complete clojure wrapper yet, so to use it in Clojure you still need to rely on (:import [brainflow BoardShim BoardIds BrainFlowInputParams]) and traditional java interop; but when my full API "brainfloj" comes out (hopefully within the next week!) we will all be able to build robust BCI applications in pure Clojure without even worrying about interop.

Let me know if you have any questions/comments/feedback! I'd love to hear from anyone else who might be interested in this. I hope that some of you are as excited about this as I am and I hope to connect if this might be interesting to you.

Also, a shoutout to the amazing sponsors and mentors I have had in this process:

  • ObneyAI
  • Cameron Barre
  • Dustin Getz
  • Amar Mehta
  • Eugene Pakhomov
  • Mark Addleman
  • MTrost
  • Cameron Desautels
  • Justin Tirrell
  • Ian Chow
  • John Tyler
  • Brandon Ridge
  • Private Donor

Community + Inspiration

Other Mentors:

  • Jason Bullers
  • Daniel Slutsky
  • SenLong Yu
  • and many more who have helped guide and support me!

Hopefully I can get the Pong game out soon, and after that..... We'll see ;)

20 Upvotes

3 comments sorted by

View all comments

Show parent comment

2

u/danielneal2 May 29 '25

> I think generating random cacophony would be orders of magnitudes simpler than any kind of controlled musical output;

Ahaha yes - totally get you on the random cacophony, like "this is the sound of an X" kind of articles sometimes contain. Finding some kind of coherent (even if not controlled) musical output would be fascinating to me.

re: The lowest frequency humans can generally hear is20 Hz.

Indeed. At the talk that you are a pianist / guitarist so apologies if any or all of this is old news.

I'm actually really interested in what happens at the far ends when we fall off the audible range.

The brainwave from what I understand is faster than what we might perceive as a rhythm or tempo, but lower than what we would perceive as a note or pitch. That intrigues me. It's in that in-between space. What I know from music is that if you half or double the frequency, you change the octave, but the note stays the same - it has the same kind of qualia - a C# is always a C#. And if you keep halving the pitch at some point it stops being pitch and becomes rhythm - but in some kind of sense, on some level it could be thought of as the same "note".

And then harmonies are related by low number ratios - e.g 3/2 ratio creates a fifth, 5/4 ratio creates a third. So what does e.g. a C# in brainwaves feel like to the person having those brainwaves, and is there any meaningful difference between "notes" within the brainwave couple of octaves (8Hz- 32Hz would be ~ 2 octaves so enough to play a brainwave "tune"), rather than a between the bands. Would be very excited to learn more / play with this.

Thanks for the link to the SciCloj talk - I'll check it out, I have a lot to learn!