I have made a code for nrf24l01 but when I connect transmitter with serioal monitor the TX led light with a delay about 1sec and this maybe cayse my problem on receiver..why that happens?
code
ok I fixed it also on serial monitor receiver print values from receiver then has some error period then print values then error period and so on.. What can I do for better results? I could add ceramic capacitor parallel vcc and gnd on nrf24l01?
Thanks for your help
There is a problem on code transmitter send values on receiver but on receiver serial monitor the adxl takes a value and dont change. For example it shows turn=90 and when I move the sensor this value dont change but all the others sensors work correctly
code:
#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
#define dataRate RF24_2MBPS
#define paLevel RF24_PA_MAX
const int MPU=0x68; // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
int VAL[4];
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.setDataRate(dataRate);
radio.setPALevel(paLevel);
radio.setChannel(70);
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();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
//--------------------( 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);
Serial.print(VAL[2]);
Serial.print("\t");
sprintf(output, "%d %d %d", x, y, z);
Serial.print(output);
Serial.print("\n");
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,14,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
VAL[3] = AcX;
Serial.print("mpu=");
Serial.print(VAL[3]);
radio.write( VAL, sizeof(VAL) );
}
Oh, man - someone has got to explain this to the non-native english speakers. Can everyone please stop talking about code in the singluar.
English has slightly different treatment of things that are counted in individual units, and stuff that isn't made up of individual units, like water (yes, obviously water is made of molecules, but in usual day-to-day usage we don't talk about it that way).
You can say "I have an orange", but it makes no sense to say "I have a water". You can have a cup or a litre of water. You can have some water. You can even simply have water (in situations where not having it is a possibility, eg you are in the desert).
Likewise, you can say "a sketch" or "a program", or "an application", but it doesn't make any sense to say "a code" (in that sense).
Code is an amount of … stuff. You can say you have a certain amount of kilobytes of code, or pages of code, or you can be indefinite and say you have "some" code, or you can sometimes leave off the quantifier altogether, but the only way to have "a" code is if you mean a single line of assembler or a single machine language instruction.
PaulMurrayCbr:
Oh, man - someone has got to explain this to the non-native english speakers. Can everyone please stop talking about code in the singluar.
English has slightly different treatment of things that are counted in individual units, and stuff that isn't made up of individual units, like water (yes, obviously water is made of molecules, but in usual day-to-day usage we don't talk about it that way).
You can say "I have an orange", but it makes no sense to say "I have a water". You can have a cup or a litre of water. You can have some water. You can even simply have water (in situations where not having it is a possibility, eg you are in the desert).
Likewise, you can say "a sketch" or "a program", or "an application", but it doesn't make any sense to say "a code" (in that sense).
Code is an amount of … stuff. You can say you have a certain amount of kilobytes of code, or pages of code, or you can be indefinite and say you have "some" code, or you can sometimes leave off the quantifier altogether, but the only way to have "a" code is if you mean a single line of assembler or a single machine language instruction.
OT - with apology to Dimitris.
As one of those non native English speakers I have found the usage of "articles"
most difficult to grasp. It seems to be grammatical crutch used by many languages ( der / das, la etc.) who lack the ability to modify the "object" the article is attached too to make "sense" , as you nicely put it , from the whole sentence..
What I found interesting is that even native English speakers cannot explain when to use "the" and when not.
So - I speak and write without articles which apparently grammatical purists find offensive.
Anyway - thanks for the post.
Very refreshing format in this sea of arrogance.