Software programming
Programming the XBEEs
To program the XBEE modules you have to use the DigiKey XTCU-Software.
One of the XBEEs has to be the "coordinator device" the other XBEE has to be configured as "end device".
I changed following parameters of both XBEEs identically:
Channel, PanID, AES encryption = enable, AES key
Be aware, that changing the baud rate in the XBEE results in changing the baudrate of the virtual COM in Windows and in your Arduino program also. So I remained at 9600 for easy switching between Arduino programing and XBEE usage.
Code for base station
// this program is for the base station with LCD
// lib for communication via I2C
#include <Wire.h>
// special lib for YWrobot LCD
#include <LiquidCrystal_I2C.h>
// I2C address of LCD module
LiquidCrystal_I2C lcd(0x27,20,4);
String XBEEsendstring;
String XBEEgetstring;
char XBEEgetchar;
int RunCounter = 1;
float wert;
void setup() {
// writing fixed Text to diesplay positions
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("WIND:");
lcd.setCursor(10,0);
lcd.print("UBAT:");
lcd.setCursor(0,1);
lcd.print("UI:");
lcd.setCursor(10,1);
lcd.print("II:");
lcd.setCursor(0,2);
lcd.print("PI:");
lcd.setCursor(11,2);
lcd.print("F:");
// sending to the remote inverter station
Serial.begin(9600);
// while nothing was received yet
while (Serial.available() <= 0)
{
// send X as handshake to the remote inverter station
Serial.print('X');
}
// giving it a little bit time to process
delay(100);
// remote inverter station answered with a lowercase x
if (Serial.read() == 'x')
{
lcd.setCursor(0,3);
lcd.print("wireless ready");
}
}
// infinite program starts here
void loop() {
// RunCounter defines amount of data to get
// 5 separate values from the inverter
if (RunCounter > 5)
{
lcd.setCursor(0,3);
// a useless text for the 4th line
lcd.print("Inverter Monitor");
// resetting for the next set of 5
RunCounter = 1;
}
switch (RunCounter)
{
// each run one paramter to get and to position at the LCD
// sending the Waeco commands through the XBEEs
case 1:
XBEEsendstring = "VBAT?";
lcd.setCursor(15,0);
break;
case 2:
XBEEsendstring = "VINV?";
lcd.setCursor(3,1);
break;
case 3:
XBEEsendstring = "IINV?";
lcd.setCursor(13,1);
break;
case 4:
XBEEsendstring = "PINV?";
lcd.setCursor(3,2);
break;
case 5:
XBEEsendstring = "FRQ?";
lcd.setCursor(13,2);
break;
}
if (XBEEsendstring != "")
{
// send it
Serial.print(XBEEsendstring);
}
// waiting for being processed remotely
delay(700);
if (Serial.available())
// return value of remote inverter station received, interpreting it as float
lcd.print(Serial.parseFloat());
RunCounter ++;
}
Code for remote inverter station
// this program is for the remote inverter station
// hardware serial is used for XBEE and Arduino programming
// software serial is used for communication with inverter
#include <SoftwareSerial.h>
SoftwareSerial SPW(3, 2); // 3 RX, 2 TX
String SPWsendstring;
String SPWgetstring;
char SPWgetchar;
String Xbeesendstring;
String Xbeegetstring;
char Xbeegetchar;
void setup()
{
// init the com port to XBEE
Serial.begin(9600);
// init the com port to inverter, 4800 is a must by Waeco Dometic
SPW.begin(4800);
// waiting for the base station
while (!Serial.available())
{
delay(10);
}
// reading one char
while (Serial.available())
{
Xbeegetchar = Serial.read();
}
// communication start received from base station
if (Xbeegetchar == 'X')
{
// answering to base with a lowercase x
Serial.print('x');
}
}
void loop()
{
SPWsendstring = "";
SPWgetstring = "";
Xbeesendstring = "";
Xbeegetstring = "";
// if connection between XBEEs is established when code already in infinte loop
// we also have to do the handshake
while (Serial.available())
{
Xbeegetchar = Serial.read();
if (Xbeegetchar == 'X')
{
Serial.print('x');
}
// if handshake is done, the real communication is clocked in char by char
Xbeegetstring.concat(Xbeegetchar);
delay(10);
}
// if last char of command string from base is a ? then command is complete
if (Xbeegetstring.substring(Xbeegetstring.length()-1,Xbeegetstring.length()) == "?")
{
// load the inverter request with the command
SPWsendstring = Xbeegetstring;
}
if (SPWsendstring != "")
{
// send the commmand to the inverter with CR+LF at the end
SPW.println(SPWsendstring);
}
// waiting for the answer of the inverter
while (SPW.available())
{
// clocking in char by char
SPWgetchar = SPW.read();
// building the string
SPWgetstring.concat(SPWgetchar);
delay(50);
}
// when => was received, the command was successful
if (SPWgetstring.substring(SPWgetstring.length()-4,SPWgetstring.length()-2) == "=>")
{
// send the received string 1:1 to the XBEE = base station (without CR+LF)
Serial.print(SPWgetstring); // without forming with .toFloat()
}
}
Hints
When testing the software, I at first had a strong look at the values of inverter power and inverter current. They were zero all the time. I assumed a bug in my software or protocoll of Waceo.
After connecting real output load I recognized, that the resolution of both is very coarse. One step of power is 23 W, one step of the current is 0,1 A AC.