Show Posts
Pages: 1 2 3 [4] 5 6
46  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);
  }

47  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.
 
48  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.
49  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. 
50  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?
51  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 01:46:34 pm
only one servo is to be controlled. As suggested I should check & change the pins as it might be using timer 2. timer 3 pins with PWM or ADC could be assigned. But where to check this thing in servo lib?
52  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 01:27:08 pm
And I don't have any extra port here as I'm using UNO R3. would it work if I use two different ports for servo & RAdar.Would it help me if I go for a mega?
53  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 01:25:03 pm
So how this shall be solved? Is there any way? Sorry but, I'm needing a solution here as I'm not much of into hardcore micro-controller stuffs.
And the parseInt link that's been forwarded to me, doesn't have any example code.
54  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 01:22:39 pm
comments are comments right? those are meant to check the speed results in the serial monitor.  
Now I'm just porting the frequency data to the port from the arduino & TRYING TO ACCEPept slider value from the port to the arduino.
I'm not that much High end with timers though. I explained my aim also that why i need those timer interrupts as then the radar won't work.
55  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 01:15:45 pm
It may be due to the timers or the bi directional communication. I tried to drive the servo from an simple UI of just slider & it worked.

--------------arduino code------------

#include <Servo.h>

Servo myservo;

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


void loop()
{
  while(Serial.available() == 0);
  {
  int pos = Serial.read() - '0';
  myservo.write(pos);
  Serial.flush();
  }
  }

------------processing code-------------

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

Serial port;
ControlP5 cp5;

int tilt = 0;

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

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

cp5 = new ControlP5(this);
cp5.addSlider("tilt")
     .setPosition(320, 0)
     .setSize(20,240)
     .setRange(0,180)
     .setValue(90)
     ;
}

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

.
56  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 01:01:38 pm
So is there any solution here? smiley-sad
57  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 12:59:26 pm
this is the code:
----------------new sketch-----------------

#include <Servo.h>

Servo myservo;

const uint16_t TICK_CNT = 3; // 255-(16MHz/1024/62Hz) 
static uint16_t freq = 0;
double sped = 0; //"speed" seems to be a reserved term


void setup()
{
  myservo.attach(9);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
 
  Serial.begin(115200);

  noInterrupts();                     // disable all interrupts while we configure 
  // init Timer1 - 16-bit timer/counter
  TCNT1   = 0;                                  // start count at zero.       
  TCCR1B  |= _BV(CS12) | _BV(CS11) | _BV(CS10); // Increment T1 input on each positive edge
                                                // using an external source. Table 16-5, pg 139.
 
  // init Timer2 - 8-bit timer/counter
  TCNT2   = TICK_CNT;                 // preload Timer2 to interrupt every 250 msec
  TIMSK2  = _BV(TOIE2);               // enable the Timer2 overflow interrupt
  TCCR2B  |= _BV(CS22) |_BV(CS21) | _BV(CS20);   // init clock prescaler to 1024. Table 18-9, page 164.
  interrupts();                       // enable all interrupts
 
  //Serial.println("Ready...");
}

ISR(TIMER1_OVF_vect) {
  // do nothing. this is just a dummy ISR in case it actually overflows.
  //Serial.println("Inside Timer1 Overflow Interrupt.");
}

ISR(TIMER2_OVF_vect) {
  //Serial.print("TCNT1: ");
  //Serial.println(TCNT1);
  freq = TCNT1;
  //Serial.println(freq);
  TCNT1 = 0;
  TCNT2 = TICK_CNT;
}

void loop()
{
  while(Serial.available() == 0);
  {
  int pos = Serial.read() - '0';
  myservo.write(pos);
  Serial.flush();
  }

  if (freq != 0)
  {
      freq = freq * 62;      // multiple the frequency * 4 (using leftshift 2 places). 250ms*4 = 1 sec.
      //sped = freq * .03225;  // multiplying freq * 0.03225 will give speed in mph. 31Hz == 1 mph.
                             // see: http://www.microwave-solutions.com/contents/en-uk/d13_System_Design.html
     // Serial.print("Freq: ");
      Serial.println(freq, DEC);
      //Serial.print(" Hz, Speed: ");
      //Serial.print(sped, 0);
      //Serial.println(" mph");
      freq = 0;
  }
}
58  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 12:54:31 pm
surely I even tried to do it by simply servo.write(the serial value).
it didn't work.
59  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 12:52:34 pm
i'm sorry for that.
Servo's not responding. even though when I ran an exemplary  "sweep" code just to check whether the servo's ok or not, it worked just fine.
60  Using Arduino / Programming Questions / Re: Serial communication querry on: February 11, 2013, 12:39:12 pm
umm smiley-confuse facing problem here!!

I've been playing with an X-Band radar & I've copy pasted a code from the forum only .

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

My aim is to get the serial data (the change in frequency data) to the processing app through serial communication where I'll visualize it in cool graphics. Along with it I would implant a webcam(To snap the pics of those passing by). Now I want to control the tilting of the webcam through a slider from the app. The whole communication goes at 115200 bps(Can't change it for timer concerns).

-----------------Arduino code------------------------
Code:
#include <Servo.h>

Servo myservo;

const uint16_t TICK_CNT = 3; // 255-(16MHz/1024/62Hz)  
static uint16_t freq = 0;
double sped = 0; //"speed" seems to be a reserved term


void setup()
{
  myservo.attach(9);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  
  Serial.begin(115200);

  noInterrupts();                     // disable all interrupts while we configure  
  // init Timer1 - 16-bit timer/counter
  TCNT1   = 0;                                  // start count at zero.        
  TCCR1B  |= _BV(CS12) | _BV(CS11) | _BV(CS10); // Increment T1 input on each positive edge
                                                // using an external source. Table 16-5, pg 139.
  
  // init Timer2 - 8-bit timer/counter
  TCNT2   = TICK_CNT;                 // preload Timer2 to interrupt every 250 msec
  TIMSK2  = _BV(TOIE2);               // enable the Timer2 overflow interrupt
  TCCR2B  |= _BV(CS22) |_BV(CS21) | _BV(CS20);   // init clock prescaler to 1024. Table 18-9, page 164.
  interrupts();                       // enable all interrupts
  
  //Serial.println("Ready...");
}

ISR(TIMER1_OVF_vect) {
  // do nothing. this is just a dummy ISR in case it actually overflows.
  //Serial.println("Inside Timer1 Overflow Interrupt.");
}

ISR(TIMER2_OVF_vect) {
  //Serial.print("TCNT1: ");
  //Serial.println(TCNT1);
  freq = TCNT1;
  //Serial.println(freq);
  TCNT1 = 0;
  TCNT2 = TICK_CNT;
}

void loop()
{
  while(Serial.available() == 0);
  {
  int data = Serial.read() - '0';
  int pos = map(data, 0, 180, 0, 180);
  pos = constrain(pos, 0, 180);
  myservo.write(pos);
  Serial.flush();
  }
  if (freq != 0)
  {
      freq = freq * 62;      // multiple the frequency * 4 (using leftshift 2 places). 250ms*4 = 1 sec.
      //sped = freq * .03225;  // multiplying freq * 0.03225 will give speed in mph. 31Hz == 1 mph.
                             // see: http://www.microwave-solutions.com/contents/en-uk/d13_System_Design.html
     // Serial.print("Freq: ");
      Serial.println(freq, DEC);
      //Serial.print(" Hz, Speed: ");
      //Serial.print(sped, 0);
      //Serial.println(" mph");
      freq = 0;
  }
}

------------------processing code----------------------------
Code:
import processing.serial.*;
import codeanticode.gsvideo.*;
import controlP5.*;

PFont fontB;

GSCapture cam;
Serial port;
ControlP5 cp5;

int id = 1;
int freq = 0;
float velocity = 0.00;
int tilt = 0;

void setup()
{
size(680, 420);

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

String[] cameras = GSCapture.list();

fontB = loadFont("ArialMT-48.vlw");
textFont(fontB, 48);

if (cameras.length == 0)
  {
    println("There are no cameras available for capture.");
    exit();
  }
  else
  {
    println("Available cameras:");
    
    for (int i = 0; i < cameras.length; i++)
    {
      println(cameras[i]);
    }
    
    cam = new GSCapture(this, 320, 240, cameras[0]);
    cam.start();  
    }
  
cp5 = new ControlP5(this);

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

void draw()
  {
    if (cam.available() == true)
    {
    background(0);
    
    cam.read();
    image(cam, 0, 0);
    
    fill(255);
    text(velocity, 350, 350);
    text("mph", 500, 350);
    println(tilt);
    port.write(tilt);
    
    }
  }

void serialEvent (Serial port)
{
  String inString = port.readStringUntil('\n');//reading from serial data until new line
  
   if (inString != null)
 {
  //conversion of the string into integer
  inString = trim(inString);
  freq = int(inString);
  velocity = (freq * .03225)-1.9994999;
  
  if(velocity == 1.9994999)
    {
      velocity = 0.00;
    }
  }
}

help!!! smiley-cry


Moderator edit: [code] [/code] tags added.
Pages: 1 2 3 [4] 5 6