Je suis nouveaux sur ce Forum , je m'appelle Dylan et j'ai 17 ans. Je suis en Terminale.
Aujourd'hui je vais avoir besoin de votre aide ! car mon professeur de technologie nous a annoncer que nous allons realiser un robot comme projet. Ensuite il a dit que si on voulait ( ceux qui etait interesse) pouvaient realiser un robot chez eux et ensuite le ramener a l'ecole pour recevoir une note !! Donc j'ai jusqu'en Avril pour finir mon robot que j'ai deja commence.Mon robot n'est pas encore finis. C'est en fait une plateforme qui possede 2 servomoteurs 360* a l'arriere et une roue folle a l'avant. Dessus sera visse un bras robotique avec une pince au bout (total 5 moteurs + 2 servomoteurs) . Tout ceci sera pilote VIA Bluetooth par mon ordianteur (Clavier) Mais malheureusement je fais du sur place , d'un cote avec le code de la pince que je n'arrive pas a trouver l'erreur et l'autre avec le module Bluetooth et les servomoteurs toujours pas acheter.
Est ce que quelqu'un pourrais m'eclairer pour mon code qui ne fonctionne pas ? j'ai une erreur dans processing , mais ou ca ?
Je vous remerci d'avance esperant avoir des reponses rapidement.
Bonne soiree a tous !
code Arduino :
// set the output pins
// 14-18 are actually analog pins 0-4
int baseMotorEnablePin = 2;
int baseMotorPin1 = 3;
int baseMotorPin2 = 4;
int shoulderMotorEnablePin = 5;
int shoulderMotorPin1 = 6;
int shoulderMotorPin2 = 7;
int elbowMotorEnablePin = 11;
int elbowMotorPin1 = 12;
int elbowMotorPin2 = 13;
int wristMotorEnablePin = A0;
int wristMotorPin1 = A1;
int wristMotorPin2 = A2;
int handMotorEnablePin = 8;
int handMotorPin1 = 9;
int handMotorPin2 = 10;
int LedBlanche = 52;
// set a variable to store the byte sent from the serial port
int incomingByte;
void setup() {
// set the SN754410 pins as outputs:
pinMode(baseMotorPin1, OUTPUT);
pinMode(baseMotorPin2, OUTPUT);
pinMode(baseMotorEnablePin, OUTPUT);
digitalWrite(baseMotorEnablePin, HIGH);
pinMode(shoulderMotorPin1, OUTPUT);
pinMode(shoulderMotorPin2, OUTPUT);
pinMode(shoulderMotorEnablePin, OUTPUT);
digitalWrite(shoulderMotorEnablePin, HIGH);
pinMode(elbowMotorPin1, OUTPUT);
pinMode(elbowMotorPin2, OUTPUT);
pinMode(elbowMotorEnablePin, OUTPUT);
digitalWrite(elbowMotorEnablePin, HIGH);
pinMode(wristMotorPin1, OUTPUT);
pinMode(wristMotorPin2, OUTPUT);
pinMode(wristMotorEnablePin, OUTPUT);
digitalWrite(wristMotorEnablePin, HIGH);
pinMode(handMotorPin1, OUTPUT);
pinMode(handMotorPin2, OUTPUT);
pinMode(handMotorEnablePin, OUTPUT);
digitalWrite(handMotorEnablePin, HIGH);
pinMode(LedBlanche, OUTPUT);
// start sending data at 9600 baud rate
Serial.begin(9600);
}
void loop() {
// check that there's something in the serial buffer
if (Serial.available() > 0) {
// read the byte and store it in our variable
// the byte sent is actually an ascii value
incomingByte = Serial.read();
// note the upper casing of each letter!
// each letter turns a motor different way.
if (incomingByte == 'Q') {
digitalWrite(baseMotorPin1, LOW);
digitalWrite(baseMotorPin2, HIGH);
digitalWrite(LedBlanche, LOW);
}
if (incomingByte == 'W') {
digitalWrite(baseMotorPin1, HIGH);
digitalWrite(baseMotorPin2, LOW);
digitalWrite(LedBlanche, LOW);
}
if (incomingByte == 'E') {
digitalWrite(shoulderMotorPin1, LOW);
digitalWrite(shoulderMotorPin2, HIGH);
digitalWrite(LedBlanche, LOW);
}
if (incomingByte == 'R') {
digitalWrite(shoulderMotorPin1, HIGH);
digitalWrite(shoulderMotorPin2, LOW);
digitalWrite(LedBlanche, LOW);
}
if (incomingByte == 'A') {
digitalWrite(elbowMotorPin1, LOW);
digitalWrite(elbowMotorPin2, HIGH);
digitalWrite(LedBlanche, LOW);
}
if (incomingByte == 'S') {
digitalWrite(elbowMotorPin1, HIGH);
digitalWrite(elbowMotorPin2, LOW);
digitalWrite(LedBlanche, LOW);
}
if (incomingByte == 'D') {
digitalWrite(wristMotorPin1, LOW);
digitalWrite(wristMotorPin2, HIGH);
digitalWrite(LedBlanche, HIGH);
}
if (incomingByte == 'F') {
digitalWrite(wristMotorPin1, HIGH);
digitalWrite(wristMotorPin2, LOW);
digitalWrite(LedBlanche, HIGH);
}
if (incomingByte == 'Z') {
digitalWrite(handMotorPin1, LOW);
digitalWrite(handMotorPin2, HIGH);
digitalWrite(LedBlanche, LOW);
}
if (incomingByte == 'X') {
digitalWrite(handMotorPin1, HIGH);
digitalWrite(handMotorPin2, LOW);
digitalWrite(LedBlanche, LOW);
}
// if a O is sent make sure the motors are turned off
if (incomingByte == 'O') {
digitalWrite(baseMotorPin1, LOW);
digitalWrite(baseMotorPin2, LOW);
digitalWrite(shoulderMotorPin1, LOW);
digitalWrite(shoulderMotorPin2, LOW);
digitalWrite(elbowMotorPin1, LOW);
digitalWrite(elbowMotorPin2, LOW);
digitalWrite(wristMotorPin1, LOW);
digitalWrite(wristMotorPin2, LOW);
digitalWrite(handMotorPin1, LOW);
digitalWrite(handMotorPin2, LOW);
digitalWrite(LedBlanche, LOW);
}
}
}
Code proceesing :
// Language: Arduino
// RobotArmControl.pde
//
// by Sam Thongrong Feb 26, 2012
// rev.02
// control commands array:
// {GripOut, GripIn, WristUp, WristDown, ElbowUp, ElbowDown,
// ShoulderUp, shoulderDown, BaseCW, BaseCCW, LightOn, LightOff, Stop};
int controls[13] = { 0x47, 0x67, 0x57, 0x77, 0x45, 0x65,
0x53, 0x73, 0x42, 0x62, 0x4c, 0x6c, 0x58 };
// Base
int baseEnablePin = 3;
int basePin1 = 16;
int basePin2 = 17;
// Shoulder
int shoulderEnablePin = 14;
int shoulderPin1 = 2;
int shoulderPin2 = 4;
// Elbow
int elbowEnablePin = 6;
int elbowPin1 = 7;
int elbowPin2 = 15;
// Wrist
int wristEnablePin = 11;
int wristPin1 = 8;
int wristPin2 = 12;
//Grip
int gripEnablePin = 10;
int gripPin1 = 9;
int gripPin2 = 5;
int ledPin = 13;
// set a variable to store the byte sent from the serial port
int incomingByte;
void setup() {
// set light LED
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// set the SN754410 pins as outputs:
pinMode(basePin1, OUTPUT);
pinMode(basePin2, OUTPUT);
pinMode(baseEnablePin, OUTPUT);
pinMode(shoulderPin1, OUTPUT);
pinMode(shoulderPin2, OUTPUT);
pinMode(shoulderEnablePin, OUTPUT);
pinMode(elbowPin1, OUTPUT);
pinMode(elbowPin2, OUTPUT);
pinMode(elbowEnablePin, OUTPUT);
pinMode(wristPin1, OUTPUT);
pinMode(wristPin2, OUTPUT);
pinMode(wristEnablePin, OUTPUT);
pinMode(gripPin1, OUTPUT);
pinMode(gripPin2, OUTPUT);
pinMode(gripEnablePin, OUTPUT);
// start sending data at 115200 baud rate
// I set my Xbee Baud Rate at 115200 bps,
// change the Baud Rate according to your XBee
Serial.begin(115200);
}
void loop() {
// check that there's something in the serial buffer
if (Serial.available() > 0) {
// read the byte and store it in our variable
// the byte sent is actually an ascii value
incomingByte = Serial.read();
// note the upper casing of each letter!
// each letter turns a motor different way.
//===== Grip
// Grip in
if (incomingByte == controls[0]) {
gripIn();
}
// Grip Out
if (incomingByte == controls[1]) {
gripOut();
}
//Wrist
if (incomingByte == controls[2]) {
//digitalWrite(wristPin1, LOW);
//digitalWrite(wristPin2, HIGH);
wristUp();
}
if (incomingByte == controls[3]) {
wristDown();
}
//===== Elbow
// Elbow Up
if (incomingByte == controls[4]) {
elbowUp();
}
// Elbow Down
if (incomingByte == controls[5]) {
elbowDown();
}
//===== Shoulder
// Shoulder Up
if (incomingByte == controls[6]) {
shoulderUp();
}
// Shoulder Down
if (incomingByte == controls[7]) {
shoulderDown();
}
//===== Base
// Base Right
if (incomingByte == controls[8]) {
baseRight();
}
// Base Left
if (incomingByte == controls[9]) {
baseLeft();
}
// Light ON
if (incomingByte == controls[10]) {
digitalWrite(ledPin, HIGH);
}
// Light OFF
if (incomingByte == controls[11]) {
digitalWrite(ledPin, LOW);
}
// if a O is sent make sure the motors are turned off
if (incomingByte == controls[12]) {
allStop();
}
delay(100);
}
}
void gripIn() {
digitalWrite(gripEnablePin, HIGH);
digitalWrite(gripPin1, LOW);
digitalWrite(gripPin2, HIGH);
}
void gripOut() {
digitalWrite(gripEnablePin, HIGH);
digitalWrite(gripPin2, LOW);
digitalWrite(gripPin1, HIGH);
}
void wristUp() {
digitalWrite(wristEnablePin, HIGH);
digitalWrite(wristPin1, LOW);
digitalWrite(wristPin2, HIGH);
}
void wristDown() {
digitalWrite(wristEnablePin, HIGH);
digitalWrite(wristPin2, LOW);
digitalWrite(wristPin1, HIGH);
}
void elbowUp() {
digitalWrite(elbowEnablePin, HIGH);
digitalWrite(elbowPin1, LOW);
digitalWrite(elbowPin2, HIGH);
}
void elbowDown() {
digitalWrite(elbowEnablePin, HIGH);
digitalWrite(elbowPin2, LOW);
digitalWrite(elbowPin1, HIGH);
}
void shoulderUp() {
digitalWrite(shoulderEnablePin, HIGH);
digitalWrite(shoulderPin1, LOW);
digitalWrite(shoulderPin2, HIGH);
}
void shoulderDown() {
digitalWrite(shoulderEnablePin, HIGH);
digitalWrite(shoulderPin2, LOW);
digitalWrite(shoulderPin1, HIGH);
}
void baseRight() {
digitalWrite(baseEnablePin, HIGH);
digitalWrite(basePin1, LOW);
digitalWrite(basePin2, HIGH);
}
void baseLeft() {
digitalWrite(baseEnablePin, HIGH);
digitalWrite(basePin2, LOW);
digitalWrite(basePin1, HIGH);
}
void allStop() {
digitalWrite(baseEnablePin, LOW);
digitalWrite(basePin1, LOW);
digitalWrite(basePin2, LOW);
digitalWrite(shoulderEnablePin, LOW);
digitalWrite(shoulderPin1, LOW);
digitalWrite(shoulderPin2, LOW);
digitalWrite(elbowEnablePin, LOW);
digitalWrite(elbowPin1, LOW);
digitalWrite(elbowPin2, LOW);
digitalWrite(wristEnablePin, LOW);
digitalWrite(wristPin1, LOW);
digitalWrite(wristPin2, LOW);
digitalWrite(gripEnablePin, LOW);
digitalWrite(gripPin1, LOW);
digitalWrite(gripPin2, LOW);
}
Stable Library ========================================= Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 Stable Library ========================================= Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 java.lang.NullPointerException at processing.serial.Serial.write(Unknown Source) at sketch_121202a.sendCommands(sketch_121202a.java:261) at sketch_121202a.draw(sketch_121202a.java:322) at processing.core.PApplet.handleDraw(PApplet.java:2128) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190) at processing.core.PApplet.run(PApplet.java:2006) at java.lang.Thread.run(Thread.java:662) Exception in thread "Animation Thread" java.lang.RuntimeException: Error inside Serial.write() at processing.serial.Serial.errorMessage(Unknown Source) at processing.serial.Serial.write(Unknown Source) at sketch_121202a.sendCommands(sketch_121202a.java:261) at sketch_121202a.draw(sketch_121202a.java:322) at processing.core.PApplet.handleDraw(PApplet.java:2128) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190) at processing.core.PApplet.run(PApplet.java:2006) at java.lang.Thread.run(Thread.java:662)
je pense que l'erreur vient de ma liaison série avec le bras. Car il est ecris :
"java.lang.NullPointerException at processing.serial.Serial.write(Unknown Source)"
Au mon Dieu quelle honte ..... je suis vraiment idiot , je me suis tromper de code. C'est celui que j'avais tester il y'a 4 mois et qui ne marche pas. Je suis vraiment desole.
les bons codes sont ceux la :
Arduino
/* controls each motor in an Edge Robotic Arm using data sent from a Processing Sketch luckylarry.co.uk
*/ // set the output pins // 14-18 are actually analog pins 0-4 int baseMotorEnablePin = 2; int baseMotorPin1 = 3; int baseMotorPin2 = 4; int shoulderMotorEnablePin = 14; int shoulderMotorPin1 = 15; int shoulderMotorPin2 = 16; int elbowMotorEnablePin = 8; int elbowMotorPin1 = 9; int elbowMotorPin2 = 10; int wristMotorEnablePin = 5; int wristMotorPin1 = 6; int wristMotorPin2 = 7; int handMotorEnablePin = 11; int handMotorPin1 = 17; int handMotorPin2 = 18; // set a variable to store the byte sent from the serial port int incomingByte;
void loop() { // check that there's something in the serial buffer if (Serial.available() > 0) { // read the byte and store it in our variable // the byte sent is actually an ascii value incomingByte = Serial.read(); // note the upper casing of each letter! // each letter turns a motor different way. if (incomingByte == 'Q') { digitalWrite(baseMotorPin1, LOW); digitalWrite(baseMotorPin2, HIGH); } if (incomingByte == 'W') { digitalWrite(baseMotorPin1, HIGH); digitalWrite(baseMotorPin2, LOW); } if (incomingByte == 'E') { digitalWrite(shoulderMotorPin1, LOW); digitalWrite(shoulderMotorPin2, HIGH); } if (incomingByte == 'R') { digitalWrite(shoulderMotorPin1, HIGH); digitalWrite(shoulderMotorPin2, LOW); } if (incomingByte == 'A') { digitalWrite(elbowMotorPin1, LOW); digitalWrite(elbowMotorPin2, HIGH); } if (incomingByte == 'S') { digitalWrite(elbowMotorPin1, HIGH); digitalWrite(elbowMotorPin2, LOW); } if (incomingByte == 'D') { digitalWrite(wristMotorPin1, LOW); digitalWrite(wristMotorPin2, HIGH); } if (incomingByte == 'F') { digitalWrite(wristMotorPin1, HIGH); digitalWrite(wristMotorPin2, LOW); } if (incomingByte == 'Z') { digitalWrite(handMotorPin1, LOW); digitalWrite(handMotorPin2, HIGH); } if (incomingByte == 'X') { digitalWrite(handMotorPin1, HIGH); digitalWrite(handMotorPin2, LOW); } // if a O is sent make sure the motors are turned off if (incomingByte == 'O') { digitalWrite(baseMotorPin1, LOW); digitalWrite(baseMotorPin2, LOW); digitalWrite(shoulderMotorPin1, LOW); digitalWrite(shoulderMotorPin2, LOW); digitalWrite(elbowMotorPin1, LOW); digitalWrite(elbowMotorPin2, LOW); digitalWrite(wristMotorPin1, LOW); digitalWrite(wristMotorPin2, LOW); digitalWrite(handMotorPin1, LOW); digitalWrite(handMotorPin2, LOW); } } }
Processing
/* Processing sketch that send a ascii byte character to Arduino which then subsquentally controls a motor luckylarry.co.uk
*/
// load the serial library for Processing import processing.serial.*; // instance of the serial class Serial port; // values to store X, Y for each button int M1LX, M1RX, M2LX, M2RX, M3LX, M3RX, M4LX, M4RX, M5LX, M5RX; int M1LY, M1RY, M2LY, M2RY, M3LY, M3RY, M4LY, M4RY, M5LY, M5RY; // stores the width/height of the box int boxSize = 64; // 2 new instances of my arrow class // also set an array of coordinates for each arrow arrow myRightArrow; int[]rightArrowxpoints={30,54,30,30,0,0,30}; int[]rightArrowypoints={0,27,54,40,40,15,15}; arrow myLeftArrow; int[]leftArrowxpoints={0,24,24,54,54,24,24}; int[]leftArrowypoints={27,0,15,15,40,40,54}; // set the font PFont myFont;
void setup() { // screen size of the program size(145, 455); // set the coordinates of each button box // base motor M1LX = Motor 1 Left X etc.. M1LX = 5; M1LY = 25; M1RX = 75; M1RY = 25; // shoulder motor M2LX = 5; M2LY = 115; M2RX = 75; M2RY = 115; // elbow motor M3LX = 5; M3LY = 205; M3RX = 75; M3RY = 205; // wrist motor M4LX = 5; M4LY = 295; M4RX = 75; M4RY = 295; // hand motor M5LX = 5; M5LY = 385; M5RX = 75; M5RY = 385;
// List all the available serial ports in the output pane. // You will need to choose the port that the Arduino board is // connected to from this list. The first port in the list is // port #0 and the third port in the list is port #2. println(Serial.list()); // set the font to use myFont = createFont("verdana", 12); textFont(myFont); // Open the port that the Arduino board is connected to (in this case #0) // Make sure to open the port at the same speed Arduino is using (9600bps) port = new Serial(this, Serial.list()[1], 9600); // create the base arrow myRightArrow = new arrow(rightArrowxpoints,rightArrowypoints,7); myLeftArrow = new arrow(leftArrowxpoints,leftArrowypoints,7); }
void draw() { background(0); noStroke(); fill(150); // draw each box/ button with a label above each text("Base Motor (Q/W)", 5, 5, 200, 75); text("Shoulder Motor (E/R)", 5, 95, 200, 75); text("Elbow Motor (A/S)", 5, 185, 200, 75); text("Wrist Motor (D/F)", 5, 275, 200, 75); text("Hand Motor (Z/X)", 5, 365, 200, 75);
// start looking to see whats pressed and send a value // over the serial port if(keyPressed) { if (key == 'q' || key == 'Q') { port.write('Q'); } if (key == 'w' || key == 'W') { port.write('W'); } if (key == 'e' || key == 'E') { port.write('E'); } if (key == 'r' || key == 'R') { port.write('R'); } if (key == 'a' || key == 'A') { port.write('A'); } if (key == 's' || key == 'S') { port.write('S'); } if (key == 'd' || key == 'D') { port.write('D'); } if (key == 'f' || key == 'F') { port.write('F'); } if (key == 'z' || key == 'Z') { port.write('Z'); } if (key == 'x' || key == 'X') { port.write('X'); } } // if no key is pressed check to see if the mouse button is pressed else if (mousePressed == true) { // check to see if the mouse is inside each box/ button if so send the value if (mouseX > M1LX-boxSize && mouseX < M1LX+boxSize && mouseY > M1LY-boxSize && mouseY < M1LY+boxSize) { port.write('Q'); } else if(mouseX > M1RX-boxSize && mouseX < M1RX+boxSize && mouseY > M1RY-boxSize && mouseY < M1RY+boxSize) { port.write('W'); } else if(mouseX > M2LX-boxSize && mouseX < M2LX+boxSize && mouseY > M2LY-boxSize && mouseY < M2LY+boxSize) { port.write('E'); } else if(mouseX > M2RX-boxSize && mouseX < M2RX+boxSize && mouseY > M2RY-boxSize && mouseY < M2RY+boxSize) { port.write('R'); } else if(mouseX > M3LX-boxSize && mouseX < M3LX+boxSize && mouseY > M3LY-boxSize && mouseY < M3LY+boxSize) { port.write('A'); } else if(mouseX > M3RX-boxSize && mouseX < M3RX+boxSize && mouseY > M3RY-boxSize && mouseY < M3RY+boxSize) { fill(200); port.write('S'); } else if (mouseX > M4LX-boxSize && mouseX < M4LX+boxSize && mouseY > M4LY-boxSize && mouseY < M4LY+boxSize) { port.write('D'); } else if(mouseX > M4RX-boxSize && mouseX < M4RX+boxSize && mouseY > M4RY-boxSize && mouseY < M4RY+boxSize) { port.write('F'); } else if (mouseX > M5LX-boxSize && mouseX < M5LX+boxSize && mouseY > M5LY-boxSize && mouseY < M5LY+boxSize) { port.write('Z'); } else if(mouseX > M5RX-boxSize && mouseX < M5RX+boxSize && mouseY > M5RY-boxSize && mouseY < M5RY+boxSize) { port.write('X'); } else { // if the mouse is pressed but not with in a box make sure nothings moving port.write('O'); } } else { // no key or mouse press then make sure nothings moving. port.write('O'); }
class arrow extends java.awt.Polygon { /* our class is basically an instance of java.awt.Polygons and this class expects and array of X points, Y points and the number of points in our shape. The variable names also have to be direct references to what this class expects, so xpoints, ypoints and npoints are all set/defined in the java class. */ public arrow(int[] xpoints,int[] ypoints, int npoints) { // super invokes the java.awt.Polygon class super(xpoints,ypoints,npoints);
} // supply offsets to draw the arrow, means I don't need to set points for each one void drawArrow(int xOffset, int yOffset){ fill(150); rect(xOffset-5, yOffset-5, boxSize, boxSize); fill(255); beginShape(); for(int i=0;i<npoints;i++){ vertex(xpoints[i]+xOffset,ypoints[i]+yOffset); } endShape(); } }
// set the output pins
// 14-18 are actually analog pins 0-4
int baseMotorEnablePin = 2;
int baseMotorPin1 = 3;
int baseMotorPin2 = 4;
int shoulderMotorEnablePin = 14;
int shoulderMotorPin1 = 15;
int shoulderMotorPin2 = 16;
int elbowMotorEnablePin = 8;
int elbowMotorPin1 = 9;
int elbowMotorPin2 = 10;
int wristMotorEnablePin = 5;
int wristMotorPin1 = 6;
int wristMotorPin2 = 7;
int handMotorEnablePin = 11;
int handMotorPin1 = 17;
int handMotorPin2 = 18;
// set a variable to store the byte sent from the serial port
int incomingByte;
void setup() {
// set the SN754410 pins as outputs:
pinMode(baseMotorPin1, OUTPUT);
pinMode(baseMotorPin2, OUTPUT);
pinMode(baseMotorEnablePin, OUTPUT);
digitalWrite(baseMotorEnablePin, HIGH);
pinMode(shoulderMotorPin1, OUTPUT);
pinMode(shoulderMotorPin2, OUTPUT);
pinMode(shoulderMotorEnablePin, OUTPUT);
digitalWrite(shoulderMotorEnablePin, HIGH);
pinMode(elbowMotorPin1, OUTPUT);
pinMode(elbowMotorPin2, OUTPUT);
pinMode(elbowMotorEnablePin, OUTPUT);
digitalWrite(elbowMotorEnablePin, HIGH);
pinMode(wristMotorPin1, OUTPUT);
pinMode(wristMotorPin2, OUTPUT);
pinMode(wristMotorEnablePin, OUTPUT);
digitalWrite(wristMotorEnablePin, HIGH);
pinMode(handMotorPin1, OUTPUT);
pinMode(handMotorPin2, OUTPUT);
pinMode(handMotorEnablePin, OUTPUT);
digitalWrite(handMotorEnablePin, HIGH);
// start sending data at 9600 baud rate
Serial.begin(9600);
}
void loop() {
// check that there's something in the serial buffer
if (Serial.available() > 0) {
// read the byte and store it in our variable
// the byte sent is actually an ascii value
incomingByte = Serial.read();
// note the upper casing of each letter!
// each letter turns a motor different way.
if (incomingByte == 'Q') {
digitalWrite(baseMotorPin1, LOW);
digitalWrite(baseMotorPin2, HIGH);
}
if (incomingByte == 'W') {
digitalWrite(baseMotorPin1, HIGH);
digitalWrite(baseMotorPin2, LOW);
}
if (incomingByte == 'E') {
digitalWrite(shoulderMotorPin1, LOW);
digitalWrite(shoulderMotorPin2, HIGH);
}
if (incomingByte == 'R') {
digitalWrite(shoulderMotorPin1, HIGH);
digitalWrite(shoulderMotorPin2, LOW);
}
if (incomingByte == 'A') {
digitalWrite(elbowMotorPin1, LOW);
digitalWrite(elbowMotorPin2, HIGH);
}
if (incomingByte == 'S') {
digitalWrite(elbowMotorPin1, HIGH);
digitalWrite(elbowMotorPin2, LOW);
}
if (incomingByte == 'D') {
digitalWrite(wristMotorPin1, LOW);
digitalWrite(wristMotorPin2, HIGH);
}
if (incomingByte == 'F') {
digitalWrite(wristMotorPin1, HIGH);
digitalWrite(wristMotorPin2, LOW);
}
if (incomingByte == 'Z') {
digitalWrite(handMotorPin1, LOW);
digitalWrite(handMotorPin2, HIGH);
}
if (incomingByte == 'X') {
digitalWrite(handMotorPin1, HIGH);
digitalWrite(handMotorPin2, LOW);
}
// if a O is sent make sure the motors are turned off
if (incomingByte == 'O') {
digitalWrite(baseMotorPin1, LOW);
digitalWrite(baseMotorPin2, LOW);
digitalWrite(shoulderMotorPin1, LOW);
digitalWrite(shoulderMotorPin2, LOW);
digitalWrite(elbowMotorPin1, LOW);
digitalWrite(elbowMotorPin2, LOW);
digitalWrite(wristMotorPin1, LOW);
digitalWrite(wristMotorPin2, LOW);
digitalWrite(handMotorPin1, LOW);
digitalWrite(handMotorPin2, LOW);
}
}
}
Processing
// load the serial library for Processing
import processing.serial.*;
// instance of the serial class
Serial port;
// values to store X, Y for each button
int M1LX, M1RX, M2LX, M2RX, M3LX, M3RX, M4LX, M4RX, M5LX, M5RX;
int M1LY, M1RY, M2LY, M2RY, M3LY, M3RY, M4LY, M4RY, M5LY, M5RY;
// stores the width/height of the box
int boxSize = 64;
// 2 new instances of my arrow class
// also set an array of coordinates for each arrow
arrow myRightArrow;
int[]rightArrowxpoints={30,54,30,30,0,0,30};
int[]rightArrowypoints={0,27,54,40,40,15,15};
arrow myLeftArrow;
int[]leftArrowxpoints={0,24,24,54,54,24,24};
int[]leftArrowypoints={27,0,15,15,40,40,54};
// set the font
PFont myFont;
void setup() {
// screen size of the program
size(145, 455);
// set the coordinates of each button box
// base motor M1LX = Motor 1 Left X etc..
M1LX = 5;
M1LY = 25;
M1RX = 75;
M1RY = 25;
// shoulder motor
M2LX = 5;
M2LY = 115;
M2RX = 75;
M2RY = 115;
// elbow motor
M3LX = 5;
M3LY = 205;
M3RX = 75;
M3RY = 205;
// wrist motor
M4LX = 5;
M4LY = 295;
M4RX = 75;
M4RY = 295;
// hand motor
M5LX = 5;
M5LY = 385;
M5RX = 75;
M5RY = 385;
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
println(Serial.list());
// set the font to use
myFont = createFont("verdana", 12);
textFont(myFont);
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[1], 9600);
// create the base arrow
myRightArrow = new arrow(rightArrowxpoints,rightArrowypoints,7);
myLeftArrow = new arrow(leftArrowxpoints,leftArrowypoints,7);
}
void draw()
{
background(0);
noStroke();
fill(150);
// draw each box/ button with a label above each
text("Base Motor (Q/W)", 5, 5, 200, 75);
text("Shoulder Motor (E/R)", 5, 95, 200, 75);
text("Elbow Motor (A/S)", 5, 185, 200, 75);
text("Wrist Motor (D/F)", 5, 275, 200, 75);
text("Hand Motor (Z/X)", 5, 365, 200, 75);
// start looking to see whats pressed and send a value
// over the serial port
if(keyPressed) {
if (key == 'q' || key == 'Q') {
port.write('Q');
}
if (key == 'w' || key == 'W') {
port.write('W');
}
if (key == 'e' || key == 'E') {
port.write('E');
}
if (key == 'r' || key == 'R') {
port.write('R');
}
if (key == 'a' || key == 'A') {
port.write('A');
}
if (key == 's' || key == 'S') {
port.write('S');
}
if (key == 'd' || key == 'D') {
port.write('D');
}
if (key == 'f' || key == 'F') {
port.write('F');
}
if (key == 'z' || key == 'Z') {
port.write('Z');
}
if (key == 'x' || key == 'X') {
port.write('X');
}
}
// if no key is pressed check to see if the mouse button is pressed
else if (mousePressed == true) {
// check to see if the mouse is inside each box/ button if so send the value
if (mouseX > M1LX-boxSize && mouseX < M1LX+boxSize &&
mouseY > M1LY-boxSize && mouseY < M1LY+boxSize) {
port.write('Q');
}
else if(mouseX > M1RX-boxSize && mouseX < M1RX+boxSize &&
mouseY > M1RY-boxSize && mouseY < M1RY+boxSize) {
port.write('W');
}
else if(mouseX > M2LX-boxSize && mouseX < M2LX+boxSize &&
mouseY > M2LY-boxSize && mouseY < M2LY+boxSize) {
port.write('E');
}
else if(mouseX > M2RX-boxSize && mouseX < M2RX+boxSize &&
mouseY > M2RY-boxSize && mouseY < M2RY+boxSize) {
port.write('R');
}
else if(mouseX > M3LX-boxSize && mouseX < M3LX+boxSize &&
mouseY > M3LY-boxSize && mouseY < M3LY+boxSize) {
port.write('A');
}
else if(mouseX > M3RX-boxSize && mouseX < M3RX+boxSize &&
mouseY > M3RY-boxSize && mouseY < M3RY+boxSize) {
fill(200);
port.write('S');
}
else if (mouseX > M4LX-boxSize && mouseX < M4LX+boxSize &&
mouseY > M4LY-boxSize && mouseY < M4LY+boxSize) {
port.write('D');
}
else if(mouseX > M4RX-boxSize && mouseX < M4RX+boxSize &&
mouseY > M4RY-boxSize && mouseY < M4RY+boxSize) {
port.write('F');
}
else if (mouseX > M5LX-boxSize && mouseX < M5LX+boxSize &&
mouseY > M5LY-boxSize && mouseY < M5LY+boxSize) {
port.write('Z');
}
else if(mouseX > M5RX-boxSize && mouseX < M5RX+boxSize &&
mouseY > M5RY-boxSize && mouseY < M5RY+boxSize) {
port.write('X');
}
else {
// if the mouse is pressed but not with in a box make sure nothings moving
port.write('O');
}
} else {
// no key or mouse press then make sure nothings moving.
port.write('O');
}
// draw the buttons
myRightArrow.drawArrow(80,30);
myRightArrow.drawArrow(80,120);
myRightArrow.drawArrow(80,210);
myRightArrow.drawArrow(80,300);
myRightArrow.drawArrow(80,390);
myLeftArrow.drawArrow(10,30);
myLeftArrow.drawArrow(10,120);
myLeftArrow.drawArrow(10,210);
myLeftArrow.drawArrow(10,300);
myLeftArrow.drawArrow(10,390);
}
class arrow extends java.awt.Polygon {
/* our class is basically an instance of java.awt.Polygons and this class expects and array of X points, Y points and the number of
points in our shape. The variable names also have to be direct references to what this class expects, so xpoints, ypoints and npoints are all
set/defined in the java class.
*/
public arrow(int[] xpoints,int[] ypoints, int npoints) {
// super invokes the java.awt.Polygon class
super(xpoints,ypoints,npoints);
}
// supply offsets to draw the arrow, means I don't need to set points for each one
void drawArrow(int xOffset, int yOffset){
fill(150);
rect(xOffset-5, yOffset-5, boxSize, boxSize);
fill(255);
beginShape();
for(int i=0;i<npoints;i++){
vertex(xpoints[i]+xOffset,ypoints[i]+yOffset);
}
endShape();
}
}
Oui Oui puisque quand je lance le code processing , dans le rectangle noir en dessous il est ecrit qu'il se connecte au COM3. Ma carte Arduino est connecter au Com3.
Code arduino Erreur
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Retrouvez moi sur mon blog et ma chaine Youtube !