Pages: [1]   Go Down
Author Topic: adding serial commands to code for remote control  (Read 536 times)
0 Members and 1 Guest are viewing this topic.
Fl
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Fl
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Via xbee radios
Logged

Fl
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Fl
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Fl
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 46000
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: