Pages: [1]   Go Down
Author Topic: Using different pins for RX and TX with the Easy Transfer Library  (Read 1613 times)
0 Members and 1 Guest are viewing this topic.
USA
Offline Offline
Newbie
*
Karma: 0
Posts: 8
What's with all the extra pieces?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am working on a wireless robot project using two arduino Nano's and two Xbee Series 1 transceivers. Using a couple of Adafruit adapter kits and an FTDI cable, I configured both transceivers to run at 57600 Baud. I am wanting to use pins D2 and D3 as my RX and TX pins for transmit and receive but am not sure how to change the code to allow this. I have previously used the SoftwareSerial library to do this but have not been able to use the two together.

In case you were wondering this project will ultimately be using a PS2 remote to control a remote inspection device.

Thank you in advance for any help you can offer.

Code:
#include <EasyTransfer.h>
#include <SoftwareSerial.h>


SoftwareSerial mySerial =  SoftwareSerial(2, 3); //this creates a new instance of a serial port under the
                                                 //name of "mySerial" and in the form of (Rx , Tx)
                                                 //This will set pins 2 and 3 to transmit and receive
EasyTransfer ET;


struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int Cross;
  int Circle;
  int Square;
  int Triangle;
};

SEND_DATA_STRUCTURE mydata;


void setup() 
{
  pinMode(13, OUTPUT);
  Serial.begin(57600); // set the data rate of the local serial I/O terminal
//  Serial.println("Goodnight moon!"); //print the following statement to local serial terminal
  mySerial.begin(57600); // set the data rate for the SoftwareSerial port
//  mySerial.println("Hello, world?"); //Transmit following statement using serial transmission
                                 

  ET.begin(details(mydata), &Serial);   //This is where I tried to use &mySerial instead of &Serial


}

void loop()                     // run over and over again
{
  //this is how you access the variables. [name of the group].[variable name]
  mydata.Cross    = 1;
  mydata.Circle   = 0;
  mydata.Square   = 1;
  mydata.Triangle = 0;
  //send the data
  ET.sendData();
  delay(10000); 
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  ET.begin(details(mydata), &Serial);   //This is where I tried to use &mySerial instead of &Serial
This is also where you failed to tell us what happened.
Logged

USA
Offline Offline
Newbie
*
Karma: 0
Posts: 8
What's with all the extra pieces?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I get an error and cannot compile the code.

The error verbatim:

no matching function for call to 'EasyTransfer::begin(byte*, unsigned int, SoftwareSerial*)'

Transmit_Using_Data_Packet.cpp: In function 'void setup()':
Transmit_Using_Data_Packet:31: error: no matching function for call to 'EasyTransfer::begin(byte*, unsigned int, SoftwareSerial*)'
C:\Program Files\Arduino\arduino-1.0.1\libraries\EasyTransfer/EasyTransfer.h:46: note: candidates are: void EasyTransfer::begin(uint8_t*, uint8_t, HardwareSerial*)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I get an error and cannot compile the code.
That error means "You can not do that!".

You could modify the EasyTransfer library to add that capability. It would not be hard.
Logged

USA
Offline Offline
Newbie
*
Karma: 0
Posts: 8
What's with all the extra pieces?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again for the help and quick response. I was looking through the Easy Transfer Library and noticed there are two lines that are commented out. Any thoughts on what might happen if I were to remove the "//" and let it run as is?

The lines of interest are
Quote
void begin(uint8_t *, uint8_t, HardwareSerial *theSerial);
//void begin(uint8_t *, uint8_t, NewSoftSerial *theSerial);
and
Quote
HardwareSerial *_serial;
//NewSoftSerial *_serial;

Code:
#ifndef EasyTransfer_h
#define EasyTransfer_h


//make it a little prettier on the front end.
#define details(name) (byte*)&name,sizeof(name)

//Not neccessary, but just in case.
#if ARDUINO > 22
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "HardwareSerial.h"
//#include <NewSoftSerial.h>
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <avr/io.h>

class EasyTransfer {
public:
void begin(uint8_t *, uint8_t, HardwareSerial *theSerial);
//void begin(uint8_t *, uint8_t, NewSoftSerial *theSerial);
void sendData();
boolean receiveData();
private:
HardwareSerial *_serial;
//NewSoftSerial *_serial;
uint8_t * address;  //address of struct
uint8_t size;       //size of struct
uint8_t * rx_buffer; //address for temporary storage and parsing buffer
uint8_t rx_array_inx;  //index for RX parsing buffer
uint8_t rx_len; //RX packet length according to the packet
uint8_t calc_CS;    //calculated Chacksum
};



#endif
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17253
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Thanks again for the help and quick response. I was looking through the Easy Transfer Library and noticed there are two lines that are commented out. Any thoughts on what might happen if I were to remove the "//" and let it run as is?

That should work but then you should add the "//" to the preceding Hardware.Serial lines. This is just allowing two different serial methods hardware serial or software serial to be used in the same sketch, but of course not both at the same time.

Lefty
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could add a flag to the class, and set it to one value in the hardware overload, and another value in the software overload. Create different names for the hardware and software instances. In the other methods that use the instance, check the flag and use the appropriate hardware or software instance,

Or, as retrolefty says, comment out the hardware instance when you uncomment the software instance.
Logged

Pages: [1]   Go Up
Jump to: