Send Data

I have a 9 degree of Freedom.
I wrote its code
but , I need to connect it to another controller. I want to send data via Tx and Receive via Rx. I don't know if my code is correct or not , I need help checking it
#include <Wire.h>

#define MAGN_ADDRESS ((int) 0x1E) // 0x1E = 0x3C / 2
#define WIRE_SEND(b) Wire.write((byte) b)
#define WIRE_RECEIVE() Wire.read()

float magnetom[3];

void setup()
{
// Init serial output
Serial.begin(9600);

Wire.begin();
Wire.beginTransmission(MAGN_ADDRESS);
WIRE_SEND(0x02);
WIRE_SEND(0x00); // Set continuous mode (default 10Hz)
Wire.endTransmission();
delay(5);

Wire.beginTransmission(MAGN_ADDRESS);
WIRE_SEND(0x00);
WIRE_SEND(0b00011000); // Set 50Hz
Wire.endTransmission();
delay(20); // Give sensor enough time to collect data
}

// Main loop
void loop()
{
int i = 0;
byte buff[6];
int x_value = 0 ;

Wire.beginTransmission(MAGN_ADDRESS);
WIRE_SEND(0x03); // Send address to read from
Wire.endTransmission();

Wire.beginTransmission(MAGN_ADDRESS);
Wire.requestFrom(MAGN_ADDRESS, 6); // Request 6 bytes
while(Wire.available()) // ((Wire.available())&&(i<6))
{
buff = WIRE_RECEIVE(); // Read one byte

  • i++;*

  • }*

  • Wire.endTransmission();*

  • if (i == 6) // All bytes received?*

  • {*

  • // MSB byte first, then LSB; X, Y, Z*
    _ magnetom[0] = -1 * ((((int) buff[2]) << 8 ) | buff[3]); // X axis (internal sensor -y axis)_
    _ // magnetom[1] = -1 * ((((int) buff[0]) << 8 ) | buff[1]); // Y axis (internal sensor -x axis)_
    _ // magnetom[2] = -1 * ((((int) buff[4]) << 8 ) | buff[5]); // Z axis (internal sensor -z axis)_

  • if (magnetom[1] > 0.0) magnetom[0] += magnetom[0] > 0.0 ? 90.0 : -90.0;*

  • x_value = ((int)(magnetom[0]/4.7) + 90) ;*

  • Serial.println(x_value);*

  • while(Wire.available())\ This is supposed to receive data from Rx ????????*

  • {*

  • Serial.write(x_value); // sending data. Question , how is it going to be sent ?*

  • }*

  • }*

  • delay(20); // Give sensor enough time to collect data*
    }
    Thank you

magnetom[0] = -1 * ((((int) buff[2]) << smiley-cool | buff[3]); /

The old shift left by smiley-cool then.

Please read the how to use this forum sticky and then post your code correctly.

I have a 9 degree of Freedom.

What is this? A link would help.

Grumpy_Mike:

I have a 9 degree of Freedom.

What is this? A link would help.

It's like an honours degree in liberty :wink:

Do you remember typing your code in italics?
No?
Now do you see why we ask you post your code between code tags?