Need a fresh set of eyes Servo over nRf24L01 Transmitter

NEED A FRESH SET OF EYES

I'm Build an 10 Chanel transmitter from a video Cheep Ass Quadcopter

I have Been working on Transmitter this for several months I'm having a rough time getting the 2 pots to work.

The Pots read as if one is stuck or at times they both work as if they are on the same pins reading the same values.

All 4 of my switches work

Replaced the Pots with new ones and Changed Analog Pin location 4,5,6,7 with no change thats why i think the hardware is ok.

I'm using a very new version of Arduino and nRF24L01 and they work everywhere else sketch wise that is.

I also removed constrain from the Pots in the sketch also no change

I will build a new Tester Thingy with 3V Arduino and A new Arduino for the Transmitter if you recommend

below is the sketch..

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

const uint64_t pipeOut = 0xE8E8F0F0E1LL;

RF24 radio(9, 10);

// The sizeof this struct should not exceed 32 bytes
struct MyData {
 byte throttle;
 byte yaw;
 byte pitch;
 byte roll;
 byte dial1;
 byte dial2;
 byte switches; // bitflag
};

MyData data;

void resetData() 
{
 data.throttle = 0;
 data.yaw = 127;
 data.pitch = 127;
 data.roll = 127;
 data.dial1 = 0;
 data.dial2 = 0;
 data.switches = 0;
}

void setup()
{
 radio.begin();
 radio.setAutoAck(false);
 radio.setDataRate(RF24_250KBPS);

 radio.openWritingPipe(pipeOut);

 resetData();
}

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

// Returns a corrected value for a joystick position that takes into account
// the values of the outer extents and the middle of the joystick range.
int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse)
{
 val = constrain(val, lower, upper);
 if ( val < middle )
   val = map(val, lower, middle, 0, 128);
 else
   val = map(val, middle, upper, 128, 255);
 return ( reverse ? 255 - val : val );
}

void loop()
{
 boolean mode1 = false;//!digitalRead(4);
 
 // The calibration numbers used here should be measured 
 // for your joysticks using the TestJoysticks sketch.
 data.throttle = mapJoystickValues( analogRead(A0), 180, 482, 807, false );
 data.yaw      = mapJoystickValues( analogRead(A1), 150, 490, 800, true );
 data.pitch    = mapJoystickValues( analogRead(A2), 220, 468, 800, false );
 data.roll     = mapJoystickValues( analogRead(A3), 225, 487, 850, true );
 
 data.dial1    = constrain( map( analogRead(A4), 1, 1020, 0, 255 ), 0, 255);
 data.dial2    = constrain( map( analogRead(A5), 1, 1020, 0, 255 ), 0, 255);
 
 data.switches = 0;
 if ( ! digitalRead(2) ) data.switches |= 0x1;
 if ( ! digitalRead(3) ) data.switches |= 0x2;
 if ( ! digitalRead(4) ) data.switches |= 0x4;
 if ( ! digitalRead(5) ) data.switches |= 0x8;
 
 radio.write(&data, sizeof(MyData));
}

You may be getting spurious values when you read different analog pins one after the other because there is only one analog converter and it may still have some electricity left over from the previous pin. Try reading each pin twice - which effectively discards the first reading. Like this

data.throttle = mapJoystickValues( analogRead(A0), 180, 482, 807, false );
data.throttle = mapJoystickValues( analogRead(A0), 180, 482, 807, false );

data.yaw      = mapJoystickValues( analogRead(A1), 150, 490, 800, true );
data.yaw      = mapJoystickValues( analogRead(A1), 150, 490, 800, true );

And see how much better the code looks when you use the code button </> as in How to use the Forum

...R

Thanks I will try

I will also learn to add code in the box

Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Should help...Tom.. :slight_smile:

THANKS FIR THE HELP BUT IT DID NOT WORK.

ALSO FIXED THE CODE

THINKING THIS IS HARDWARE??????

Any other software ideas???

markgrecowork:
THANKS FIR THE HELP BUT IT DID NOT WORK.

ALSO FIXED THE CODE

THINKING THIS IS HARDWARE??????

Any other software ideas???

Please STOP SHOUTING

"Did not work" does not provide any information from which to help you. You need to post the latest version of your code and tell us exactly what it does.

Rather than have a complex line of code like this

data.throttle = mapJoystickValues( analogRead(A0), 180, 482, 807, false );

do it in stages like

int joyA0val = analogRead(A0);
joyA0val = analogRead(A0);
Serial.print("joyA0val ");
Serial.println(joyA0val);
data.throttle = map(joyA0val, 180,482, 807, false);
Serial.print("Throttle ");
Serial.println(data.throttle);

so that you can check the values at each stage of the process.

I presume you have a multimeter so you can measure the voltage at A0 to check the conversion value.

...R