Go Down

Topic: adding serial commands to code for remote control (Read 807 times) previous topic - next topic

capt_carroll

i am a noob and i have some code for my motors but i need help adding serial commands to it so i can transmit from one arduino to another for remote control of motors. could someone please help get me started in the right direction for both the transmitter and receiver, i would greatly appreciate the help.

Code: [Select]
#include <Stepper.h>

const int stepsPerRevolution = 64;

Stepper pan(stepsPerRevolution, 8,10,9,11);
Stepper tilt(stepsPerRevolution, 3,5,4,6);

void setup() {

  pan.setSpeed(300);
  tilt.setSpeed(300):
}


void loop() {
 
  int sensorReading = analogRead(A0); // X-axis

  if (sensorReading < 300) { pan.step(2); }   // left
  if (sensorReading > 800) { pan.step(-2); }  // right
 
  int sensorReading2 = analogRead(A1); // Y-axis

  if (sensorReading2 < 300) { tilt.step(2); } // down
  if (sensorReading2 > 800) { tilt.step(-2); } // up
   
   
}


thanks for your help

PaulS

Quote
but i need help adding serial commands to it so i can transmit from one arduino to another for remote control of motors.

Transmit how? How are the Arduino's connected?

Basically, the process is EXACTLY the same as transferring the data to the Serial Monitor, and there are billions of examples of how to do THAT around.


capt_carroll

http://gravitech.us/xbadforarna.html is the sheild im using with an adduino nano and xbees

PaulS

Quote
...is the sheild im using with an adduino nano and xbees

With that device, and properly configured XBees, it is a direct replacement for a wire. You'd program the Arduinos just as if they had a wire connecting them.

capt_carroll

That makes a little bit of sense but how you structure the code for the transmitter an receiver ? sorry am a complete noob when it comes to coding...

thanks

PaulS

Quote
sorry am a complete noob when it comes to coding...

There is a world of difference between being a noob and being to lazy to try something. There are, as I mentioned, a bazillion examples around of how to output serial data with a wire (USB cable, FTDI cable, whatever). There is NO difference in the code when you use XBees instead of a wire.

capt_carroll

agreed but there is also a difference between being lazy and seeking help because i simply dont understand the serial code tags if you will and due to previous failures i dont want to give up because it is rather interesting process.

PaulS

Quote
i simply dont understand the serial code tags if you will

I have no idea what you mean by "serial code tags". I can't believe that anyone gets past blinking an LED without being able to Serial.print("Some stupid crap");.

Reading serial data, on the other end, is a little harder, but not much.

But, you need to make some attempt, even if it falls flat on its face.

Go Up