EEG AD8232 Phase 2

by msuzuki777 in Circuits > Arduino

6331 Views, 47 Favorites, 0 Comments

EEG AD8232 Phase 2

WirelessEEGconnected.JPG
WithUSB.jpg
WithouUSB.jpg

So this Lazy Old Geek (L.O.G.) built an EEG:

https://www.instructables.com/id/EEG-AD8232-Phase-...

It seems to work okay but one of the things I don’t like about it is being tethered to a computer. I use that as an excuse to not do any testing. Another concern I have is that it seems like I’m getting some AC power line noise in my signal.

During some earlier testing I saw mysterious 40Hz spike that seems to go away when I disconnect the USB and ran it on battery. See pictures.

Anyway, I did some testing with HC05 and HC06 Bluetooth modules and was able to get them to work:

https://www.instructables.com/id/OldMan-and-Blueto...

As mentioned, fellow Instructabler, lingib released his EEG Monitor:

https://www.instructables.com/id/Mind-Control-3-EE...

He writes much better code than I do and also developed a Processing code, so this project is based on his EEG Monitor. For Phase 2, I want to make a battery-powered EEG monitor. (Will try to enter in Battery Powered Contest)

Design Wireless Module

EEG Wireless.jpg
EEG_AD8232Wireless.png
PXL_20201022_220049736.jpg

For the microcontroller I will use a 3.3V Micro Pro. This Arduino is a 3.3V device so it is compatible with the AD8232. The Sparkfun version uses a 3.3V MIC5219 voltage regulator.

For a battery, I will be using an old rechargeable battery I happen to have. This is a lithium rechargeable battery probably designed for a smartphone.

As discussed later, I found out the AliExpress Micro Pro uses an XC6204 voltage regulator instead of the MIC5219.

So my design is a little borderline. Lithium batteries are typically 3.5 to 4.2V depending on the charge. The XC6204 claims a typical dropout of 200mV with a load up to 100mA. So worst case scenario at full load with 3.5V battery, the regulator would output would be about 3.3V. This should be fine, but just be aware of possible problems.

Other components are the modified AD8232 from Phase 1 and an HC05 modified for 3.3V Bluetooth module as discussed in:

https://www.instructables.com/id/OldMan-and-Blueto...

For convenience I used Eagle Cadsoft and made a PCB using this method:

https://www.instructables.com/id/Vinyl-Sticker-PCB...

Schematic and Eagle files are attached.

I measured power consumption: it was 58mA. At one time, I’d tested this battery for a capacity of 1750mA hours which gives a run time of about 30 hours on a charge.

For the battery connector, I used a JST2.0 2pin connector so that it would match up with my Adafruit M4 Express. Many of these batteries have three contacts but just measure with a multimeter for about 4V and solder the wires to the battery. I used hot glue to seal and support the connection.

WARNING: Some JST2.0 connectors have the Red and Black wires reversed from the Adafruit.

I also added a JST2.0 connector to a Lithium battery charger. See Picture.

Packaging and Sketch

Armband Case.jpg
Headband.jpg
3.5Plug.jpg
HC05_Rt_Angle.jpg
EEG Wireless.jpg
IntoPocket.jpg
WirelessOnArm.JPG
WirelessEEGconnected.JPG

To be useful to me, my EEG needs to be portable. I had a little pouch for another project. I sewed some Velcro on the back. I sewed an arm band strap with the other Velcro and some elastic, measured to fit my arm. The EEG goes into the pocket and attaches to the armband. See pictures.

To make the headband easier to use, (instead of soldering) I took a 3.5mm audio cable extender, cut off one end and connected it to the headband sensors and the ear ground. This will plug into the AD8232 module.

TIP: I assumed that the connector would be like standard audio cables with Left on the tip, Right in the middle and the bottom Ground. That is not correct for the AD8232 so I had to rewire it, see picture.

The original HC05 has pins coming out parallel to the PCB. To make it flatter, I straightened them so they were at right angles to the PCB, see picture. While the uneven pins is not intentional, it does make a better electrical connection.

The next picture shows the assembled wireless EEG, then how it will go into the pocket, which will velcro to the armband.

A couple of pictures show how it’s all attached.

Arduino sketch is attached,fix_FFT_EEG_wireless.ino

This is based on lingib code with a few lines added for HC05 communications.

Base Station

Base1.jpg
Base2.jpg
BaseStation.png

So this EEG Wireless will work with one of my CP2102-HC06 adapters to display real time data on a PC using Processing from:

https://www.instructables.com/id/Mind-Control-3-EE...

My thoughts: so brainwaves represent what your brain is doing. So if I’m looking at what my brainwaves are doing on the computer screen, the process of looking at the screen and thinking about it is going to affect my EEG. So I wanted the option of recording my EEG without having to view them. I decided to record time stamped data to a micro SD card so I can do some offline analysis.

The concept is, e.g., that if I’m testing how some binaural beats affect my brainwaves, I can write down when and what beats I’m listening to and later look at my EEG data to see if there are some effects during and after that time period.

This will use a base station, basically another Micro Pro with a HC06 to receive data from the wireless EEG, a DS3231 RTC to record the time and a microSD card adapter to save the time-stamped data to a microSD card. This is basically like my IR Thermometer:

https://www.instructables.com/id/IR-Thermometer-fo...

In fact I will leave the option of using an IR thermometer and DHT22(temp and humidity) on the PCB.

Here are the major components:

3.3V Micro Pro Arduino

DS3231 RTC (modified)

(future addition DHT22 temperature/RH)

HC06

(future addition MLX90614 IR Temp Sensor)

5V microSD card adapter

Power consumption:

As there are a lot of sensors attached to this Micro Pro, I’m going to pay a little attention to current.

The voltage regulator on the Micro Pro is powering all the sensors.

(The Sparkfun Micro Pro has an MIC5219 3.3v regulator on it that can supply 500mA of current.)

The AliExpress 3.3v Micro Pro I bought apparently has a Torex XC6204B regulator. This is suggested by the marking I can barely read but it looks like 4B2X.

The 4B stands for XC6204B, the 2 means 3.3V output.

As far as I can tell, the XC6204B outputs a maximum of 150mA (a lot less than the MIC5219 500mA). Nevertheless.

I cannot find any data on idle current draw of the 3.3V Micro Pro. So I decided to measure some:

3.3V Pro Micro 11.2mA

3.3V L.O.G. Binaural beats 20mA

3.3V Wireless EEG 58mA

The DS3231 datasheet max current at 3V is 200uA or 0.2mA.

The DHT22 datasheet max current is 2.5mA.

The HC06 is 8.5mA in active mode (40mA in pairing mode)

The MLX90614 datasheet I’m not sure looks like max current is 52mA.

So adding them all up is about 85mA which is not a lot less than 150mA. But it should be okay.

The microSD card adapter is powered by the RAW pin 5V.

I’ve attached a schematic of the base station. The protoboard I’m using and the sketch to follow does not include the DHT22 or IR thermometer.

Sketch

Arduino-Logo.jpg

Basically, the sketch receives the data sent by the wireless EEG HC05 via the bound HC06, it sends the data out it’s USB port in the same format as the wireless EEG so it can be read by EEG_Monitor_2 (Processing) and displayed.

It also gets the time and date from the DS3231 RTC and time stamps the data and writes it to a microSD card in CSV (comma separated values) format.

PROBLEM1: The wireless EEG was sending Bluetooth data to my HC06 at 115,200 baud. Apparently my HC06 can’t communicate correctly at that speed as it was seeing garbage. Well, I played around with it, finally got it working by setting both the HC05 and HC06 to 19,200 baud.

PROBLEM2: Daylight Saving time has been a problem for me. I ran across the following by JChristensen:

https://forum.arduino.cc/index.php?topic=96891.0

https://github.com/JChristensen/Timezone

To use this, you first have to set the RTC to UTC (Coordinated Universal Time), this is time in Greenwich, England. Well, I didn’t know how to do that but found this article:

https://www.justavapor.com/archives/2482

Rewrote it for Mountain time (attached) UTCtoRTC.ino

This sets DS3231 to UTC time, 6 hours later than Mountain time.

Then I incorporated the timezone into my Sketch. To be honest, I haven’t tested it out so just assuming that it works.

PROBLEM3: One of the problems with Bluetooth (and most other serial communications) is that it’s asynchronous. That means you don’t really know when the data started and you might be looking in the middle of a data stream.

So what I did was started each packet of data with a ‘$’ and looked for that in my base station. A better way to do this is called handshaking where the sender sends out some data then waits for the receiver to send back an acknowledgment of receipt. For this purpose, I’m not that concerned if I miss a packet every once in a while.

Sketch is attached, basecode.ino

Conclusions

WirelessEEGconnected.JPG
Processing.jpg

Unfortunately, since I started this project, I’ve lost my ability to really focus on projects. I wanted to do some actual testing with this EEG, especially with binaural beats. Maybe someday.

But I think I’ve provided enough information for others to build this project.

I was in the process of developing some 5 band code. The idea was to display the five brainwave bands, delta, theta, alpha, beta and gamma. I think the baseband sketch works, I don't think the fix_FFT works for Processing but I've attached it for those who might be interested.