HMc5833l Magneto sensor data over RF434

Hi, guy. i am interfacing Magneto sensor triple axis. HMC5833l i have UNO at Tx side and Mega at Rx side.

the problem is i am not gett ing right data on at TX side. here is my code.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
#include <VirtualWire.h> //Load the library

float headingDegrees,hd; //Define the temp float variable
char msg[6];

Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);

void setup(void)
{
Serial.begin(9600);
//Serial.println(“HMC5883 Magnetometer Test”); Serial.println("");
vw_set_tx_pin(12); // Sets pin D12 as the TX pin
vw_setup(2000); // Bits per sec
// settx();
/* Initialise the sensor /
if(!mag.begin())
{
/
There was a problem detecting the HMC5883 … check your connections */
Serial.println(“Ooops, no HMC5883 detected … Check your wiring!”);
while(1);
}

/* Display some basic information on this sensor */
// displaySensorDetails();
}

void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
mag.getEvent(&event);

/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
// Serial.print("X: “); Serial.print(event.magnetic.x); Serial.print(” ");
//Serial.print("Y: “); Serial.print(event.magnetic.y); Serial.print(” ");
//Serial.print("Z: “); Serial.print(event.magnetic.z); Serial.print(” ");Serial.println(“uT”);

// Hold the module so that Z is pointing ‘up’ and you can measure the heading with x&y
// Calculate heading when the magnetometer is level, then correct for signs of axis.
float heading = atan2(event.magnetic.y, event.magnetic.x);

// Once you have your heading, you must then add your ‘Declination Angle’, which is the ‘Error’ of the magnetic field in your location.
// Find yours here: http://www.magnetic-declination.com/
// Mine is: -13* 2’ W, which is ~13 Degrees, or (which we need) 0.22 radians
// If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
float declinationAngle = 0.22;
heading += declinationAngle;

// Correct for when signs are reversed.
if(heading < 0)
heading += 2*PI;

// Check for wrap due to addition of declination.
if(heading > 2PI)
heading -= 2
PI;

// Convert radians to degrees for readability.
float headingDegrees = heading * 180/M_PI;
hd = headingDegrees;

dtostrf(hd, 6,2,msg); //converts the float into a char
vw_send((uint8_t *)msg,strlen(msg)); //transmits the data
vw_wait_tx(); // Wait until the whole message is gone
//delay(1000);

//Serial.print("Heading (degrees): "); Serial.println(headingDegrees);

delay(500);
}

plz help me

Please read "How to use this forum" and follow the directions. Edit your post to add code tags.

How do you know that you are not getting the right data? Why did you comment out the code that printed the values from the sensor? If you are not getting good data from the sensor, why do you bother doing anything with the garbage data?