0

I am building mini Arduino quadcopter project. I am using USB host shield for joystick support and nrf24l01 to transmit the data. Unfortunately, I got wrong data transmitted at the receiver and tried many things but doesn't work. I hope you can help me to further my understanding. It is my own first arduino project and it means a lot for me to keep this momentum. Please, guide me. So, i am using maniac library for nrf24l01 https://github.com/maniacbug/RF24/archive/master.zip . USB host shield is use https://www.arduinolibraries.info/libraries/usb-host-shield-library-2-0 . Help me to find out how to get the value that i send instead of getting error value on serial monitor...

This is the serial monitor GettingStarted from tmrh library


Now sending 26291...ok...Failed, response timed out.

Now sending 27494...ok...Got response 27494, round-trip delay: 22

Now sending 28518...ok...Got response 28518, round-trip delay: 22

Now sending 29541...ok...Failed, response timed out.

Now sending 30742...ok...Failed, response timed out.

Now sending 31944...ok...Got response 31944, round-trip delay: 23

Now sending 32968...ok...Got response 32968, round-trip delay: 23

Now sending 33991...ok...Got response 33991, round-trip delay: 23

Now sending 35014...ok...Failed, response timed out.

Now sending 36215...ok...Got response 36215, round-trip delay: 23

Now sending 37239...ok...Got response 37239, round-trip delay: 23

Now sending 38262...ok...Got response 38262, round-trip delay: 23

Now sending 39285...ok...Failed, response timed out.

Now sending 40486...ok...Got response 40486, round-trip delay: 23

Now sending 41510...ok...Failed, response timed out.

This is the output I send from transmitter (Now, I'm using maniac library, because tmrh give irrelevant response and only a joystick response to this, pretty sure)

X: 128   Y: 32   Hat: 0  Twist: 128  Slider: 15  Buttons A: 128  Buttons B: 0
X: 128   Y: 32   Hat: 0  Twist: 128  Slider: 15  Buttons A: 128  Buttons B: 0
X: 128   Y: 32   Hat: 0  Twist: 128  Slider: 15  Buttons A: 128  Buttons B: 0
X: 0     Y: 32   Hat: 0  Twist: 128  Slider: 15  Buttons A: 128  Buttons B: 0
X: 0     Y: 32   Hat: 0  Twist: 128  Slider: 15  Buttons A: 128  Buttons B: 0
X: 0     Y: 32   Hat: 0  Twist: 128  Slider: 15  Buttons A: 128  Buttons B: 0
X: 0     Y: 32   Hat: 0  Twist: 128  Slider: 15  Buttons A: 128  Buttons B: 0

This is what I receive

Throttle: 0    Yaw: 127    Pitch: 127    Roll: 127    Aux1: 0    Aux2: 0
Throttle: 0    Yaw: 127    Pitch: 127    Roll: 127    Aux1: 0    Aux2: 0
Throttle: 0    Yaw: 127    Pitch: 127    Roll: 127    Aux1: 0    Aux2: 0
Throttle: 0    Yaw: 32    Pitch: 0    Roll: 128    Aux1: 15    Aux2: 128
Throttle: 0    Yaw: 32    Pitch: 0    Roll: 128    Aux1: 15    Aux2: 128
Throttle: 0    Yaw: 32    Pitch: 0    Roll: 128    Aux1: 15    Aux2: 128
Throttle: 0    Yaw: 32    Pitch: 0    Roll: 128    Aux1: 15    Aux2: 128
Throttle: 0    Yaw: 32    Pitch: 0    Roll: 128    Aux1: 15    Aux2: 128

Here is my transmitter coding

#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#include "le3dp_rptparser.h"

RF24 radio(9, 8); // select  CSN  pin
const byte address[6] = "00001"; //IMPORTANT: The same as in the receiver


//byte throttle = 512;       // min: 0 | max: 1023 | center: 512
//byte yaw = 512;       // min: 0 | max: 1023 | center: 512
//byte pitch = 8;       // up: 0 | right-up: 1 | right: 2 | right-down: 3 | down: 4 | left-down: 5 | left: 6 | left-up: 7 | center: 8
//byte roll = 128;   // min: 0 | max: 255 | center: 128
//byte AUX1 = 0;    // min: 0 | max: 255
//byte AUX2 = 0;
//byte joyButtonsB = 0;

  byte throttle ;
  byte yaw ;
  byte pitch ;
  byte roll;
  byte AUX1;
  byte AUX2;
  byte joyButtonsB;

struct MyData {
  byte throttle; 
  byte yaw; 
  byte pitch; 
  byte roll;
  byte AUX1;
  byte AUX2;
};

MyData data;

void resetData() 
{
  //This are the start values of each channal
  // Throttle is 0 in order to stop the motors
  //127 is the middle value of the 10ADC.

  data.throttle = 0;
  data.yaw = 127;
  data.pitch = 127;
  data.roll = 127;
  data.AUX1 = 0;
  data.AUX2 = 0;
}

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB                                             Usb;
USBHub                                          Hub(&Usb);
HIDUniversal                                    Hid(&Usb);
JoystickEvents                                  JoyEvents;
JoystickReportParser                            Joy(&JoyEvents);


void setup()
{
  //Start everything up
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();

//  radio.setPayloadSize(32);
  resetData();



  Serial.begin( 115200 );
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  Serial.println("Start");

  if (Usb.Init() == -1)
      Serial.println("OSC did not start.");

  delay( 200 );

  if (!Hid.SetReportParser(0, &Joy))
      ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1  );


}

void loop()
{
    //Print all the values into the serial monitor:
    Usb.Task();

  data.throttle = throttle;
  data.yaw      = yaw;
  data.pitch    = pitch;
  data.roll     = roll;
  data.AUX1     = AUX1;
  data.AUX2     = AUX2;
    radio.write(&data, sizeof(MyData));

    Serial.print("X: ");
    Serial.print(data.throttle);
    Serial.print("\t Y: ");
    Serial.print(data.yaw);
    Serial.print("\t Hat: ");
    Serial.print(data.pitch);
    Serial.print("\t Twist: ");
    Serial.print(data.roll);
    Serial.print("\t Slider: ");
    Serial.print(data.AUX1);
    Serial.print("\t Buttons A: ");
    Serial.print(data.AUX2);
    Serial.print("\t Buttons B: ");
    Serial.println(joyButtonsB);
}

void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
  //Put the values from the joystick in another variable:
  throttle = evt->x;
  yaw = evt->y;
  pitch = evt->hat;
  roll = evt->twist;
  AUX1 = evt->slider;
  AUX2 = evt->buttons_a;
  joyButtonsB = evt->buttons_b;
}

This is the receiver


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const byte address[6] = "00001"; 

RF24 radio(9, 8); 

struct MyData {
byte throttle; //We define each byte of data input, in this case just 6 channels
byte  yaw;
byte pitch;
byte roll;
byte AUX1;
byte AUX2;
};

MyData data;

void resetData()
{

data.throttle = 0;
data.yaw = 127;
data.pitch = 127;
data.roll = 127;
data.AUX1 = 0;
data.AUX2 = 0;

}

/**************************************************/

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

/**************************************************/

unsigned long lastRecvTime = 0;

void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(MyData));
lastRecvTime = millis(); //here we receive the data
}
}

/**************************************************/

void loop()
{
recvData();
unsigned long now = millis();
//Here we check if we've lost signal, if we did we reset the values 
if ( now - lastRecvTime > 1000 ) {
// Signal lost?
resetData();
}

Serial.print("Throttle: "); Serial.print(data.throttle);  Serial.print("    ");
Serial.print("Yaw: ");      Serial.print(data.yaw);       Serial.print("    ");
Serial.print("Pitch: ");    Serial.print(data.pitch);     Serial.print("    ");
Serial.print("Roll: ");     Serial.print(data.roll);      Serial.print("    ");
Serial.print("Aux1: ");     Serial.print(data.AUX1);      Serial.print("    ");
Serial.print("Aux2: ");     Serial.print(data.AUX2);      Serial.print("\n");



}

/**************************************************/

  • 1
    What is the actual result that you are getting? What values are you receiving and how do they correspond to the values that you are sending? Break your project down to get each bit working properly first. eg, try sending static data instead of data read from the joystick. – Majenko Jun 1 at 11:27
  • Maniacbug's RF24 is rather ancient. Could you please update to TMRh20's RF24, run the GettingStarted sketch on your boards and post the output? – Avamander Jun 1 at 16:31
  • @majenko sure i will post the result I m getting – bad kinect Jun 1 at 18:46
  • they give random value only when I turn a joystick to the left ` Throttle: 0 Yaw: 127 Pitch: 127 Roll: 127 Aux1: 0 Aux2: 0 Throttle: 0 Yaw: 127 Pitch: 127 Roll: 127 Aux1: 0 Aux2: 0 Throttle: 0 Yaw: 32 Pitch: 0 Roll: 128 Aux1: 15 Aux2: 128 Throttle: 0 Yaw: 32 Pitch: 0 Roll: 128 Aux1: 15 Aux2: 128 ` this is example I'm sending from transmitter ` X: 128 Y: 32 Hat: 0 Twist: 128 Slider: 15 Buttons A: 128 Buttons B: 0 X: 24 Y: 0 Hat: 0 Twist: 128 Slider: 15 Buttons A: 128 Buttons B: 0` – bad kinect Jun 1 at 19:00
  • @Avamander i tried both and found out the same output from here tmrh tmrh20.github.io/RF24 I have done the testing for simple code, and it works. the difference i made for this, i think the integer value is assuming the value from joystick is byte and sending it and try to receive it in same byte value. but doesn't work, i still don't get it ... please, really need your helps... – bad kinect Jun 1 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.