Brain
Brain copied to clipboard
Reading Serial Data Manually
I couldn't figure out how to make this library work and was wondering how I could parse serial data manually. I am getting data but I don't know what it means. Any help would be appreciated.
edit: this isn't much of an error but I didn't know where to post it
Parsing the serial data directly is tough work. Perhaps it'll help you to read through https://github.com/sixtyfive/tgam1/tree/master/lib/tg_stream_parser ?
Parsing the serial data directly is tough work. Perhaps it'll help you to read through https://github.com/sixtyfive/tgam1/tree/master/lib/tg_stream_parser ?
This seems more general. I have data and am wondering what it means in the context of an EEG device.
This is what directly reading serial data looks like: https://pastebin.com/vyYLFxBW
Looks like it might be the signal of one channel, as in, the digitized version of how many mV were measured by that channel's electrode relative to the ground or reference electrode at those moments in time. You might want to turn that into an x-y-plot or perhaps do some FFT (fast fourier transform) on it, like for example @kitschpatrol's other project, https://github.com/kitschpatrol/BrainGrapher, does.
Ok, thanks. From the data I have, how would I do something like getting the attention value or something similar?
Hmm. I only guessed that what you're seeing is raw data. That's not certain - you never gave any information about how you get that data. If indeed it is and instead you're interested in the attention value, then you might have to change the way you read out the chip. The attention value is calculated internally and send out as part of the unaltered serial output for any of the commercial devices I'm aware of. Also be aware that noone knows what the chip does to calculate either the attention or the meditation values and there's criticism of that. Others (like me) are interested in the EEG power bands only and prefer to calculate those themselves from the raw data.
I got this data by connecting a wire from the "T" pin of the chip to the serial "RX" pin. I then directly read the input serial data. This is what I've seen people doing but the Brain library didn't work after doing this so I was wondering if I could get data myself.
Ah, in that case it's more likely you have the preprocessed data (unless you also played with the resistors on the TGAM board). Try my project (https://github.com/sixtyfive/tgam1; make sure you go through the config file!) instead of the Brain library, see if you can get to work. Perhaps if that works you'll have an easier time figuring out how to get the Brain library to work.
Is there another way I can talk to you(discord or something else) because I have a few other questions?
Sorry, I stay off of social networks for precisely those reasons. One place where you should be able to find more help is https://electronics.stackexchange.com. If you want to help the people there to help you, also have a look at https://stackoverflow.com/help/how-to-ask.
Ok, that makes sense. Thanks a lot though.
Also, with the tgam1 program, I'm getting a lot of errors with the different libraries: #include <ESP8266WiFi.h> #include <DNSServer.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> WiFiClient wifi_client;
#include <PubSubClient.h>
I can't find ones that work. Where should I get them from?
One last thing. Reading serial data from the 57600 baudrate gives me this data: https://pastebin.com/2SH1yarQ
Does this have any significance? I briefly looked at the neurosky documentation but didn't see anything.
It's just numbers. Without knowing what resistors you have set on your TGAM board I don't think it's knowable what their meaning is. Also, if I remember correctly (this is all more than a year ago for me – Read The Source, Luke!) the TGAM serial data doesn't include newlines. Certainly doesn't include timestamps. So where are those newlines coming from and how do you know they're not arbitrary?
Short answer: The numbers you receive at 57600 contain the raw value. It's every 8th number in the stream. You can identify it by looking for the number 170 being sent twice in a row. The two numbers before that were the raw EEG value. The number after the double 170 is also important. It indicates how good the electrode connection is. All other numbers represent calculated values that in my experience have no practical use.
But this is just my guess from looking at the numbers. If you want to be sure I'd have to know which version of the TGAM you are using and what the settings are.
I hope that helps. If not, or if you're interested in a longer answer, let me know.
So what does the 8th number represent? You said "It's every 8th number in the stream." but what is "it"? And how could I get the attention/meditation values from this?
(Sorry if this is a dumb question, I'm just trying to figure out how this works)
By "calculated values", I understand @steeph-k to mean the attention and meditation values. And "it", every 8th number in the stream (thank you from my side as well, @steeph-k!), THAT is the raw value. THAT is what you want to take and perform your FFT on to get your EEG power spectrum.
Ohhhh. Thanks a lot both of you guys.
Well, I should have said the 7th and 8th byte. It's a 2-byte-number. But yes, it's the raw value that you would perform FFT on or feed to some software to interpret it. Keep in mind I'm just guessing as to the settings of your module. But the "eSense Attention" value, as Neurosky calls it, should be the second number after the 170 170 and "eSense Meditation" the third.
On the neurosky documentation, it says esense attention is 0-100 but in the second Pastebin you can see that sometimes the number after the 170, 170 is 255. What does this mean?
Actually, these are all the "attention" values from the pastebin:
[128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 26, 170, 170, 255, 170, 170, 170, 170, 170, 170, 133, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 32, 170, 170, 170, 170, 119, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 112, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 133, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 22, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 133, 170, 170, 133, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 252, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 249, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 119, 170, 119, 170, 170, 170, 170, 133, 119, 170, 170, 170]
They are all similar which makes it seem less likely that these are the actual meditation values.
It means that I didn't take another look at your output before writing my last comment and that my guess was wrong.
lol. Well, no problem. I'll just look over the data again and see if there's anything else that I find.
Well, most of that output seems unusable anyway. It looks like there are many numbers missing, most likely because of a bad connection for the serial transmission. If you're only after the eSense values, you could switch to 9600 baud anyway. This makes transmission errors much less likely and setting the mode ensures you know what the module actually sends. If you have a soldering iron with a small tip you can set the bridges accordingly. If I remember correctly you can do the same by sending a command code at 57600 baud, then switch to 9600 on your receiving device. It sounds like you have the spec sheet that explains the codes. I'd have to look them up myself.
Ok. Is there any useful data in the 9600 baud serial output(https://pastebin.com/vyYLFxBW)? I'm just not really sure what to be looking for.
I'm not sure there is useful data in this output. Are you sure your serial connection is okay and without strong interference? What are you using to read the data? The Brain library worked well for this when I used it. Maybe have another go at adding the library to your Arduino?
When I used the library, it only prints the data when brain.update() is true, which never happened. I don't really know why that's happening.
Also, I'm just reading the raw serial data at the 9600 baud rate.
Does the module send at 9600? Because the 57600 stream looked right (although incomplete). You have to set it to "normal" mode before you read at 9600. Other than that the only idea I have is to check the serial connection and make sure the receiver works probably. Maybe try a different software there as well. Because the output at pastebin is not raw. It has timestamps added. Maybe that's not all your receiver changes.
i'll note that i had to put full grounded sheet metal shielding around my board before the raw data values became usable and the signal began resembling actual EEG data. and yes, 9k6 baud will be easier to manage if you're not interested in the raw data anyways.
fwiw, what didn't work with my board was to tell it in software to switch to 57k6 when the resistors were untouched. but after removing that resistor that needed removing and then running at 57k6, using software to tell it to go back down to 9k6, that worked fine.
That was my experience as well.