• Log in with Facebook Log in with Twitter Log In with Google      Sign In    
  • Create Account
  LongeCity
              Advocacy & Research for Unlimited Lifespans

Photo
* * * * * 3 votes

DIY Low-Cost HEG neurofeedback

heg diy pre-frontal autism

  • Please log in to reply
23 replies to this topic

#1 thebrainstore

  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 08 January 2016 - 05:21 PM


Hi all.

 

I recently had the loan of  HEG system and it's expense versus complexity struck me as downright appalling. It is quite simple to build such a thing for people to DIY at low cost.

 

For those of you who don't know, Haemoencephaolography (HEG) is a technique where blood flow on the forehead is measured, and turned into a performance score. Those with low performance in this test are likely to have poor executive function, due to blood flow issues on the scalp. Executive function is the power you have to control your life, and comes from the prefrontal cortex. If we do not have use of this, our default nature is anxious, inflexible, basically pure fear.

 

However, the technology is very simple. It is an infra-red temperature sensor connected to an analog-digital converter that reads the temperature and outputs it over a serial port. A piece of software then tracks this temperature, and calculates positive rate of change i.e. the rate upward variation in temperature. 

 

This score of upward variation rate can be directly applied to a source of audio/video feedback. The user then gets informed of how much blood is flowing through the forehead by the starting and stopping of the media.

 

Over time the brain learns that in order to hear the sound or watch the video it has to increase blood flow. The result of this is reactivation of the prefrontal cortex, problems with which are associated with a raft of health issues from PTSD to ADHD.

 

An MLX90614 température sensor connects to an Arduino via the SMBUS. The Arduino will calculate the rate of change and forward the value to the serial port which can be picked up on a computer through the USB port. From there a simple app in Processing or Max/MSP could generate feedback relative to the control signal. There are software libraries to make most of this a breeze.

 

The most elegant solution would be to run this on a raspberry pi zero and connect it directly to a TV. 

 

The hardware cost is sub $20. Is anyone on here interested in getting involved, or shall I just get on with it and present it when it's done?


Edited by spektrolyte, 08 January 2016 - 05:57 PM.

  • Enjoying the show x 1
  • Good Point x 1
  • Informative x 1

#2 Gerald Dwelle

  • Guest
  • 1 posts
  • 0

Posted 08 January 2016 - 05:52 PM

I am interested. I had a frontal lobe head injury in my youth and would love a low cost treatment option.



sponsored ad

  • Advert
Click HERE to rent this advertising spot for BRAIN HEALTH to support LongeCity (this will replace the google ad above).

#3 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 08 January 2016 - 05:58 PM

Cool :) How can you help?

 

Also have you looked at CES (tDCS)? It can also help to give relief by causing those tense muscles on the scalp to loosen. Might even be better for you considering you had executive function to begin with. I didn't have any, so HEG is more a tool for me to learn what I never did as a child.



#4 middpanther88

  • Guest
  • 185 posts
  • -4

Posted 08 January 2016 - 07:30 PM

Interested to see how you could make it.



#5 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 24 January 2016 - 06:31 PM

Here's how:

 

Use an Arduino board with an I2C temperature sensor positioned on the forehead to detect blood flow.

 

Arduino code calculates the rate of positive temperature change and sends it down a serial port to a computer as a positive integer.

 

A simple app built in Processing listens to that serial data, and controls the colour (black -> 256 greys -> white) of a large rectangle on the screen. No upward temp change = black, max upward change = white anywhere in between = grey.

 

The object of the game is therefore to make the screen brighter, by relaxing the forehead and allowing blood to flow toward the prefrontal cortex.

 

I am stuck on getting the arduino to read the temperature LOL cheap chinese eBay sensor.....



#6 88LS

  • Guest
  • 100 posts
  • 31
  • Location:Cape Town, South Africa

Posted 24 January 2016 - 09:33 PM

If you get it working right, I'll buy one from you.

#7 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 25 January 2016 - 02:17 PM

I am very interested in this subject because this sounds like great idea to me.

I am not an expert but I tried to read something on the internet about connecting the MLX90614 to the Raspberry. It seems like there are some problems to get data from the sensor using I2C because there is a function called "repeated start" needed, which is not implemented in the Kernel of the Pi. Changing the programming language could be an option, there are some packages for Perl which allow the communication between sensor and Pi, but this woudl go too far for my skills.

My programming skills are mainly limited to Python, so maybe if you have ideas how to realize this project using this soft- and hardware, please share.

 

Also, i am sceptical about the sensors technical properties. The temperature solution i listed as 0.01 - 0.02°C which should be fine for measurement of the small changes occuring when bloodflow changes, but the absolute accuracy is listed as 0.5°C which is, imho way too low.

 

It would be a nice idea combine this with audio (like a noise changing pitch) or video feedback, after the online measurement is implemented.



#8 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 25 January 2016 - 10:24 PM

If you get it working right, I'll buy one from you.

 

If we get it working right it will cost about $20 maximum and be quite simple to assemble so you can build one yourself...

 

The only non standard part involved is something to hold the sensor on the forehead. A sweat band and a small 3d printed enclosure would be ideal for this.

 

I want to start the DIY neurofeedback revolution, the cost of such simple equipment is so high currently and that's just bullshit, something like this should be available to everyone regardless of their income.

 

My current idea is to plug it into a laptop but if we made it run on the new Pi Zero all someone would need is a phone charger and a TV with HDMI input...


Edited by spektrolyte, 25 January 2016 - 10:34 PM.

  • Agree x 2

#9 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 04 February 2016 - 11:25 PM

Hi,

 

I would like to push this topic so I bought an Arduino Uno and the MLX90614 sensor online. On the photo you can see the sensor connected to the Arduino and the Arduino software getting temperature data in °C from the serial (USB) port. This was the first test to see if everything works.

I am in the progress of writing a small Python script which gathers the data from serial port and will calculate the difference to the start temperature. The sensor will stay at the forehead for some minutes to reach temperature equilibrium with the skin and from that point the script will print feedback in some way on the screen.

Seems to work fine so far, next step is to build a gadget like a headband to enable measurement directly at the forehead.

 

If anyone is interested in building a diy heg-device on his/her own:

 

the sketches for Arduino and the wiring diagram can be found online:

 

Is it hot? Arduino + MLX90614 IR Thermometer

 

 

when finished I will upload the Python feedback script for You. This can take some time because lately, I have been kind of busy studying at the university.

 

IMG_20160205_000629.jpg

Neue_Bitmap.jpg


Edited by hatschiman, 04 February 2016 - 11:27 PM.


#10 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 05 February 2016 - 09:47 AM

Nice work. It seems that my sensor is faulty, can't get any data from it with any of the example code online. Thanks for picking this idea up and taking it forward!



#11 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 05 February 2016 - 05:26 PM

Here is another idea:

why not combine HEG functionality with some other markers like HRV and skin conductivity to build a device which gives feedback on several levels? Both functions should be easy to realize and implement, maybe even on just one single arduino board.

 

 



#12 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 05 February 2016 - 06:13 PM

Yes that was the plan, I started with HEG as it's the most interesting to most people.

 

Here are the other sensors.

 

HR: Pulse sensor Heart Rate Sensor PulseSensor for Arduino Raspberry pi

 

Breath: Heat-sensitive Temperature Sensor Module Thermistor For ARDUINO AVR SCM PIC

 

GSR is just some wire soldered to aluminium foil and held in place on two fingers with velcro. There will be a few other components but it is very simple. Just measures resistance between two pins on the Arduino.

 

I have orded an SLA 3D printer to make enclosures for the Arduino and body sensors where needed.



#13 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 14 February 2016 - 07:58 PM

For those who are interested in building a headset on their own i have programmed an easy to configure sketch for arduino which works with the MLX90614 Sensor.

For feedback you can use a simple LED which will then change its brightness, so no additional PC is needed. You have to use a pin which supports PWM for the LED output, otherwise it won't work. You might have to experiment a little bit with the variables in the first lines of the sketch to get it to work proper.

 

Spoiler

 

If you have got any questions do not hesitate to ask.

Parts of the code are copied from http://bildr.org/201...x90614-arduino/

You will need to install i2cmaster.h to compile the code.

 

For my project so far i dissembled an old digital tv receiver and use its display to show the temperature and additional the feedback led on the right side of the breadboard. So what is left to do is to build a proper case for the headband and work out the optimal values for the coefficients of the sketch.

 

led.jpg


Edited by hatschiman, 14 February 2016 - 08:07 PM.


#14 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 14 February 2016 - 10:19 PM

Good. Did you get it to calculate the rate of change?

 

I got my sensor working and outputting just the celsius data 20 times per second.

 

Will add a thermistor and see if I can get it to output a signal for breath detection.



#15 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 14 February 2016 - 10:55 PM

What it actually does is not to calculate the rate of change but the difference between baseline level and real time level. So the LED lights brighter the more the temperature rises but does not give feedback about the rate of change. So if ones head would stay at a temperature higher than baseline level the LED will have a constant brightness.

My code will also print the temperature data to serial port in selectable intervals.

The rate of change (dtemp/dt) could be an additional feedback, but using this feedback would mean that if you stay at a temperature higher than the baseline level the rate of change would equal zero.

I also implemented a noise reducer to smoothen some of the noise and the ups and downs in temperature measurement. It is really simple as it just calculates the average of a certain number (del_noise) of temperature values measured successively.

For equilibration and baseline level, the arduino measures for some time and takes the last adjusted number of temperature values and calculates the average (avrg_lenght).



#16 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 14 February 2016 - 11:38 PM

The rate of change is the only feedback that is important, the actual temperature is irrelevant. Only the rate of change will show when the user has hit the spot of concentration which activates blood flow.

 

Training this sudden rise in temperature which corresponds to the increase of blood flow is how HEG works.

 

1. Sample the temperature reading, and then again 300ms later.

 

2. Take the average of this reading Divide 100 by sample1, and multiply the result by sample2 to get a percentage.

 

3. Discard all data which is less than <100, that which remains is the positive rate of change.

 

4. Take this value minus 100, and average the result over 5 seconds. 

 

5. Use the 5 second average to control the LED brightness.


Edited by spektrolyte, 15 February 2016 - 12:00 AM.


#17 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 15 February 2016 - 12:26 AM

If i have the time i will try to implement this way the next days. This should not be a big deal.

What irritates me with this form of feedback is the fact that the temperature in the forehead can not rise infinitely. So when you hit the point of maximal circulation and thus maximal temperature in the forehead the led would not show any feedback, because the rate of change would be zero. Wouldn't one want the circulation rather to stay elevated than to let it rise suddenly?

Have you got any reference backing up this thesis?

 

I do not want to offend you and just try understand why it should work his way and not another.



#18 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 15 February 2016 - 02:16 PM

http://people.ece.co...573/htq2_mg573/

 

 

This project uses a thermistor and arduino to measure breath patterns.



#19 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 15 February 2016 - 02:21 PM

If i have the time i will try to implement this way the next days. This should not be a big deal.

What irritates me with this form of feedback is the fact that the temperature in the forehead can not rise infinitely. So when you hit the point of maximal circulation and thus maximal temperature in the forehead the led would not show any feedback, because the rate of change would be zero. Wouldn't one want the circulation rather to stay elevated than to let it rise suddenly?

Have you got any reference backing up this thesis?

 

I do not want to offend you and just try understand why it should work his way and not another.

 

It's not a thesis. I used a HEG system for a month and this is what it was doing; feeding back the positive rate of change of temperature. It is the principal of HEG.

 

You can't train forever, the temperature will rise sharply when blood flows and drop again when it stops. The whole point is that when the temp is rising, it means that the blood has started flowing.

 

If the user can flow the blood constantly and immediately raise the temperature of the device to maximum then they do not need HEG training.

 

This feedback of when the blood flow starts and stops is important for the people who do not have that ability.



#20 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 15 February 2016 - 06:36 PM

Ok this is a slightly improved version of the code with better noise reduction and the LED shows the rate of change now and not the percentual difference between baseline and real time value:

 

Spoiler

 

Seems to work quite well, but the parameters have to be adjusted for it to work proper. Cheers :)



#21 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 15 February 2016 - 08:10 PM

Well done!

 

Once a stable set of parameters is found, this can be scaled by another variable to work as a threshold control by slowly decreasing sensitivity to temperature rise as the weeks go by. The position of this threshold over time will show an upward curve if the training is successful.



#22 thebrainstore

  • Topic Starter
  • Guest TheBrainStore Proprietor
  • 88 posts
  • 4
  • Location:Gloucester, UK
  • NO

Posted 17 February 2016 - 02:42 PM

Which type of Arduino board and IDE version are you using? Have been unable to compile your latest code for my Uno.


Edited by spektrolyte, 17 February 2016 - 02:43 PM.


#23 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 18 February 2016 - 10:57 PM

I use an original Arduino UNO with Arduino IDE Version 1.6.6. Did you install the i2cmaster library?

What kind of error message do you get when you try to compile the code? I tried to copy and paste the code from my post and it works on my laptop and Arduino.


Edited by hatschiman, 18 February 2016 - 11:00 PM.


sponsored ad

  • Advert
Click HERE to rent this advertising spot for BRAIN HEALTH to support LongeCity (this will replace the google ad above).

#24 hatschiman

  • Guest
  • 16 posts
  • 3
  • Location:Germany
  • NO

Posted 06 April 2020 - 09:53 AM

I am going to revive this thread as this topic is still worth to have a look at. Due to Corona restrictions I found some time to work on this project and this is what I have got so far:
 
The headband:
(cut-off sleeping mask with some foam and hot glue, very basic for test purposes)
 
When wearing, the sensor is separated from the skin by a small tube to ensure that it has no direct contact to because otherwise, it would screw up the measurements.
 
Setup:
 
MLX90614 integrated
A four-line jack cable that connects the SDA/SCL/GND/VIN ports of the i2c temperature sensor to the  Arduino
Arduino Nano
 
Sketch for the Arduino Nano:
 

#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
void setup() {
    mlx.begin();
    Serial.begin(9600);
}

void loop() {
    if(Serial.available() > 0) {
        char incomingCharacter = Serial.read();
        switch(incomingCharacter) {
            case 'A':
                Serial.print(mlx.readAmbientTempC());
                Serial.print(";");
                Serial.print(mlx.readObjectTempC());
                Serial.print("\n");
        }
    }
} 

 
Python script for the first trials:
 

import serial
import time as t
import seaborn as sns
import matplotlib.pyplot as plt

com = serial.Serial(port='//dev//ttyUSB0', baudrate=9600)

trial = "reading"

externals = []
internals = []

t0 = t.time()

for i in range(40000):
    com.write(bytearray('A', 'ascii'))
    com.flush()
    line = com.readline()
    ext = float(str(line)[:-3].split(';')[1])
    inter = float(str(line)[2:-3].split(';')[0])
    #print(ext, inter)
    if ext < 100:
        externals.append(ext)
        internals.append(inter)
    #t.sleep(0.05)
com.close()

t1 = t.time()

print(t1 - t0)

plt.figure()
sns.kdeplot(externals)
plt.savefig(trial + "_distribution.png")

plt.figure()
plt.plot(externals)
plt.savefig(trial + "_course.png") 

The Arduino is configured to deliver the external and internal temperature separated by semicolon when an Ascii-encoded ‘A’ is sent via serial port. The Python script does exactly this for a defined amount of iterations, separates the temperature values and visualizes them in two plots. The first plot is a density plot which visualizes the distribution of all temperature values. The second plot shows the distinct temperature values for each iteration.

 

Before starting the trials, the sensor has to reach equilibrium. I believe this is mostly due to the forehead warming up because of the headband itself. This needs approximately 10 minutes.

Up until now, 2 (roughly 11 minutes) trials were conducted. In one of them I was just sitting on my computer chair with eyes closed and trying not to do something specific. The second trial was conducted while reading a book.

There are some differences in the courses of temperature values as well as the temperature distributions (ignoring one temperature outlier in the closed eyes trial). Whereas the eyes closed trial does not really show a trend in temperature values, the reading trial shows a tendency for the temperature to settle somewehere around 35.45 and 35.50. This is consistent with my subjective experience to be more immersed in the text.

The temperature distribution differs between these two trials in a shift towards the upper temperature range in the reading trial as opposed to the closed eye trial. The Max peak value is higher (around 66) for the closed eye trial but more evenly distributed in the reading trial. This has to be taken with a grain of salt, because there was only one trial for each experiment and the results should be validated by multiple trials to be meaningful.

 

thebrainstore stated that not the absolute temperature is of importance but more the rate of change in temperature. Someone who has difficulties in activating their prefrontal cortex should not be able to raise the temperature for very long. In order to create a feedback, the positive rate of change should be visualized in some way.

As you can see in the course plots, there is a lot of noise, i.e. jumping of temperature values between the distinct measurements. One way to handle this would be smoothening of the signal, which can by basically done by creating the average of a certain number (a window) of successive values. This would be the next step to implement. Further, I attached a datasheet of the used sensor. There are different types of the MLX90614, some of them are calibrated to deliver medical accuracy within the temperature range which is needed in scope of this project. What we are looking for is the MLX90614ESF-DXX-XXX-TU (X is a placeholder, the D the important part). I will have a look at that in time, hopefully.

 

I would be very happy about suggestions and ideas.

 

Best regards

Attached Files







Also tagged with one or more of these keywords: heg, diy, pre-frontal, autism

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users