hello everyone. I have a neurosky TGAM module that I need to receive data through Serial1 of the arduino Mega, however, they are in this format AA AA 04 80 02 00 34
and I can't plot or use.
How do I get the arduino to receive this data via Serial1 and convert it to DEC?
IE how to decode this AA AA 04 80 02 00 34 ?
Tried some libraries but missing some values.
I'll leave the reference links I've been researching.
Anyone who can help with a link, libraries or sket I really appreciate it!!!
binary data is always transmitted as binary bits usually in groups of 8-bit bytes. it's very common to send text information using ASCII character coding. but it's more efficient to send non-text data (e.g. integer, float, graphics, audio) as a bit sequence representing those value in memory.
the issues are knowing where the data begins, how much follows and what it represents.
the above represents 7 bytes using hex notation where 4-bits are represented by a char 0-9A-F, and 2 hex characters represent an 8-bit byte.
your link describes the format of a packet.
the first two bytes are described as SYNC, 0xAA
the 3rd byte is the # of bytes that follow, 4 in this packet
the 4th byte is the code describing the data, 0x80, which in your link is a 2-byte raw wave value
the 5th byte is the # of data bytes, 2
the remaining byte are the data 0x00 0x34 in big endian format which means the 16-bit value is 0x0034 or 52 DEC
i would just define an 16-bit integer variable and copy the bytes into the multi-byte variable and then it can be operated on like any other integer.
the program needs to wait for the 2 SYNC bytes and then the packet length and read that many additional bytes into a buffer.
there could be multiple data in the packet each with a data -code and length if needed. each data-code and corresponding data need to be captured and processed independently until the entire packet is processed
the program needs to interpret the data based on the data-code. looks like there are 4 multi-byte data codes and 6 single byte data codes
somewhere i saw mention of a checksum which i think is missing in your posting.
i have code that reads a binary packet from an Automess radiation meter that must similarly wait for a start byte and process a packet. it handles a more complicated form a data
start by reading a complete packet, then disassembling it, interpreting the data and finally doing something with the data
The link you referenced tells you how to "parse" the returned packet.
A packet of information is a series of values arranged so each value has some significance.
The example below says there will be / could be 11 values.
If you read each value into an array[ ] you could look at each piece of the "packet"
for instance if you wanted to battery level you would look at array location 6. etc.
I understand this is not a simple task for a beginner. Usually this type of stuff is performed in a library some code capable kind sole wrote. However if you can't find a library you will have to do it yourself.
dear, I was happy and sad at the same time. I thought it was simpler to get the data.
I honestly don't know how to thank you for taking the time to answer me. I greatly appreciate your help.
There's a code I'm using that manages to capture data from the Tgam module but it's not that complicated. Could you analyze it please? could you comment it? It doesn't even use a specific library.