File tree 7 files changed +468
-0
lines changed
Example5_writeMicroseconds
7 files changed +468
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Author: Nathan Seidle
3
+ SparkFun Electronics
4
+ Created: August 18th, 2019
5
+ License: MIT. See SparkFun Arduino Apollo3 Project for more information
6
+
7
+ Purchasing from SparkFun helps write code like this and helps us
8
+ release products open source so that we can help each other learn: https://www.sparkfun.com/artemis
9
+
10
+ This example demonstrates the control of a servo on pin 8 on the RedBoard Artemis. Any PWM
11
+ pin can control a servo.
12
+
13
+ Hardware Connections:
14
+ Load this code
15
+ Connect a Servo to pin 18:
16
+ Red Wire -> 3.3V or 5V
17
+ Black Wire -> GND
18
+ Signal (Yellow or White) -> 8
19
+
20
+ The servo will rotate back and forth.
21
+ */
22
+
23
+ #include < Servo.h>
24
+
25
+ Servo myServo;
26
+
27
+ int pos = 0 ;
28
+
29
+ void setup ()
30
+ {
31
+ Serial.begin (9600 );
32
+ Serial.println (" SparkFun Servo Example" );
33
+
34
+ myServo.attach (8 );
35
+ }
36
+
37
+ void loop ()
38
+ {
39
+ // Sweep
40
+ for (pos = 0 ; pos <= 180 ; pos++) { // goes from 0 degrees to 180 degrees
41
+ myServo.write (pos); // tell servo to go to position in variable 'pos'
42
+ delay (5 ); // waits 15ms for the servo to reach the position
43
+ }
44
+ for (pos = 180 ; pos >= 0 ; pos--) { // goes from 180 degrees to 0 degrees
45
+ myServo.write (pos); // tell servo to go to position in variable 'pos'
46
+ delay (5 ); // waits 15ms for the servo to reach the position
47
+ }
48
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Author: Nathan Seidle
3
+ SparkFun Electronics
4
+ Created: August 18th, 2019
5
+ License: MIT. See SparkFun Arduino Apollo3 Project for more information
6
+
7
+ Purchasing from SparkFun helps write code like this and helps us
8
+ release products open source so that we can help each other learn: https://www.sparkfun.com/artemis
9
+
10
+ This example demonstrates controlling two servos.
11
+
12
+ Hardware Connections:
13
+ Load this code
14
+ Connect a Servo to pin 18:
15
+ Red Wire -> 3.3V or 5V
16
+ Black Wire -> GND
17
+ Signal (Yellow or White) -> 8
18
+
19
+ The servo will rotate back and forth.
20
+ */
21
+
22
+ #include < Servo.h>
23
+
24
+ Servo myServoA;
25
+ Servo myServoB;
26
+
27
+ int pos = 0 ;
28
+
29
+ void setup ()
30
+ {
31
+ Serial.begin (9600 );
32
+ Serial.println (" SparkFun Servo Example" );
33
+
34
+ myServoA.attach (8 );
35
+ myServoB.attach (7 );
36
+ }
37
+
38
+ void loop ()
39
+ {
40
+ // Sweep
41
+ for (pos = 0 ; pos <= 180 ; pos++) {
42
+ myServoA.write (pos);
43
+ myServoB.write (180 - pos);
44
+ delay (5 );
45
+ }
46
+ for (pos = 180 ; pos >= 0 ; pos--) {
47
+ myServoA.write (pos);
48
+ myServoB.write (180 - pos);
49
+ delay (5 );
50
+ }
51
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Author: Nathan Seidle
3
+ SparkFun Electronics
4
+ Created: August 18th, 2019
5
+ License: MIT. See SparkFun Arduino Apollo3 Project for more information
6
+
7
+ Purchasing from SparkFun helps write code like this and helps us
8
+ release products open source so that we can help each other learn: https://www.sparkfun.com/artemis
9
+
10
+ Different servos have different end points. Arduino defaults to 544us (min) and 2400us (max).
11
+ These however can be changed at startup. For more info see: https://www.arduino.cc/en/Reference/ServoAttach
12
+
13
+ Hardware Connections:
14
+ Load this code
15
+ Connect a Servo to pin 18:
16
+ Red Wire -> 3.3V or 5V
17
+ Black Wire -> GND
18
+ Signal (Yellow or White) -> 8
19
+
20
+ The servo will rotate back and forth.
21
+ */
22
+
23
+ #include < Servo.h>
24
+
25
+ Servo myServoA;
26
+
27
+ void setup ()
28
+ {
29
+ Serial.begin (9600 );
30
+ Serial.println (" SparkFun Servo Example" );
31
+
32
+ myServoA.attach (8 , 500 , 2600 ); // Increase min/max to drive servo fully
33
+ }
34
+
35
+ void loop ()
36
+ {
37
+ myServoA.write (180 ); // Go to max position
38
+ delay (2000 );
39
+ myServoA.write (0 ); // Go to min position
40
+ delay (2000 );
41
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Author: Nathan Seidle
3
+ SparkFun Electronics
4
+ Created: August 18th, 2019
5
+ License: MIT. See SparkFun Arduino Apollo3 Project for more information
6
+
7
+ Purchasing from SparkFun helps write code like this and helps us
8
+ release products open source so that we can help each other learn: https://www.sparkfun.com/artemis
9
+
10
+ Arduino defaults to 8-pin PWM resolution. This works for the majority of servos but can
11
+ be increased for projects that need it.
12
+
13
+ servoWriteResolution()
14
+ getServoResolution()
15
+
16
+ Are provided for changing and reading the resolution setting.
17
+
18
+ Hardware Connections:
19
+ Load this code
20
+ Connect a Servo to pin 18:
21
+ Red Wire -> 3.3V or 5V
22
+ Black Wire -> GND
23
+ Signal (Yellow or White) -> 8
24
+
25
+ The servo will rotate back and forth.
26
+ */
27
+
28
+ #include < Servo.h>
29
+
30
+ Servo myServoA;
31
+
32
+ void setup ()
33
+ {
34
+ Serial.begin (9600 );
35
+ Serial.println (" SparkFun Servo Example" );
36
+
37
+ myServoA.attach (8 );
38
+
39
+ servoWriteResolution (10 ); // Increase to 10-bit resolution. 16-bit is max.
40
+
41
+ int currentRes = getServoResolution ();
42
+ Serial.print (" Current resolution: " );
43
+ Serial.println (currentRes);
44
+ }
45
+
46
+ void loop ()
47
+ {
48
+ myServoA.write (180 ); // Go to max position
49
+ delay (2000 );
50
+ myServoA.write (0 ); // Go to min position
51
+ delay (2000 );
52
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Author: Nathan Seidle
3
+ SparkFun Electronics
4
+ Created: August 18th, 2019
5
+ License: MIT. See SparkFun Arduino Apollo3 Project for more information
6
+
7
+ Purchasing from SparkFun helps write code like this and helps us
8
+ release products open source so that we can help each other learn: https://www.sparkfun.com/artemis
9
+
10
+ This example shows how to write to the servo in microseconds instead of position. This
11
+ is helpful for find the min/max us settings for a given servo manufacturer.
12
+
13
+ Hardware Connections:
14
+ Load this code
15
+ Connect a Servo to RX1:
16
+ Red Wire -> 3.3V or 5V
17
+ Black Wire -> GND
18
+ Signal (Yellow or White) -> RX1
19
+
20
+ The servo will rotate back and forth.
21
+ */
22
+
23
+ #include < Servo.h>
24
+
25
+ Servo myServo;
26
+
27
+ void setup ()
28
+ {
29
+ Serial.begin (9600 );
30
+ Serial.println (" SparkFun Servo Example" );
31
+
32
+ myServo.attach (8 );
33
+
34
+ myServo.writeMicroseconds (600 ); // Servo will go to very near the 0 degree position
35
+ }
36
+
37
+ void loop ()
38
+ {
39
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Author: Nathan Seidle
3
+ SparkFun Electronics
4
+ Created: August 18th, 2019
5
+ License: MIT. See SparkFun Arduino Apollo3 Project for more information
6
+
7
+ Purchasing from SparkFun helps write code like this and helps us
8
+ release products open source so that we can help each other learn: https://www.sparkfun.com/artemis
9
+
10
+ This example demonstrates the control of 19 servos simulataneously on the BlackBoard Artemis.
11
+ Any PWM pin is capable of 16 bit servo control. Need more than 19 servos? What are you building?!
12
+ Check out the BlackBoard ATP for 29 servo capable PWM pins.
13
+
14
+ Hardware Connections:
15
+ Load this code
16
+ Connect a Servo to RX1:
17
+ Red Wire -> 3.3V or 5V
18
+ Black Wire -> GND
19
+ Signal (Yellow or White) -> RX1
20
+
21
+ The servo will rotate back and forth. Similary, you can move the signal wire to any PWM
22
+ pin and you will see the servo move to a new position and hold. This shows that the other
23
+ PWM pins are all simultaneously and actively outputting a servo signal.
24
+ */
25
+
26
+ #include < Servo.h>
27
+
28
+ Servo myServoRX;
29
+ Servo myServoTX;
30
+ Servo myServo2;
31
+ Servo myServo3;
32
+ Servo myServo4;
33
+ Servo myServo5;
34
+ Servo myServo6;
35
+ Servo myServo7;
36
+ Servo myServo8;
37
+ Servo myServo9;
38
+ Servo myServo10;
39
+ Servo myServoMOSI;
40
+ Servo myServoMISO;
41
+ Servo myServoSCK;
42
+ Servo myServoA0;
43
+ Servo myServoA1;
44
+ Servo myServoA3;
45
+ Servo myServoA5;
46
+ Servo myServoSCL;
47
+
48
+ int pos = 0 ;
49
+
50
+ void setup ()
51
+ {
52
+ Serial.begin (9600 );
53
+ Serial.println (" SparkFun Servo Example" );
54
+
55
+ myServoRX.attach (0 ); // Labeled RX1
56
+ myServoTX.attach (1 ); // Labeled TX1
57
+ myServo2.attach (2 );
58
+ myServo3.attach (3 );
59
+ myServo4.attach (4 );
60
+ myServo5.attach (5 );
61
+ myServo6.attach (6 );
62
+ myServo7.attach (7 );
63
+ myServo8.attach (8 );
64
+ myServo9.attach (9 );
65
+ myServo10.attach (10 );
66
+ myServoMOSI.attach (11 ); // Labeled MOSI
67
+ myServoMISO.attach (12 ); // Labeled MISO
68
+ myServoSCK.attach (13 ); // Labeled SCK
69
+ myServoA0.attach (A0);
70
+ myServoA1.attach (A1);
71
+ myServoA3.attach (A3);
72
+ myServoA5.attach (A5);
73
+ myServoSCL.attach (SCL);
74
+
75
+ myServo2.write (0 );
76
+ myServo3.write (10 );
77
+ myServo4.write (30 );
78
+ myServo5.write (60 );
79
+ myServo6.write (90 );
80
+ myServo7.write (120 );
81
+ myServo8.write (140 );
82
+ myServo9.write (160 );
83
+ myServo10.write (180 );
84
+ myServoMOSI.write (0 );
85
+ myServoMISO.write (30 );
86
+ myServoSCK.write (60 );
87
+ myServoA0.write (90 );
88
+ myServoA1.write (120 );
89
+ myServoA3.write (150 );
90
+ myServoA5.write (0 );
91
+ myServoSCL.write (30 );
92
+ myServoTX.write (60 );
93
+ }
94
+
95
+ void loop ()
96
+ {
97
+ myServoRX.write (0 );
98
+ delay (1500 );
99
+ myServoRX.write (180 );
100
+ delay (1500 );
101
+ }
You can’t perform that action at this time.
0 commit comments