Simulate a NMEA serial output sentence

I want to simulate the broad cast of a NMEA statement to my iPad. So far I have the Ipad wirelessly connected via TCPIP to my WiFly XV from spark fun. The WiFly data pin wants 0-3.3 TTL which I get using a level shifter. My problem is, I think, with the code (Its been a while since I last programed). Here is the essential part (largely and shamelessly borrowed from another poster). The serial print part works on the serial monitor but the WiFly isn't happily sending the right data to my iPad. Any suggestions would be gratefully recieved!

#include <SoftwareSerial.h>
#define txPin 4  // this pin is where the NMEA is transmitted from Arduino but careful we need to level shift from 0 to 5 ttl to 0 to 3.3 for the wifly
SoftwareSerial NMEAout = SoftwareSerial(0, txPin);


int sensorPinWindSpeed = A0;                              // select the input pin for the potentiometer
int sensorPinWindDirection = A1;   
const int buttonPin = 10;                  // the number of the pushbutton pin
const int buttonPin2 = 9;                  // the number of the pushbutton pin
int buttonState = 0;                     // variable for reading the pushbutton status
int buttonState2 = 0;                     // variable for reading the pushbutton status

int heading = 12;                        // When first powered this will be the heading



void setup() 
{  
                       
  NMEAout.begin(9600);                   // initialize software serial port NMEA
  Serial.begin(9600);                    // initiallize serial port so we can read on the serial monitor what is going out
  pinMode(buttonPin, INPUT);             // initialize the pushbutton pin as an input, increase heading
  pinMode(buttonPin2, INPUT);             // initialize the pushbutton pin as an input, decrease heading

}

void loop() 
{
  buttonState = digitalRead(buttonPin);            // read the state of the pushbutton value:
  buttonState2 = digitalRead(buttonPin2);         // read the state of the pushbutton value:

   if (buttonState == HIGH)                  // adds to the heading at every push
      {
          heading ++;
      }
         if (buttonState2 == HIGH)            // subtracts from the heading at every push
            {
               heading --;
            }
   if(heading==359)                        // Max degrees is 359, when reached return to 0
      {
           heading = 001;
      }
         if (heading==0)                     // Min degrees is 0, when reached return to 358,
            {                           // Had to set the degrees off slightly 
               heading = 358;               // or we get stuck in a loop
            }

     String begin = "";                     // Start of an NMEA gyro telegram                     

  if (heading < 9);
  {
      begin = "$HCHDM,00";                     // This adds the correct amount of zero`s
  }                                       // to the sentence, should always be a 
  if (heading == 10)                        // three digit number, eg 045, 003.
  {
     begin = "$HCHDM";
  }
  if (heading < 98, heading > 10)
  {
     begin = "$HCHDM,0";
  }
  if (heading > 99)
  {
      begin = "$HCHDM,";
  }

   String end = ".4,T*";                     // End of the telegram,
   String stringOne = begin + heading + end;      // Take the start, join to the heading int, and join the end

      char string[50]; 
   stringOne.toCharArray(string, 50);            // break the telegram into characters

   int XOR;
      int i;
      int c;
   for (XOR = 0, i = 0; i < strlen(string); i++)   // get the string/telegram length
         {
         c = (unsigned char)string[strlen(string)];
         if (c == '*') break;               // Ignore the $ and * symbol in the telegram
         if (c != '

) XOR ^= c;              // XOR everything else
        }
 
  int out = Serial.print(stringOne);            // Add the telegram to the serial line without checksum
  Serial.println(XOR, HEX);                  // convert the checksum to hex, add to the telegram and transmit
  NMEAout.println(XOR, HEX);                 
  delay(1000);

SoftwareSerial NMEAout = SoftwareSerial(0, txPin);

It's a REALLY bad idea to try to do software serial on (one of) the hardware serial pins. DO NOT DO IT! Especially when also trying to use the pin for hardware serial.

Thanks Paul, that didn't fix this problem but it probably explains another one that I had!

DavidFoe:
Thanks Paul, that didn't fix this problem but it probably explains another one that I had!

So, you changed the hardware and the software, and don't wish to describe either one, but you still want us to guess what is wrong. Pass.