Using packed binary data from pc serial

I am in a bit of a bind...
I have two days to interface a device to arduino and have a huge learning curve ahead of me.

I need to take incoming packed binary data, unpack it & convert it to decimal values

the incoming binary data packets are coming from a pc to an arduino on COM5 the data packets are in these two formats:

uint8_t type;
uint8_t id;
uint16_t pose;

or

uint8_t type;
uint8_t id;
int16_t roll;
int16_t pitch;
int16_t yaw;

I wanted to get the data with an identifier and comma seperated ending in /n but this is what I have to work with instead.
I have no experience working with binary and am at a loss... looking on the forum and online didnt bring up any base sketches that I could pull knowledge from.

Any help with code, hints, or links would be HUGE!!!

Start by understanding that there is NO SUCH THING AS DECIMAL VALUE, or a hex value etc. Thats just how we write things down for our convenience !

The values of type and id should give you the size and meaning of the message.

Mark

fxmech:
Any help with code, hints, or links would be HUGE!!!

It's still unclear what you are accomplish. What's sending the data? Is it sending anything to indicate when the data has "started" or "stopped"? Is it sending the same length every time?

The demo code here and here may shed a little light into some corners of your problem.

The first link is about sending data from the PC to the Arduino and the second link is about getting received data into variables.

I do hope you are young and fit because 2 days seems just enough time to work up to a heart attack from stress.

...R

The data is streaming from a PC on COM5
Binary data packets with identifiers other than the fact that the packet ended (dont understand what code tells us that since I cant see it but guessing its like /n????)
I say this because I see the data on a serial sniffer and IT knows that the data is in packets and shows them as groups of binary data in the format I described above.

I do know that for it to be in the

uint8_t type;
uint8_t id;
uint16_t pose;

format, type=1

and for this format:
uint8_t type;
uint8_t id;
int16_t roll;
int16_t pitch;
int16_t yaw;
type=2

Thanks Robin2!
I am neither young nor fit but Ive been under these deadlines enough not to stress :slight_smile:
here is what we are building as well as what we built last year....

We are no where near done :~

You just reposted what you said in your first post, instead of expanding on it given the questions asked. I didn't ask where the data was coming from, I ask what was sending it. PCs don't send it. Programs on the PC, do. If there is no way to differentiate when a packet starts or ends (either through markers or time, then you're in a bit of a pickle, because you need some way to differentiate the streams, else you run into a great amount of issues with synchronization.

Now you need to find the start and end of packet markers otherwise you wont get this to go in years let alone days.

Mark

Hopefully this will remove the mystery of binary data.
You need to load and run the sketch with Serial Monitor open,
then read the sketch source and compare the output on Serial Monitor.

This is only to fill in that day you all seem to have missed somehow, or your teacher did not explain or I dunno what.

If you don't get an OH moment then you either knew this already or you are denser than basalt.
If you knew this already then I can't can't figure out why your first post indicates such lack of understanding but perhaps a vitamin and/or sleep deprivation or other problem must be operating.

If you don't get it in less than 10 minutes, ask your study group or find a smart person to explain.

void setup( void )
{
  Serial.begin( 115200 );
  Serial.println( "\n What is in my variables?\n" );

  uint8_t my8bitVar = 65;
  uint16_t my16bitVar = 1234;

  Serial.print( "my 8 bit var as binary data: " );
  Serial.print( my8bitVar, DEC );
  Serial.print( " decimal = " );
  Serial.print( my8bitVar, HEX );
  Serial.print( " hexadecimal = " );
  Serial.print( my8bitVar, BIN );
  Serial.println( " binary, All The Same Value\n" );

  Serial.print( "my 8 bit var as 1 ASCII Text character: " );
  Serial.println( (char) my8bitVar );

  Serial.print( "\nmy 16 bit var as binary data: " );
  Serial.print( my16bitVar, DEC );
  Serial.print( " decimal = " );
  Serial.print( my16bitVar, HEX );
  Serial.print( " hexadecimal = " );
  Serial.print( my16bitVar, BIN );
  Serial.println( " binary, All The Same Value\n" );

  Serial.println( "Text data is ASCII characters that must be translated." );
  Serial.println( "Binary data is direct values that don't need to be translated." );

  Serial.println( "\nHere is text zero to nine, value as decimal then printed text.\n" );

  for ( my8bitVar = '0'; my8bitVar <= '9'; my8bitVar++ )
  {
    Serial.print( "my 8 bit var as decimal value " );
    Serial.print( my8bitVar, DEC );
    Serial.print( " is also the ASCII text character " );
    Serial.print( (char) my8bitVar );
  }
  Serial.println( "\n\nNote that in code, a text character in single quotes makes the ASCII value of the character." );
}

void loop( void )
{
}

A bunch of experts with large budget and all the tools they need look around and put together what they mostly have ready.

And you want to do that from Duh to Working in 2 days?

What really gets me is how these things are represented.
It is marketing selling expensive parts as easy-peasy, throw together like in a stupid movie.
Someone is selling kits, I'm sure, but just how complete I can't say. Is there a prize? Reputation?

Yup, thats how we roll!
Sorry your having a bad day man, but if it makes you feel better we dont have a huge budget (budgets are relative) and never had all the time in the world either... Its a project we all volunteered to be a part of because when it gets to comicon it puts big smiles on lots of faces.... hope to see you there my friend;)

This forum has always been about sharing projects and knowledge, learning and teaching...
Makes me a bit sad to get negative vibes when I post a legitimate question, but hopefully some day Ill be the one with the knowledge and desire to both help and motivate others with similar interests.

fxmech:
Yup, thats how we roll!
Sorry your having a bad day man, but if it makes you feel better we dont have a huge budget (budgets are relative) and never had all the time in the world either... Its a project we all volunteered to be a part of because when it gets to comicon it puts big smiles on lots of faces.... hope to see you there my friend;)

This forum has always been about sharing projects and knowledge, learning and teaching...
Makes me a bit sad to get negative vibes when I post a legitimate question, but hopefully some day Ill be the one with the knowledge and desire to both help and motivate others with similar interests.

I'm just trying to get you to reality from the situation as you painted it.

I hope your group has people who were ready already, that that first post does not indicate the team at all.

Hopefully by now you know just what 'binary data' means and can move to the next question.

Because if you haven't gotten that far, I am being very kind telling a declared non-swimmer that jumping in the middle of a deep lake is not a good way to learn how to swim. Please disregard if you are in fact a swimmer or do in fact have your own lifeguard. Otherwise hello dreamer, reality just called.

I get it but this industry doesn't work like that...
We learn as we go... We learn from what we need and what we need changes everyday...
We don't have time for structured classes... Just this week I'll be putting in over 90 hours...
We dream it up and make it happen... Usually by learning that's why this forum is amazing to me...
I started building with arduino a few years back and every show they want more and always deliver....
If I could have taken computer science I would have and gotten a very well rounded solid foundation on the subject, but I got in this doing animatronics.... Programming was not part of my job description but now arduino changed all of that...
When I introduced it to the studio with a programmable LED solution I got a wow.... Next week they wanted it wireless... Then servo integration, then programmable animations, etc etc...
If you ask me how to do any of that It would be a very different scenario, but this week it's about decoding packets and it's new to me...

But like I said that's how we roll.... And I always do my best and have yet to fail so every time you see me post a question I'll be the Newby but I do give back to the community on what I feel comfortable answering...

Everything I know started as a stupid Newby question... Kinda proud of that actually

Sorry, I think I inadvertently derailed the thread..

On to practical matters, now that I know you can handle more than seemed at first:

The first byte probably tells you how many bytes follow even if in an indirect way.
As long as your COM channel never has errors you should be good to go without start or stop data.

uint8_t type;
uint8_t id;
uint16_t pose;

or

uint8_t type;
uint8_t id;
int16_t roll;
int16_t pitch;
int16_t yaw;

As long as your COM channel never has errors you should be good to go without start or stop data.

How do you find the start of the first message?

OK back to the problem first,

  1. What on the PC is sending the data,

  2. What is the protocol? each packet consists of a your telling us about the data but we (and you) need to know the rest. And you are not using '\n'!.

After that we need to know what tpe of Arduino you have and how you intend to debug this. If your using the com port for data you can't use it for debuging! Does your Arduino have more than one com port?

Mark

holmes4:

As long as your COM channel never has errors you should be good to go without start or stop data.

How do you find the start of the first message?

I wouldn't know. It's how they roll, not me.

I did some research on how to do this, but I wanted to send from Arduino to Android

Basically I couldn't find a complete solution that had already been written.

On the Arduino side these is this library called Easy Transfer

However you'd need to write your own PC side of things, and to complicate matters, you'd need to do data conversions, because the data layout within a PC , or Andorid etc, wont be the same.
I. Byte order of e.g. An int. which is more than one byte long, would most likely be different, and things like double and float are probably even harder to convert.

There are some other software projects online that aim to translate binary data from one system architecture to another, I think one of them is called something pidgin, but they don't seem to be well supported , so I disregarded them as an option.
They also didn't handle the transfer, just the binary conversion.

There is another system called fermata, I think, that is supposed to allow reading and writing of the pins from a PC, e.g. You run a special sketch on the Arduino that parses the commands from the PC and either actions the commands or sends back responses e.f the state of a particular pin.
But this wasn't what I wanted and doesn't sound like its what you need either.

So I suspect that writing the PC end of Easy Transfer including data type changing is probably what you'd need to do.

Thank you Im glad I checked in again... almost didnt...
Ill check that out... The pc end is being supplied to me so I dont need to write it just need to tap into the data and make it usable for me.
Im actually making some progress with help from another helpful guy such as yourself... Ill post the code here if I get it running smoother... but I'm accessing all data now so its a huge step forward!!!!