Go Down

Topic: Servo control (Read 1 time) previous topic - next topic

dattasaurabh82

Can I use the serial value from a processing app to change an analog PIN's value of arduino  with Serial.read() & analoWrite() & connect that analog pin to another arduino's Same/Another Analog PIN. Then use the analogRead() in the 2nd arduino to read the value coming over that PIN & set  position of a servo according to the value. Can it be done? I can use an ATtiny in that case to drive the servo separate. This way it won't have to be dependent on the RADAR-ARDUINO's timers. there's a reason I want to do that

http://arduino.cc/forum/index.php?topic=147742.new;topicseen#new.

When I tried this( sketches below), it didn't work.No motion in servo.

-------------------ARDUINO CODE----------------------
Arduino 1 code:

void setup()
{
 Serial.begin(9600);
}


void loop()
{
 while(Serial.available() == 0);
 {
   int pos = Serial.read() - '0';
   analogWrite(A0, pos);
   Serial.flush();
 }
}

--------------------------------------------------------------------------------------------
Arduino 2 code:

#include <Servo.h>

Servo myservo;

void setup()
{
 myservo.attach(9);
 Serial.begin(9600);
}


void loop()
{
 int data = analogRead(A0);
 Serial.println(data);
 myservo.write(data);
 //Servo.flush();
}

------------------------PROCESSING APPLET-------------------

code:

import processing.serial.*;
import controlP5.*;

Serial port;
ControlP5 cp5;

int tilt = 0;

void setup()
{
size(200, 200);

port = new Serial(this, "COM14", 9600);
//port.bufferUntil('\n');

cp5 = new ControlP5(this);

cp5.addSlider("tilt")
    .setPosition(88,7)
    .setSize(20,180)
    .setRange(0,180)
    .setValue(90)
    ;
}

void draw()
 {
   background(0);
   println(tilt);
   port.write(tilt);
 }


dattasaurabh82

power will also be provided to the second arduino.

AWOL

On anything but a Due, "analogWrite" modifies the duty cycle of a digital signal, so an "analogRead" of such a signal will not return the value expected, without filtering.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dattasaurabh82

I'm new to this. So what shall exactly be done?

AWOL

I have no idea - you've set out a method of doing something that isn't feasible, without saying what it is you want to do.

Quote
This way it won't have to be dependent on the RADAR-ARDUINO's timers.

Whatever that means.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up