I've been scratching my head for a while trying to figure out how to get my Arduino + Ethernet Shield to talk to FlightGear. Using the information from this forum and others, I've written up an Arduino IDE code as shown below. It is simply taking in a potentiometer reading (analog input) and I'm converting it to be [-1 1] and then just trying to send the data.
- Code: Select all
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
// DECLARE VARIABLES
const int stickxio = A1; //Define stick aileron (x) input
float stickx = 0; //Start aileron (x) central
String lat_stick;
// SETUP THE ETHERNET CONNECTION (MAC ADDRESS & IP ADDRESS)
byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x84, 0xA1};
IPAddress PC_IP(192, 168, 1, 191);
IPAddress UNO_IP(192, 168, 1, 190);
//IPAddress ip(192, 168, 1, 191);
unsigned int UDP_Port = 8888; // local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
//Serial.begin(9600);
// start the Ethernet and UDP:
Ethernet.begin(mac,UNO_IP);
// begin the UDP
Udp.begin(UDP_Port);
}
void loop() {
// GATHER THE VOLTAGES AND CONVERT THEM TO [-1 1] signals
stickx = (analogRead(stickxio)/512.0)-0.998; //Calibration span and offset
//Serial.print(stickx);
lat_stick = String(stickx,2);
//Serial.println(lat_stick);
//sendUDP(stickx);
Udp.beginPacket(PC_IP, UDP_Port);
Udp.print(lat_stick);
Udp.endPacket();
delay(10);
}
By uncommenting the lines of Serial.print, I've finally got the String value called "lat_stick" to display the actual value shown by stickx. However, I still cannot get this to come through in the Debugger in FlightGear. I'm using the following XML file for communication:
- Code: Select all
--generic=socket,in,100,192.168.1.191,8888,udp,hardware ^
I'm receiving the data like so (that being said, I've tried float, integer, and string to no avail):
- Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
<input>
<line_separator>\n</line_separator>
<var_separator>,</var_separator>
<chunk>
<name>arduino</name>
<type>string</type>
<node>/instrumentation/altimeter/arduino</node>
</chunk>
</input>
</generic>
</PropertyList>
If there is anyone out there that has experience with this, I would greatly appreciate any advice. I am new to the forum so if I've uploaded anything wrong please let me know and I'll change it or add whatever information is needed.
Thank you.