Go Down

Topic: (updated)Help on Serial communication between Arduino and PC!! (Read 2019 times) previous topic - next topic

PaulS

Quote
So who am I to argue with the OP?

I'm not opposed to arguing with people that have provided no proof. Too many posters equate "compiled-and-linked-and-uploaded" to "worked perfectly".

cosailer


I'm not opposed to arguing with people that have provided no proof. Too many posters equate "compiled-and-linked-and-uploaded" to "worked perfectly".


Worked perfectly means that both mega and PC are working fine

I have updated my problem. still need a lot of helps :-)

PaulS

Quote
Worked perfectly means that both mega and PC are working fine

I have updated my problem. still need a lot of helps :-)

These are contradictory statements, you know. If everything is working perfectly, it's time to quit. If not, the "everything's fine" is not true.

So, which is it? Going back and editing your original post is nor a good idea.

cosailer


These are contradictory statements, you know. If everything is working perfectly, it's time to quit. If not, the "everything's fine" is not true.

So, which is it? Going back and editing your original post is nor a good idea.


Sorry for any misleading, I am talking about the small data size case here, which is,

If I used intData[3], then everything is working perfectly, if I used intData[20], then the problem appears.
That's the strange part about it, with smaller data size, it actually works.

Also, I am not changing my original post, I simply added some stuff, this is not a good idea?





Nick Gammon


That's the strange part about it, with smaller data size, it actually works.


Not at all. That's like saying "I have a small aircraft. If I put two passengers in it, it flies OK. If I put in 20 passengers it crashes".

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

cosailer

I have changed my post into the original state, and here is some update.

it turns out that the problem is not with Arduino(I am using 1.0 IDE) at all, I tried my program on 2 linux computer using 2 USB-TTL adaptors, the problem remains, which I think is a good thing because the problem is how to program the serial ports rather than some bugs....

Background Idea

This is a part of my semester project, so it is kinda in a hurry. The basic idea is to transfer all the sensor data from Arduino to Raspberry Pi through UART, and then goes to PC through WIFI(dongle), I also send commands to RPi and then goes to Arduino via UART.  And you are right, I need to define my own mini protocol, which is described below,

There are 3 frame types, sensor data, request data, and ACK, they all have fixed length, so no need for end marking stuff.
The sensor data has these data elements, others are much more simpler.
 byte tag;
 byte length;
 unsigned long count;
 unsigned short int intData[8];
 float floatData[5];
 byte verification;

-----------------------------------------------------------------------------

Problems

Well, I have already programmed the protocol into Arduino, since it has problems, I have to make some small tests, so you will not find the protocol in the code below, it is simply a test to transfer 20 short int data. When I tried to send 3 int data, the send and receive seemed to work perfectly, everything is correct, but if I send 20 int data, the first 7 bytes were just missing on the receiver side(still don't know where is the problem).

Now, I know the code I wrote is really really crappy(I adapt from C into C++),  which I don't really want put it up here to embarrass myself. But in case anyone want to find the problem, it is in my GDrive: [https://docs.google.com/open?id=0B-PlSu8oC8g-Q2RELWwxSUpxTk0]

So anyone care to introduce some similar examples on how to transfer the entire instance of a class(I didn't use struct because I need some methods), through the serial port ??

For example, how to send this via UART ?? and receive it on the other side properly ??

Thank you sooooo much !!

Code: [Select]
class SensorData
{
   public:
   byte tag;
   byte length;
   unsigned long count;
   unsigned short int intData[8];
   float floatData[5];
   byte verification;
};





PaulS

The first question I have is why you are using a class, rather than a struct?

The answer to how to send that data is related to marshaling/unmarshaling. That is the process for sending an object from one computer to another AS AN OBJECT. So, the question is really whether that is what you want to do. Or, is it the data in the object that you want to send?

You need to show some code that creates and populates an instance of that class (or struct, which is what it should be), and define how you want to marshal the data. The receiver needs to unmarshall the data the same way.

Endianness and differing type sizes can play havoc with marshaling/unmarshaling data. Which, of course, is why this is part of your project - to see if you have considered these issues and developed a plan to deal with them.

Nick Gammon


For example, how to send this via UART ?? and receive it on the other side properly ??


I would serialize it. That is, convert it into something else, like just a string with (say) commas between each number. There is no guarantee that an int on the receiving end will be the same size as an int on the sending end, for example, or that floats have the same format internally.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy