Estou tentando controlar um servo no arduino pelo processing, até agora o código ficou assim:

//

import processing.serial.*;
import cc.arduino.*;
 
Arduino arduino;
int servo = 9;
 
void setup()
{
 println(Arduino.list());
 arduino = new Arduino(this, Arduino.list()[0], 57600);
 arduino.pinMode(servo, Arduino.SERVO);
}
 
void draw()
{
arduino.digitalWrite(servo,120);

arduino.digitalWrite(servo,140);
}

//

 Porém, o servo não se mexe... se o servo está em um angulo qualquer, quando eu aciono o processing ele zera o angulo e depois não move mais... como posso fazer isso?

Exibições: 694

Responder esta

Respostas a este tópico

Sugestões :

Faça um teste com Sketch ( IDE Arduino) primeiro, para ter certeza que a programação e as ligações estão corretas.

Ao invés de usar digitalWrite use analogWrite:

analogWrite(pin, value): writes an analog value (PWM wave) to a digital pin that supports it (pins 3, 5, 6, 9, 10, and 11); value should be from 0 (always off) to 255 (always on).

Referências :

https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing

http://www.seucurso.com.br/index.php?option=com_content&view=ar...

no arduino roda tudo bonitinho, isso foi um teste de migrat do arduino para o processing... e o analogWrite, não dá resultado...

Veja esse exemplo :

http://playground.arduino.cc/Learning/SingleServoExample

/**
* Servocontrol (derived from processing Mouse 1D example.)
*
* Updated 24 November 2007
*/


// Use the included processing code serial library
import processing.serial.*;


int gx = 15;
int gy = 35;
int spos=90;

float leftColor = 0.0;
float rightColor = 0.0;
Serial port; // The serial port

void setup()
{
size(720, 720);
colorMode(RGB, 1.0);
noStroke();
rectMode(CENTER);
frameRate(100);

println(Serial.list()); // List COM-ports

//select second com-port from the list
port = new Serial(this, Serial.list()[1], 19200);
}

void draw()
{
background(0.0);
update(mouseX);
fill(mouseX/4);
rect(150, 320, gx*2, gx*2);
fill(180 - (mouseX/4));
rect(450, 320, gy*2, gy*2);
}

void update(int x)
{
//Calculate servo postion from mouseX
spos= x/4;

//Output the servo position ( from 0 to 180)
port.write("s"+spos);

// Just some graphics
leftColor = -0.002 * x/2 + 0.06;
rightColor = 0.002 * x/2 + 0.06;

gx = x/2;
gy = 100-x/2;

}

Fantastico esse exemplo:

https://www.youtube.com/watch?v=KF_sBGWdCzI

Opa achei isso !

http://forum.processing.org/two/discussion/2469/servo-motor-arduino...

Qual versão do Processing esta usando ? Use a versão mais nova 2.2.1 !

https://www.processing.org/download/?processing

vou tentar! muito obrigado

por algum motivo o processing 2.2.1 não reconhece meu arduino :/

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço