Show Posts
Pages: 1 2 [3] 4 5 6
31  Using Arduino / Project Guidance / Re: Servo control on: February 13, 2013, 03:05:03 am
I've modified the reciever arduino code a little. But not working still. Is it because there is something missing in the code or since I've not used Pull ups in tn the I2C bus? The servo keeps on rotating.

Code:
#include <Wire.h>
#include <Servo.h>

Servo myservo;
int pos = 0;

void setup()
{
  Wire.begin(4);               
  Wire.onReceive(receiveEvent);
  myservo.attach(9);
}

void loop()
{
  delay(100);
}

void receiveEvent(int howMany)
{
  pos = Wire.read();   
  myservo.write(pos);
}
32  Using Arduino / Project Guidance / Re: Servo control on: February 12, 2013, 02:26:12 pm
\until & unless the data over I2C is 0, it'll keep on reading & set that value to a variable x. This variable is then used to define the position of a servo
33  Using Arduino / Project Guidance / Re: Servo control on: February 12, 2013, 02:09:10 pm
Well I tried with both the low pass filter way & the  i2c way. low pass filter had some glitches. Sometimes it worked just fine. The system is not dependable for crucious moments. moving on to I2C.

The code for the arduino which will receive serail data from the Processing app is :

Code:
#include <Wire.h>

int data = 0;

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

void loop()
{
  while(Serial.available() == 0)
  {
    int data = Serial.read() - '0';
    Wire.beginTransmission(4);
    Wire.write(data);
    Wire.endTransmission();
    Serial.flush();
  }
  delay(50);
}

& the code for the arduino that is connected to the previous arduino with I2C & a servo is

Code:
#include <Wire.h>
#include <Servo.h>

Servo myservo;
int x = 0;

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  //Serial.begin(9600);
  myservo.attach(9);
}

void loop()
{
  //delay(100);
  myservo.write(x);
  //Servoflush();
}

void receiveEvent(int howMany)
{
  while( Wire.available() == 0) // loop through all but the last
  {
      x = Wire.read();    // receive byte as an intege
  }
}

The problem is the servo keeps on moving . Never stops & is not affected by the serial data coming over the first arduino.
I guess there is some random data like the -49 for the subtraction (- '0') that we are employing in the first arduino program is causing the problem. My best guess. Any more problems sorted out & fixable is needed. help again. smiley-sad 
34  Using Arduino / Programming Questions / Re: Serial communication querry on: February 12, 2013, 10:03:51 am
like 1-wire & i2C?
35  Using Arduino / Project Guidance / Re: Servo control on: February 12, 2013, 07:33:26 am
Searching for a while, i found these
http://arduino.cc/forum/index.php?topic=116015.0
where a similar problem was raised & a person suggested something like I thought with analog read & write ()s .
36  Using Arduino / Project Guidance / Re: Servo control on: February 12, 2013, 07:17:53 am
Code:
//-------------------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();
  }
}

Code:
//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();
}

Code:
//------------------------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);
  }
37  Using Arduino / Project Guidance / Re: Servo control on: February 12, 2013, 06:49:44 am
And more over, it would be just helpful if you could help me with the problem I raised here. This way you would be saved of a lot of burden. I need to know about the filtering as you said up there & modifying it in my code will help me better understand .
Thank you
38  Using Arduino / Project Guidance / Re: Servo control on: February 12, 2013, 06:45:53 am
I think I've given a link back up there about another discussion. It'll give you a better insight about what I'm up-to. please go through 'em
39  Using Arduino / Project Guidance / Re: Servo control on: February 12, 2013, 06:27:25 am
I'm new to this. So what shall exactly be done?
40  Using Arduino / Project Guidance / Re: Servo control on: February 12, 2013, 06:16:32 am
power will also be provided to the second arduino.
41  Using Arduino / Project Guidance / Servo control on: February 12, 2013, 06:13:36 am
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);
  }

42  Using Arduino / Programming Questions / Re: Serial communication querry on: February 12, 2013, 05:07:40 am
 If can I use the tilt value from the processing app to change set an analog PIN of arduino  with analoWrite() for  the corresponding tilt value coming over serial & connect that analog pin to another arduino's Same/Another Analog PIN. Then use the analogRead() to read the value coming over that PIN & set  position of 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.
 
43  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 02:45:19 pm
Thanks peter for the info. But can you follow that up by putting it & testing it a little bit in the first pair of sketches I sent? I would be a great help for me? Thanks in adv.
44  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 01:59:48 pm
In my code timer one's counting & timer three's interrupting. 
45  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 01:58:19 pm
Tried all the PWM pins & few analog pins. Didn't work. when I checked the servo.cpp, I found none of the AVR family use timer 2 . they use timer 1 & 3 only. then where's this coming from?
Pages: 1 2 [3] 4 5 6