Problem EasyTransfer

Hello,

I install EasyTranfer_2way_wPot_Example and EasyTranfer_2way_wServo_Example on two Arduino due's.

And I use an Half Duplex hardware.

At first I thought it worked well, but sometimes after starting it doesn't go well.

I think I have a situation where both tx (transmit data) of the arduinos are active at the same time.

And that doesn't recover.

Like a response how I can solve this problem.

Or maybe an advice to use another library. ( I only want read and write in and outputs, and read and write a data register )

Thanks in advance,

Lenn.

EasyTranfer_2way_wPot_Example
=========================

#include <EasyTransfer.h>


EasyTransfer ETin, ETout; 


struct RECEIVE_DATA_STRUCTURE{
 
  int16_t buttonstate;
};

struct SEND_DATA_STRUCTURE{
 
  int16_t buttonstate;
  int16_t servoval;
};


RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Serial.begin(9600);

  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
  
  pinMode(13, OUTPUT);  
  pinMode(12, INPUT_PULLUP);
  
}

void loop(){
  

  txdata.servoval = analogRead(0);
  
  if(!digitalRead(12))
    txdata.buttonstate = HIGH;
  else
    txdata.buttonstate = LOW;
  
  
  ETout.sendData();
  
 
  for(int i=0; i<5; i++){
 
    ETin.receiveData();
    
    
    digitalWrite(13, rxdata.buttonstate);
    
    delay(10);
  }
  
  delay(10);


EasyTranfer_2way_wServo_Example
=========================


#include <Servo.h>
#include <EasyTransfer.h>

//create two objects
EasyTransfer ETin, ETout; 

Servo myservo;

struct RECEIVE_DATA_STRUCTURE{

  int16_t buttonstate;
  int16_t servoval;
};

struct SEND_DATA_STRUCTURE{

  int16_t buttonstate;
};


RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;

void setup(){
  Serial.begin(9600);
.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
  
  pinMode(13, OUTPUT);  

  pinMode(12, INPUT_PULLUP);
  
  myservo.attach(9);
}

void loop(){
  
  if(!digitalRead(12))
    txdata.buttonstate = HIGH;
  else
    txdata.buttonstate = LOW;
  
  ETout.sendData();
  

  for(int i=0; i<5; i++){

    ETin.receiveData();
    
    digitalWrite(13, rxdata.buttonstate);
    
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));
    

    delay(10);
  }
  
  delay(10);
}

Why don't you use Hardwareserial between your 2 DUEs ?

Hello,

First I am a new user, so it's all new to me.

The ultimate goal is that a master can serial communicate with two slaves.

The first thought is to start with two Arduino's and expand to three Arduino's.

Maybe you can give advice for the ultimate goal.

Thanks in advance,

Lenn.

Connect Serial1 (RX1,TX1) of DUE "Master" to Serial1 (TX1, RX1) of DUE "Slave1", and Serial2 (RX2,TX2) of DUE "Master" to Serial1 (TX1, RX1) of DUE "Slave2".

You can find example sketches for using Serial.available() in File>Example>Communication.

An example sketch to play with Serial1, Serial2 on a single board. It's easy to cut the sketch for 2 DUE boards (don't forget to connect GND pins together !):

/*********************************************************************/
/* Jumper between RX1 and TX2, and another one between TX1 and RX2   */
/*********************************************************************/

char c = 0;
void setup() {
 
  Serial.begin(250000);
  Serial1.begin(5000000);
  Serial2.begin(5000000); 
  Serial2.print("Hello");
}


void loop() {
  String s;
  s.reserve(10);
  s = "";

  while (Serial1.available() > 0) {
    c = Serial1.read();
    s += c;

  }
  if (s.length() > 0) {
    Serial.println(s);
    Serial2.print(s);
  }
  delay(1000);
}

Oke thanks for the information.

But I want in the future make my own processor boards.

End I want make a RS485 network whit one serial hardware connection.

So that I must be able to give the slaves an address, sorry that is the ultimate goal.

And I need to be able to read and write data.

Lenn

You might consider a CAN bus (a differential bus, you can have up to 100 nodes, multimaster protocol, up to several hundred meters long, a very good CAN library for the DUE, 2 embedded CAN bus on a DUE). Only need to add 3.3V CAN transceivers.

Note that on a testbed for software debugging, if distance between 2 DUEs is less than a few meters, transceivers are not absolutly neccessary.

Note: Replace 5V by 3.3V in the AP !

Hello,

I want use the serial port because I want the CAN bus use in the future for other application. ( on same board )

So I have to use the serial bus ( TX-RX )

Lenn