hi
I'm working on a project where I want to transfer wireless the values from adxl345 accelerometer via nrf but on the receiver im taking 0 values what's the problem?
here are my codes
transmitter:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#include "Wire.h"
#define JOYSTICKFINGER A0 //reads from finger
#define JOYSTICKARM A1 //reads from arm
int VAL[3];
char output[512];
byte values[6];
#define accel_module (0x53)
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
void setup()
{
Wire.begin();
Serial.begin(9600);
//----nrf
radio.begin();
radio.openWritingPipe(pipe);
//-----adxl
Wire.beginTransmission(accel_module);
Wire.write(0x2D);
Wire.write(0);
Wire.endTransmission();
Wire.beginTransmission(accel_module);
Wire.write(0x2D);
Wire.write(16);
Wire.endTransmission();
Wire.beginTransmission(accel_module);
Wire.write(0x2D);
Wire.write(8);
Wire.endTransmission();
}
//--------------------( voide loop )-----------------
void loop()
{
VAL[0] = analogRead(JOYSTICKFINGER);
VAL[1] = analogRead(JOYSTICKARM);
int y, x, z;
int xyzregister = 0x32;
Wire.beginTransmission(accel_module);
Wire.write(xyzregister);
Wire.endTransmission();
Wire.beginTransmission(accel_module);
Wire.requestFrom(accel_module, 6);
int i = 0;
while(Wire.available()){
values[i] = Wire.read();
i++;
}
Wire.endTransmission();
x = (((int)values[1]) << 8) | values[0];
y = (((int)values[3])<< 8) | values[2];
z = (((int)values[5]) << 8) | values[4];
if (x < -255) x = -255; else if (x > 255) x = 255;
if (y < -255) y = -255; else if (y > 255) y = 255;
VAL[2] = map(y, -255, 255, 0, 180);
sprintf(output, "%d %d %d", x, y, z);
Serial.print(output);
radio.write( VAL, sizeof(VAL) );
}
receiver:
[code]
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
int valfinger, valarm;
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int VAL[3];
void setup()
{
Serial.begin(9600);
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}
void loop()
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.read( VAL, sizeof(VAL) );
valfinger = VAL[0]; //finger joy
Serial.print("finger =");
Serial.print(VAL[0]);
Serial.print("\t");
valfinger = VAL[1]; //finger joy
Serial.print("X =");
Serial.print(VAL[1]);
Serial.print("\n");
Serial.print("turn =");
Serial.print(VAL[2]);
Serial.print("\t");
//ADXL
}
}
else
{
Serial.println("NO radio available");
}
}
[/code]