Okay,
Here what i found , if you move the joystick up slowly then it works just fine , keep in mind that
i am applying FORWARD & BACKWARD on the same motor but if you move the joystick whether UP/DOWN quickly then the arduino reset.
So is it the code issue ?
///////////////////////////////////////////////////////////////////////////
// GND : GND
// VCC : 3.3V
// SE : pin 9
// CSN : pin 10
// SCK : pin 13
// MOSI: pin 11
// MISO: pin 12
// ESC : pin 6
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Servo.h>
#define SServoMIN 30 // Don't go to very end of servo travel
#define SServoMAX 170 // which may not be all the way from 0 to 180.
#define enB 3
#define in4 5
#define in3 6
struct dataStruct {
unsigned long _micros; // to save response times
//Servo
int SXposition; // The Joystick position values
int SYposition;
bool SswitchOn; // The Joystick push-down switch
//Motor
int MXposition; // The Joystick position values
int MYposition;
bool MswitchOn; // The Joystick push-down switch
} myData;
Servo myServo;
int ServoPosition;
int motorPosition;
RF24 radio(9,10);
int ReceivedMessage[1] = {000};
const uint64_t pipe = 0xE8E8F0F0E1LL;
void setup(void)
{
Serial.begin(9600);
radio.begin();
radio.setRetries(15,15);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1,pipe);
radio.startListening();
myServo.attach(8);
pinMode(enB, OUTPUT);
pinMode(in4, INPUT);
pinMode(in3, INPUT);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
void loop(void)
{
if (radio.available()){
while (radio.available()) // While there is data ready to be retrieved from the receive pipe
{
radio.read( &myData, sizeof(myData));
// Servo block
ServoPosition = map(myData.SXposition, 0, 1023, SServoMIN , SServoMAX);
myServo.write(ServoPosition);
//Serial.print(F(" Servo X= "));
//Serial.print(myData.SXposition);
//Serial.print(F(" Servo Y= "));
//Serial.print(myData.SYposition);
//Serial.print(F(" Servo Button= "));
//Serial.println( myData.SswitchOn);
////////////////////////////////////////////////////////////////
// Motor Block
int pwmOutput = map(myData.MYposition, 460, 0, 0, 255); // Map the potentiometer value from 0 to 255
int pos=myData.MYposition;
// Send PWM signal to L298N Enable pin
Serial.println(myData.SswitchOn);
if(pwmOutput<-30 & (myData.SswitchOn==1))
{
analogWrite(enB, 0);
analogWrite(enB, pwmOutput*-1);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
else if(pwmOutput>30 & (myData.SswitchOn==0))
{
analogWrite(enB, 0);
analogWrite(enB, pwmOutput);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
else
{
analogWrite(enB, 0);
}
//////////////////////////////////////////////////////////////////
}
}
}