Skip to content

Commit 204503f

Browse files
committed
Refactored SAMD support
1 parent f426725 commit 204503f

File tree

30 files changed

+1262
-337
lines changed

30 files changed

+1262
-337
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
Simple: -DPRINT_FOR_SERIAL_PLOTTER
7878
PCA9685_ExpanderFor32Servos: -DTRACE -DDISABLE_MICROS_AS_DEGREE_PARAMETER
7979
PCA9685_ExpanderAndServo: -DUSE_SOFT_I2C_MASTER
80+
QuadrupedControl: -DQUADRUPED_1_WITH_DVD_REMOTE
8081

8182
- arduino-boards-fqbn: arduino:avr:leonardo
8283
sketches-exclude: TwoServos,RobotArmControl # No LightweightServoLib and TinyReceiver available
@@ -98,6 +99,7 @@ jobs:
9899
sketches-exclude: TwoServos,QuadrupedControl,RobotArmControl
99100

100101
# Error in default samd/Servo.cpp:44:60 - volatile struct TC_STATUS_Type::<unnamed> has no member named SYNCBUSY
102+
# because Arduino uses the newer arduino and not the adafruit servo library
101103
# - arduino-boards-fqbn: adafruit:samd:adafruit_metro_m4:cache=on,speed=120,opt=small,maxqspi=50,usbstack=arduino,debug=off
102104
# platform-url: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
103105
# sketches-exclude: TwoServos,QuadrupedControl,RobotArmControl

examples/AsymmetricEasing/PinDefinitionsAndMore.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
#define SPEED_IN_PIN A0
9595
#define MODE_ANALOG_INPUT_PIN A1
9696

97+
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
98+
#define SERVO1_PIN 5
99+
#define SERVO2_PIN 6
100+
#define SERVO3_PIN 7
101+
#define SPEED_IN_PIN A1 // A0 is DAC output
102+
#define MODE_ANALOG_INPUT_PIN A2
103+
104+
#if !defined(ARDUINO_SAMD_ADAFRUIT)
105+
// On the Zero and others we switch explicitly to SerialUSB
106+
#define Serial SerialUSB
107+
#endif
108+
109+
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
110+
// Attention!!! D2 and D4 are swapped on these boards!!!
111+
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
112+
//#undef LED_BUILTIN
113+
//#define LED_BUILTIN 24 // PB11
114+
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
115+
//#undef LED_BUILTIN
116+
//#define LED_BUILTIN 25 // PB03
117+
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
118+
97119
#else
98120
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
99121
// Default valued for unidentified boards
@@ -114,11 +136,3 @@
114136
#if !defined(LED_BUILTIN) && !defined(ESP32)
115137
#define LED_BUILTIN PB1
116138
#endif
117-
// On the Zero and others we switch explicitly to SerialUSB
118-
#if defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_SAMD_ADAFRUIT)
119-
#define Serial SerialUSB
120-
// The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board.
121-
// Attention! D2 and D4 are swapped on these boards
122-
//#undef LED_BUILTIN
123-
//#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low.
124-
#endif

examples/CatMover/PinDefinitionsAndMore.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
#define SPEED_IN_PIN A0
9595
#define MODE_ANALOG_INPUT_PIN A1
9696

97+
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
98+
#define SERVO1_PIN 5
99+
#define SERVO2_PIN 6
100+
#define SERVO3_PIN 7
101+
#define SPEED_IN_PIN A1 // A0 is DAC output
102+
#define MODE_ANALOG_INPUT_PIN A2
103+
104+
#if !defined(ARDUINO_SAMD_ADAFRUIT)
105+
// On the Zero and others we switch explicitly to SerialUSB
106+
#define Serial SerialUSB
107+
#endif
108+
109+
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
110+
// Attention!!! D2 and D4 are swapped on these boards!!!
111+
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
112+
//#undef LED_BUILTIN
113+
//#define LED_BUILTIN 24 // PB11
114+
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
115+
//#undef LED_BUILTIN
116+
//#define LED_BUILTIN 25 // PB03
117+
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
118+
97119
#else
98120
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
99121
// Default valued for unidentified boards
@@ -114,11 +136,3 @@
114136
#if !defined(LED_BUILTIN) && !defined(ESP32)
115137
#define LED_BUILTIN PB1
116138
#endif
117-
// On the Zero and others we switch explicitly to SerialUSB
118-
#if defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_SAMD_ADAFRUIT)
119-
#define Serial SerialUSB
120-
// The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board.
121-
// Attention! D2 and D4 are swapped on these boards
122-
//#undef LED_BUILTIN
123-
//#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low.
124-
#endif

examples/ConsecutiveEasingsWithCallback/PinDefinitionsAndMore.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
#define SPEED_IN_PIN A0
9595
#define MODE_ANALOG_INPUT_PIN A1
9696

97+
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
98+
#define SERVO1_PIN 5
99+
#define SERVO2_PIN 6
100+
#define SERVO3_PIN 7
101+
#define SPEED_IN_PIN A1 // A0 is DAC output
102+
#define MODE_ANALOG_INPUT_PIN A2
103+
104+
#if !defined(ARDUINO_SAMD_ADAFRUIT)
105+
// On the Zero and others we switch explicitly to SerialUSB
106+
#define Serial SerialUSB
107+
#endif
108+
109+
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
110+
// Attention!!! D2 and D4 are swapped on these boards!!!
111+
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
112+
//#undef LED_BUILTIN
113+
//#define LED_BUILTIN 24 // PB11
114+
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
115+
//#undef LED_BUILTIN
116+
//#define LED_BUILTIN 25 // PB03
117+
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
118+
97119
#else
98120
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
99121
// Default valued for unidentified boards
@@ -114,11 +136,3 @@
114136
#if !defined(LED_BUILTIN) && !defined(ESP32)
115137
#define LED_BUILTIN PB1
116138
#endif
117-
// On the Zero and others we switch explicitly to SerialUSB
118-
#if defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_SAMD_ADAFRUIT)
119-
#define Serial SerialUSB
120-
// The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board.
121-
// Attention! D2 and D4 are swapped on these boards
122-
//#undef LED_BUILTIN
123-
//#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low.
124-
#endif

examples/ContinuousRotatingServo/PinDefinitionsAndMore.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
#define SPEED_IN_PIN A0
9595
#define MODE_ANALOG_INPUT_PIN A1
9696

97+
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
98+
#define SERVO1_PIN 5
99+
#define SERVO2_PIN 6
100+
#define SERVO3_PIN 7
101+
#define SPEED_IN_PIN A1 // A0 is DAC output
102+
#define MODE_ANALOG_INPUT_PIN A2
103+
104+
#if !defined(ARDUINO_SAMD_ADAFRUIT)
105+
// On the Zero and others we switch explicitly to SerialUSB
106+
#define Serial SerialUSB
107+
#endif
108+
109+
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
110+
// Attention!!! D2 and D4 are swapped on these boards!!!
111+
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
112+
//#undef LED_BUILTIN
113+
//#define LED_BUILTIN 24 // PB11
114+
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
115+
//#undef LED_BUILTIN
116+
//#define LED_BUILTIN 25 // PB03
117+
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
118+
97119
#else
98120
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
99121
// Default valued for unidentified boards
@@ -114,11 +136,3 @@
114136
#if !defined(LED_BUILTIN) && !defined(ESP32)
115137
#define LED_BUILTIN PB1
116138
#endif
117-
// On the Zero and others we switch explicitly to SerialUSB
118-
#if defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_SAMD_ADAFRUIT)
119-
#define Serial SerialUSB
120-
// The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board.
121-
// Attention! D2 and D4 are swapped on these boards
122-
//#undef LED_BUILTIN
123-
//#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low.
124-
#endif

examples/EndPositionsTest/PinDefinitionsAndMore.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
#define SPEED_IN_PIN A0
9595
#define MODE_ANALOG_INPUT_PIN A1
9696

97+
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
98+
#define SERVO1_PIN 5
99+
#define SERVO2_PIN 6
100+
#define SERVO3_PIN 7
101+
#define SPEED_IN_PIN A1 // A0 is DAC output
102+
#define MODE_ANALOG_INPUT_PIN A2
103+
104+
#if !defined(ARDUINO_SAMD_ADAFRUIT)
105+
// On the Zero and others we switch explicitly to SerialUSB
106+
#define Serial SerialUSB
107+
#endif
108+
109+
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
110+
// Attention!!! D2 and D4 are swapped on these boards!!!
111+
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
112+
//#undef LED_BUILTIN
113+
//#define LED_BUILTIN 24 // PB11
114+
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
115+
//#undef LED_BUILTIN
116+
//#define LED_BUILTIN 25 // PB03
117+
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
118+
97119
#else
98120
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
99121
// Default valued for unidentified boards
@@ -114,11 +136,3 @@
114136
#if !defined(LED_BUILTIN) && !defined(ESP32)
115137
#define LED_BUILTIN PB1
116138
#endif
117-
// On the Zero and others we switch explicitly to SerialUSB
118-
#if defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_SAMD_ADAFRUIT)
119-
#define Serial SerialUSB
120-
// The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board.
121-
// Attention! D2 and D4 are swapped on these boards
122-
//#undef LED_BUILTIN
123-
//#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low.
124-
#endif

examples/LightweightServoExample/PinDefinitionsAndMore.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
#define SPEED_IN_PIN A0
9595
#define MODE_ANALOG_INPUT_PIN A1
9696

97+
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
98+
#define SERVO1_PIN 5
99+
#define SERVO2_PIN 6
100+
#define SERVO3_PIN 7
101+
#define SPEED_IN_PIN A1 // A0 is DAC output
102+
#define MODE_ANALOG_INPUT_PIN A2
103+
104+
#if !defined(ARDUINO_SAMD_ADAFRUIT)
105+
// On the Zero and others we switch explicitly to SerialUSB
106+
#define Serial SerialUSB
107+
#endif
108+
109+
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
110+
// Attention!!! D2 and D4 are swapped on these boards!!!
111+
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
112+
//#undef LED_BUILTIN
113+
//#define LED_BUILTIN 24 // PB11
114+
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
115+
//#undef LED_BUILTIN
116+
//#define LED_BUILTIN 25 // PB03
117+
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
118+
97119
#else
98120
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
99121
// Default valued for unidentified boards
@@ -114,11 +136,3 @@
114136
#if !defined(LED_BUILTIN) && !defined(ESP32)
115137
#define LED_BUILTIN PB1
116138
#endif
117-
// On the Zero and others we switch explicitly to SerialUSB
118-
#if defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_SAMD_ADAFRUIT)
119-
#define Serial SerialUSB
120-
// The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board.
121-
// Attention! D2 and D4 are swapped on these boards
122-
//#undef LED_BUILTIN
123-
//#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low.
124-
#endif

examples/OneServo/OneServo.ino

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,15 @@ void loop() {
237237
// resume movement using interrupts
238238
Servo1.resumeWithInterrupts();
239239
#endif
240-
delay(3000); // wait extra 2 seconds
240+
while (Servo1.isMoving()); // wait for servo to stop
241+
242+
Servo1.detach();
243+
/*
244+
* After detach the servo is "not powered" for 5 seconds, i.e. no servo signal is generated.
245+
* This allows you to easily move the servo manually.
246+
*/
247+
delay(5000); // wait 5 seconds
248+
Servo1.attach(SERVO1_PIN, 0);
241249
}
242250

243251
void blinkLED() {

examples/OneServo/PinDefinitionsAndMore.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
#define SPEED_IN_PIN A0
9595
#define MODE_ANALOG_INPUT_PIN A1
9696

97+
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
98+
#define SERVO1_PIN 5
99+
#define SERVO2_PIN 6
100+
#define SERVO3_PIN 7
101+
#define SPEED_IN_PIN A1 // A0 is DAC output
102+
#define MODE_ANALOG_INPUT_PIN A2
103+
104+
#if !defined(ARDUINO_SAMD_ADAFRUIT)
105+
// On the Zero and others we switch explicitly to SerialUSB
106+
#define Serial SerialUSB
107+
#endif
108+
109+
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
110+
// Attention!!! D2 and D4 are swapped on these boards!!!
111+
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
112+
//#undef LED_BUILTIN
113+
//#define LED_BUILTIN 24 // PB11
114+
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
115+
//#undef LED_BUILTIN
116+
//#define LED_BUILTIN 25 // PB03
117+
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
118+
97119
#else
98120
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
99121
// Default valued for unidentified boards
@@ -114,11 +136,3 @@
114136
#if !defined(LED_BUILTIN) && !defined(ESP32)
115137
#define LED_BUILTIN PB1
116138
#endif
117-
// On the Zero and others we switch explicitly to SerialUSB
118-
#if defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_SAMD_ADAFRUIT)
119-
#define Serial SerialUSB
120-
// The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board.
121-
// Attention! D2 and D4 are swapped on these boards
122-
//#undef LED_BUILTIN
123-
//#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low.
124-
#endif

examples/PCA9685_Expander/PinDefinitionsAndMore.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@
9494
#define SPEED_IN_PIN A0
9595
#define MODE_ANALOG_INPUT_PIN A1
9696

97+
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
98+
#define SERVO1_PIN 5
99+
#define SERVO2_PIN 6
100+
#define SERVO3_PIN 7
101+
#define SPEED_IN_PIN A1 // A0 is DAC output
102+
#define MODE_ANALOG_INPUT_PIN A2
103+
104+
#if !defined(ARDUINO_SAMD_ADAFRUIT)
105+
// On the Zero and others we switch explicitly to SerialUSB
106+
#define Serial SerialUSB
107+
#endif
108+
109+
// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17.
110+
// Attention!!! D2 and D4 are swapped on these boards!!!
111+
// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines.
112+
//#undef LED_BUILTIN
113+
//#define LED_BUILTIN 24 // PB11
114+
// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines.
115+
//#undef LED_BUILTIN
116+
//#define LED_BUILTIN 25 // PB03
117+
//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW
118+
97119
#else
98120
#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h.
99121
// Default valued for unidentified boards
@@ -114,11 +136,3 @@
114136
#if !defined(LED_BUILTIN) && !defined(ESP32)
115137
#define LED_BUILTIN PB1
116138
#endif
117-
// On the Zero and others we switch explicitly to SerialUSB
118-
#if defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_SAMD_ADAFRUIT)
119-
#define Serial SerialUSB
120-
// The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board.
121-
// Attention! D2 and D4 are swapped on these boards
122-
//#undef LED_BUILTIN
123-
//#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low.
124-
#endif

0 commit comments

Comments
 (0)