Need help programming

Arduino RC Pan and Tilt Mechanism with Stepper Motors:
Stepper Motor Control Through NRF24L01 Radio Connection

I've been getting into arduino projects this year so I'm not very familiar with programming, but I have been wondering how I would control 2 stepper motors with a joystick module. One stepper motor will be dedicated to turn on the x axis (pan), and the other stepper motor on the y axis (tilt). Another concept I've wondered about is how I would control these stepper motors with the joystick over a pair of radio transceivers such as the NRF24L01+. I have one Arduino Mega ATmega2560 R3, one Arduino Uno R3, one 5 pin joystick module, two NRF24L01+, two NEMA-17 stepper motors, and one stackable v2.3 adafruit motor shield. I plan on connecting the 2 stepper motors to the motor shield and then stacking that motor shield onto the Arduino Mega. Then I will connect one NRF24L01+ to the Arduino Mega and the other to the Arduino Uno. The Arduino Uno will serve as a transmitter for the joystick and the Arduino Mega will serve as the receiver. If anyone could give me advice or sample code with explanations on how to control the stepper motors through the NRF24L01+ with a joystick module, it would be very much appreciated! Thanks everyone!

P.S. If anyone could help me with the code for the controlling of the stepper motors with the joystick but not over the wireless connection, that would help a lot too.

That's a lot of stuff to do... Take it one step at a time...

I'd recommend starting with the input (joystick) and just write a little program to control some LEDs. There are example programs for reading input ports and turning on & off LEDs and you'd just need to add some if-statements to light (or dim) different LEDs depending on joystick movement.

If it's an analog joystick you can dim the LEDs like you'd do with a potentiometer.

For the output, there's a stepper motor library. Start by controlling one stepper motor under software control (with no joystick input) and then add the code to make it respond to the joystick.

When that all works, work on the RF stuff. Again, I'd start by transmitting a simple "message" to turn on & off an LED.

Arduino RC Pan and Tilt Mechanism with Stepper Motors...

Most pan & tilt mechanisms use servo motors.

I'm not very familiar with programming

The two most important concepts in programming are conditional branching (if-statements, etc.) and loops (doing something over-and-over, usually until some condition is met).

Of course, there's a LOT more to programming than that, but once you understand those two concepts you should have a good idea about how to structure a program.

Again, take it one step at a time. For a beginning programmer, that means writing, test-compiling, and debugging one or two lines of code at a time. That's not quite as easy as it sounds because you can't just 'start at the top'... i.e. If you delete the bottom half of a program it won't make sense to the compiler and you'll get lots of reported errors.

The biggest mistake beginning programmers make is to write the whole program before testing it... The compiler can get confused and it might reports hundreds of cryptic errors and you don't know where to start fixing it. If you've added one or two lines since there was no error, at least you know where to start looking. ...The error messages are almost always cryptic because the compiler doesn't know what you're trying to do. But, the error message usually points to where the error is, or at least it usually points to a line near where the error is.

I'm not very familiar with programming

Are you familiar with electronics?

I agree completely with "one step at a time". That is not just advice for a beginner. That is how an experienced programmer will do it.

For each piece you don't know write a very short program to enable you to learn.
When you have all the parts working separately it will be time to start joining them together.

Have a look at planning and implementing a program. It illustrates how the whole program is a collection of small parts.

You will probably also find useful info in stepper motor basics and serial input basics. But don't try to take all this in at once. Take your time.

You should read stepper motor basics before you spend money on steppers and stepper drivers.

The techniques in serial input basics may also be relevant for receiving data wirelessly.

...R

Awesome advice! thanks. I think i was just intimidated by this project. So i took your guys' advice and modified some example code that came with the adafruit motor driver v2 library...some of the notes will probably be inaccurate...

/* 
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2 
---->	http://www.adafruit.com/products/1438
*/


#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor1 = AFMS.getStepper(200, 1);
Adafruit_StepperMotor *myMotor2 = AFMS.getStepper(200, 2);


void setup() {
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotor1->setSpeed(40);  // 40 rpm
  myMotor2->setSpeed(40);  
}

void loop() {
  int analogValueX = analogRead(X_pin);
  int analogValueY = analogRead(Y_pin);
  
  if (analogValueX > 530){
    myMotor1->step(2, FORWARD, INTERLEAVE);
  }

  if (analogValueX < 510){
  myMotor1->step(2, BACKWARD, INTERLEAVE); 
}

  if (analogValueY > 510){
  myMotor2->step(2, FORWARD, INTERLEAVE);
}

  else if (analogValueY < 490){
  myMotor2->step(2, BACKWARD, INTERLEAVE);
}

  //Code below will let you see the joystick's axis values on serial monitor
  //Serial.print("Switch:  ");
  //Serial.print(digitalRead(SW_pin));
  //Serial.print("\n");
  //Serial.print("X-axis: ");
  //Serial.print(analogRead(X_pin));
  //Serial.print("\n");
  //Serial.print("Y-axis: ");
  //Serial.println(analogRead(Y_pin));
  //Serial.print("\n\n");
  //delay(500);

}

So i can control the stepper motors with the analog joystick and I'm pretty happy with it, but it would be nice to make it wireless. there's a website that gives example code and instructions on how to make a NRF24L01 receiver and trasmitter, but its still very intimidating to me. if you have the time, check it out and see if it makes sense for what i want to do. much thanks for your time!

https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

Set up your wireless receiver and transmitter just so you can send and receive messages and display them on the Serial Monitor. When you have that figured out it will be time to consider how to use received data to control your motors and what the data content should be.

...R

thanks for all the help and advice. I'll try that