I'm trying to send data via EasyTransfer.h with Xbees. Then display the data on an LCD. The data displays perfect for integer data but only shows up as scrambled text for character data. I have tried both String and Char* data types but both only show garbled text on the LCD.
Thanks!
/*
SENDER CODE / SENDER CODE /SENDER CODE / SENDER CODE / SENDER CODE
SENDER CODE / SENDER CODE /SENDER CODE / SENDER CODE / SENDER CODE
SENDER CODE / SENDER CODE /SENDER CODE / SENDER CODE / SENDER CODE
SENDER CODE / SENDER CODE /SENDER CODE / SENDER CODE / SENDER CODE
*/
#include <EasyTransfer.h>
#include "Wire.h"
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 5, 4, 6, 7);
//create two objects
EasyTransfer ETin, ETout;
struct RECEIVE_DATA_STRUCTURE{
int buttonstate_val1;
int buttonstate_val2;
int buttonstate_val3;
char *msgLCDSender;
};
struct SEND_DATA_STRUCTURE{
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;
int inPin_val1 = 12; // the number of the input pin
int outPin_val1 = 13; // the number of the output pin
int state_val1 = HIGH; // the current state of the output pin
int reading_val1; // the current reading from the input pin
int previous_val1 = LOW; // the previous reading from the input pin
long time_val1 = 0; // the last time the output pin was toggled
long debounce_val1 = 200; // the debounce time, increase if the output flickers
int inPin_val2 = 10; // the number of the input pin
int outPin_val2 = 11; // the number of the output pin
int state_val2 = HIGH; // the current state of the output pin
int reading_val2; // the current reading from the input pin
int previous_val2 = LOW; // the previous reading from the input pin
long time_val2 = 0; // the last time the output pin was toggled
long debounce_val2 = 200; // the debounce time, increase if the output flickers
int inPin_val3 = 8; // the number of the input pin
int outPin_val3 = 9; // the number of the output pin
int state_val3 = HIGH; // the current state of the output pin
int reading_val3; // the current reading from the input pin
int previous_val3 = LOW; // the previous reading from the input pin
long time_val3 = 0; // the last time the output pin was toggled
long debounce_val3 = 200; // the debounce time, increase if the output flickers
void setup(){
Serial.begin(9600);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ETin.begin(details(rxdata), &Serial);
ETout.begin(details(txdata), &Serial);
pinMode(inPin_val1, INPUT);
pinMode(outPin_val1, OUTPUT);
pinMode(inPin_val2, INPUT);
pinMode(outPin_val2, OUTPUT);
pinMode(inPin_val3, INPUT);
pinMode(outPin_val3, OUTPUT);
}
void loop(){
for(int i=0; i<5; i++){
if (ETin.receiveData()) {
//Parse the return values and set them here
digitalWrite(outPin_val1, rxdata.buttonstate_val1);
digitalWrite(outPin_val2, rxdata.buttonstate_val2);
digitalWrite(outPin_val3, rxdata.buttonstate_val3);
lcd.begin(16, 2);
lcd.print(rxdata.msgLCDSender);
delay(10);
}
}
delay(10);
}
/*
RECIEVER CODE / RECIEVER CODE / RECIEVER CODE / RECIEVER CODE / RECIEVER CODE
RECIEVER CODE / RECIEVER CODE / RECIEVER CODE / RECIEVER CODE / RECIEVER CODE
RECIEVER CODE / RECIEVER CODE / RECIEVER CODE / RECIEVER CODE / RECIEVER CODE
RECIEVER CODE / RECIEVER CODE / RECIEVER CODE / RECIEVER CODE / RECIEVER CODE
*/
#include <Servo.h>
#include <EasyTransfer.h>
//create two objects
EasyTransfer ETin, ETout;
//create servo
Servo myservo_1;
int state_val1 = HIGH; // the current state of the output pin
int state_val2 = HIGH; // the current state of the output pin
int state_val3 = HIGH; // the current state of the output pin
int servoPin_1 = 9; // the number of the input pin
int outPin_val1 = 13; // the number of the output pin
int outPin_val2 = 12; // the number of the output pin
int outPin_val3 = 11; // the number of the output pin
struct RECEIVE_DATA_STRUCTURE{
};
struct SEND_DATA_STRUCTURE{
//put your variable definitions here for the data you want to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int buttonstate_val1;
int buttonstate_val2;
int buttonstate_val3;
char *msgLCDSender;
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;
void setup(){
Serial.begin(9600);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ETin.begin(details(rxdata), &Serial);
ETout.begin(details(txdata), &Serial);
myservo_1.attach(servoPin_1);
pinMode(outPin_val1, OUTPUT);
pinMode(outPin_val2, OUTPUT);
pinMode(outPin_val3, OUTPUT);
}
void loop(){
////////////////////////////SENDS THE DATA PART//////////////////////////
//then we will go ahead and send that data out
txdata.buttonstate_val1 = state_val1;
txdata.buttonstate_val2 = state_val2;
txdata.buttonstate_val3 = state_val3;
txdata.msgLCDSender = "TEST MESSAGE";
ETout.sendData();
////////////////////////////SENDS THE DATA PART//////////////////////////
//delay for good measure
delay(10);
}