madsci1016 / Arduino-EasyTransfer

An Easy way to Transfer data between Arduinos
http://www.billporter.info/easytransfer-arduino-library/
320 stars 114 forks source link

Connecting Teensy 3.2 together using RS485 / Easy transfer Library #13

Open Tejkaran opened 8 years ago

Tejkaran commented 8 years ago

Hi guys

I am new to this library and although I have used C language at lower levels, I would definitely rank myself as a rookie. I am quick to learn though.. I am trying to understand how this library works so that I can communicate between two Teensy 3.2. I have 1 master and 1 slave with a view for 1 master and 2+slaves later on. I have read the piece from Bill Porter(http://www.billporter.info/2011/05/30/easytransfer-arduino-library/) and a few others too. I know this is quite a long post with a lot of questions, but I would appreciate the help given.

At the moment I am set up as shown in this post on pjrc (https://forum.pjrc.com/threads/35616-Connecting-2-or-more-Teensy-together-with-RS485) and also the code too. I have attached a potentiometer to pin 14 too.

The questions I have revolve around how the library is constructed and what I can do with it.

So in the example that is set up (EasyTransfer_2Way_wPot_Example), the first that is done is to create two Objects. My understanding is that Objects save values of some sort. But what do the examples of ETIn and ETOut actually do? What is the purpose of having them there?

We then move onto struct RECEIVE_DATA_STRUCTURE and struct SEND_DATA_STRUCTURE I understand that the struct function creates a structure/record that you can call upon (http://www.tutorialspoint.com/cprogramming/c_structures.htm) What is the purpose of struct in the example? Is it not possible to just create a variable normally? Or a definition? The final point on the struct bit, the purpose of naming the data structures rxdata & txdata is to recall that structure when rxdata & txdata are used in the future right?

In the void setup, we have the lines:

  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);

Is there a specific syntax that is being followed here, as in what is this saying? To my understanding it is saying: For the values saved as ETIn[I dont know what details does] follow the structure set up above in rxdata and assign this to Serial and the same for the tx data too.

In the void loop, we have the lines: txdata.servoval = analogRead(0); I am just trying to get my head around this, does this say, select the structure called txdata and then from there choose servoval and make servoval equal to analogRead. Or is is saying make txdata.servoval equal to analogRead?

  if(!digitalRead(12))
    txdata.buttonstate = HIGH;
  else
    txdata.buttonstate = LOW;

If not read anything from pin 12, then buttonstate is high, but if you can it is low? is that right?

then the final few bits:

ETout.sendData(); What data is being sent out here? This is the master sending to the slave right?

ETin.receiveData(); Same questions as out, what is being received here? This is the master receiving from the slave?

Many, many thanks if you can help here. I apprentice this is a mix of C programming questions and also library questions, but I really am keen to know what is going on so I can crack ahead with what I am looking to do.

Tej