Skip to main content
Arduino

Return to Answer

Commonmark migration
Source Link

###TL;DR

TL;DR

###TL;DR

TL;DR

Added images, reorganised answer
Source Link
Greenonline
  • 3.2k
  • 7
  • 36
  • 48

Regarding your question about the maximum and minimums, again, these will be handled by the Servo.h library.

If you do not supply external power, then the Arduino board, by itself will not be able to supply enough power and even. Even though the code may be running, the lack of power may make it appear that there is no output, as the servos remain immobile, due to the lack of current.

If you do not supply external power, then the Arduino board, by itself will not be able to supply enough power and even though the code may be running, the lack of power may make it appear that there is no output, as the servos remain immobile, due to the lack of current.

Regarding your question about the maximum and minimums, again, these will be handled by the Servo.h library.

If you do not supply external power, then the Arduino board, by itself will not be able to supply enough power. Even though the code may be running, the lack of power may make it appear that there is no output, as the servos remain immobile, due to the lack of current.

Added images, reorganised answer
Source Link
Greenonline
  • 3.2k
  • 7
  • 36
  • 48

I use a generic servo shield, and the servo PWM outputs (3 pin inline connector) on the shield are labeled accordingly (0 - 15). Your Adafruit servo shield should be the same, see below.

Adafruit Servo shield

The link that you provide also has the ArduinoArduino version, see below. You should use that, instead of the ProcessingProcessing version.

LookingThe Arduino library Servo.h, handles all of the "Servo PWM to Arduino pin conversions" that you ask for. So, looking at theFixbot code, it would seem that all you would need to do is change the five pins (servo PWM outputs) to which the servos are attached in setup(), according to which servo PWM outputs you attach each servo to.

I use a generic servo shield, and the servo outputs on the shield are labeled accordingly.

#include <Servo.h>
String command;
Servo seg0;
Servo seg1;
Servo seg2;
Servo seg3;
Servo seg4;
void setup() {
 Serial.begin(115200);
 seg0.attach(8); /* <--- Change Me !!! */
 seg1.attach(9); /* <--- Change Me !!! */
 seg2.attach(10); /* <--- Change Me !!! */
 seg3.attach(11); /* <--- Change Me !!! */
 seg4.attach(12); /* <--- Change Me !!! */
}
void loop() {
 if(Serial.available() > 0) {
 char inChar = Serial.read();
 command += inChar;
 if(inChar == '\n') {
 // clear command
 performCmd(command);
 command = "";
 }
 Serial.flush();
 }
}
void performCmd(String cmd) {
 int comma1 = cmd.indexOf(',');
 int comma2 = cmd.indexOf(',', comma1+1);
 int comma3 = cmd.indexOf(',', comma2+1);
 int comma4 = cmd.indexOf(',', comma3+1);
 
 int cmd0 = stringToInt(cmd.substring(0, comma1));
 int cmd1 = stringToInt(cmd.substring(comma1+1, comma2));
 int cmd2 = stringToInt(cmd.substring(comma2+1, comma3));
 int cmd3 = stringToInt(cmd.substring(comma3+1, comma4));
 int cmd4 = stringToInt(cmd.substring(comma4+1, cmd.length()));
 
 seg0.write(cmd0);
 seg1.write(cmd1);
 seg2.write(cmd2);
 seg3.write(cmd3);
 seg4.write(cmd4);
 
}
int stringToInt(String str) {
 String tmp = String(str);
 return str.toInt();
}

Power Requirements

As an aside, remember that you will need to supply external power (+5V) to the Adafruit Servo board, via the blue screw terminal block, in order to have sufficient power (current) to actuate the servos. In the photo above the screw terminal block is not shown, but would be mounted half way up on the left hand side of the PCB (where it says 5-6V Servo). It can be seen in this photo, at the top:

Adafruit Servo Shield, showing blue screw terminal

If you do not supply external power, then the Arduino board, by itself will not be able to supply enough power and even though the code may be running, the lack of power may make it appear that there is no output, as the servos remain immobile, due to the lack of current.

The link that you provide also has the Arduino version, see below. You should use that, instead of the Processing version.

Looking at the code, it would seem that all you would need to do is change the five pins to which the servos are attached in setup(), according to which servo outputs you attach each servo to.

I use a generic servo shield, and the servo outputs on the shield are labeled accordingly.

#include <Servo.h>
String command;
Servo seg0;
Servo seg1;
Servo seg2;
Servo seg3;
Servo seg4;
void setup() {
 Serial.begin(115200);
 seg0.attach(8);
 seg1.attach(9);
 seg2.attach(10);
 seg3.attach(11);
 seg4.attach(12);
}
void loop() {
 if(Serial.available() > 0) {
 char inChar = Serial.read();
 command += inChar;
 if(inChar == '\n') {
 // clear command
 performCmd(command);
 command = "";
 }
 Serial.flush();
 }
}
void performCmd(String cmd) {
 int comma1 = cmd.indexOf(',');
 int comma2 = cmd.indexOf(',', comma1+1);
 int comma3 = cmd.indexOf(',', comma2+1);
 int comma4 = cmd.indexOf(',', comma3+1);
 
 int cmd0 = stringToInt(cmd.substring(0, comma1));
 int cmd1 = stringToInt(cmd.substring(comma1+1, comma2));
 int cmd2 = stringToInt(cmd.substring(comma2+1, comma3));
 int cmd3 = stringToInt(cmd.substring(comma3+1, comma4));
 int cmd4 = stringToInt(cmd.substring(comma4+1, cmd.length()));
 
 seg0.write(cmd0);
 seg1.write(cmd1);
 seg2.write(cmd2);
 seg3.write(cmd3);
 seg4.write(cmd4);
 
}
int stringToInt(String str) {
 String tmp = String(str);
 return str.toInt();
}

As an aside, remember that you will need to supply external power to the Adafruit Servo board in order to have sufficient power (current) to actuate the servos.

I use a generic servo shield, and the servo PWM outputs (3 pin inline connector) on the shield are labeled accordingly (0 - 15). Your Adafruit servo shield should be the same, see below.

Adafruit Servo shield

The link that you provide also has the Arduino version, see below. You should use that, instead of the Processing version.

The Arduino library Servo.h, handles all of the "Servo PWM to Arduino pin conversions" that you ask for. So, looking at theFixbot code, it would seem that all you would need to do is change the five pins (servo PWM outputs) to which the servos are attached in setup(), according to which servo PWM outputs you attach each servo to.

#include <Servo.h>
String command;
Servo seg0;
Servo seg1;
Servo seg2;
Servo seg3;
Servo seg4;
void setup() {
 Serial.begin(115200);
 seg0.attach(8); /* <--- Change Me !!! */
 seg1.attach(9); /* <--- Change Me !!! */
 seg2.attach(10); /* <--- Change Me !!! */
 seg3.attach(11); /* <--- Change Me !!! */
 seg4.attach(12); /* <--- Change Me !!! */
}
void loop() {
 if(Serial.available() > 0) {
 char inChar = Serial.read();
 command += inChar;
 if(inChar == '\n') {
 // clear command
 performCmd(command);
 command = "";
 }
 Serial.flush();
 }
}
void performCmd(String cmd) {
 int comma1 = cmd.indexOf(',');
 int comma2 = cmd.indexOf(',', comma1+1);
 int comma3 = cmd.indexOf(',', comma2+1);
 int comma4 = cmd.indexOf(',', comma3+1);
 
 int cmd0 = stringToInt(cmd.substring(0, comma1));
 int cmd1 = stringToInt(cmd.substring(comma1+1, comma2));
 int cmd2 = stringToInt(cmd.substring(comma2+1, comma3));
 int cmd3 = stringToInt(cmd.substring(comma3+1, comma4));
 int cmd4 = stringToInt(cmd.substring(comma4+1, cmd.length()));
 
 seg0.write(cmd0);
 seg1.write(cmd1);
 seg2.write(cmd2);
 seg3.write(cmd3);
 seg4.write(cmd4);
 
}
int stringToInt(String str) {
 String tmp = String(str);
 return str.toInt();
}

Power Requirements

As an aside, remember that you will need to supply external power (+5V) to the Adafruit Servo board, via the blue screw terminal block, in order to have sufficient power (current) to actuate the servos. In the photo above the screw terminal block is not shown, but would be mounted half way up on the left hand side of the PCB (where it says 5-6V Servo). It can be seen in this photo, at the top:

Adafruit Servo Shield, showing blue screw terminal

If you do not supply external power, then the Arduino board, by itself will not be able to supply enough power and even though the code may be running, the lack of power may make it appear that there is no output, as the servos remain immobile, due to the lack of current.

Source Link
Greenonline
  • 3.2k
  • 7
  • 36
  • 48
Loading
default

AltStyle によって変換されたページ (->オリジナル) /