Skip to content

Commit 4a76131

Browse files
committed
Initial commit
1 parent 5b41274 commit 4a76131

File tree

18 files changed

+2400
-4
lines changed

18 files changed

+2400
-4
lines changed

.github/workflows/arduino_ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Arduino_CI # 워크플로우의 이름 설정
2+
3+
on: [pull_request] # 워크플로우를 실행할 이벤트 설정 (pull request가 열릴 때 실행)
4+
5+
jobs:
6+
arduino_ci:
7+
runs-on: ubuntu-latest # 워크플로우가 실행될 환경 설정 (Ubuntu 최신 버전 사용)
8+
9+
steps:
10+
- uses: actions/checkout@v3 # GitHub Actions를 사용하여 코드를 체크아웃하는 단계 추가
11+
12+
- uses: Arduino-CI/action@stable-1.x # Arduino CI 액션 사용
13+
env:
14+
USE_SUBDIR: . # 라이브러리의 경로 설정 (기본값은 현재 디렉토리)
15+
EXPECT_EXAMPLES: false # 예제 코드가 없는 경우 테스트를 실패로 처리할지 여부 설정
16+
EXPECT_UNITTESTS: false # 유닛 테스트가 없는 경우 테스트를 실패로 처리할지 여부 설정
17+
# 커스텀 라이브러리 설치 스크립트가 필요한 경우, 스크립트 파일의 경로 설정
18+
# 이 스크립트는 Arduino 라이브러리 디렉토리에서 실행됩니다.
19+
# CUSTOM_INIT_SCRIPT: install_dependencies.sh

LICENSE

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
1-
MIT License
1+
CA_MotorShield Library Copyright Notice:
2+
3+
Copyright (c) [2024], CodingArray / hanol JU. All rights reserved.
4+
This library is based on the Adafruit_MotorShield v2 library from Adafruit Industries
5+
and the PCA9685_RT library from Rob Tillaart, integrating the strengths of both libraries
6+
to address issues arising during DC motor operation with I2C communication errors and
7+
when changing the motor's rotation direction encountered with the Adafruit_MotorShield v2 library.
8+
Such issues were particularly evident in the 'void Adafruit_MotorShield::setPin(uint8_t pin, boolean value)'
9+
function, where setting multiple pins to HIGH or LOW caused problems.
10+
This library is distributed under the MIT license.
11+
Use, modification, and redistribution must follow the conditions below:
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
14+
AND NONINFRINGEMENT.
15+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES,
16+
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
17+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
The Adafruit_MotorShield v2 library is distributed under the BSD license,
19+
and the PCA9685_RT library is distributed under the MIT license.
20+
Users are considered to have agreed to these license conditions by using these libraries.
21+
22+
23+
Adafruit_MotorShield v2 Copyright Notice:
24+
Software License Agreement (BSD License)
25+
Copyright (c) 2012, Adafruit Industries. All rights reserved.
226

3-
Copyright (c) 2024 CodingArray
27+
Redistribution and use in source and binary forms, with or without
28+
modification, are permitted provided that the following conditions are met:
29+
1. Redistributions of source code must retain the above copyright
30+
notice, this list of conditions and the following disclaimer.
31+
2. Redistributions in binary form must reproduce the above copyright
32+
notice, this list of conditions and the following disclaimer in the
33+
documentation and/or other materials provided with the distribution.
34+
3. Neither the name of the copyright holders nor the names of its
35+
contributors may be used to endorse or promote products derived from
36+
this software without specific prior written permission.
37+
38+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
39+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
40+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
42+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48+
49+
50+
PCA9685_RT Copyright Notice:
51+
MIT License
52+
Copyright (c) 2016-2024 Rob Tillaart
453

554
Permission is hereby granted, free of charge, to any person obtaining a copy
655
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
1-
# CA_MotorShield_V1_Library
2-
Advanced Arduino library for Coding Array Motor Shield V1 supports 4 DC or 2 stepper motors, removing Adafruit dependencies. Includes microstepping, stacking, and PCA9685_RT for precise PWM control. Addresses motor direction and I2C communication issues. Compatible with Adafruit Motor Shield V2 clones. MIT and BSD licensed.
1+
[![Build Status](https://github.com/codingarray/CA_MotorShield_V1_Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/codingarray/CA_MotorShield_V1_Library/actions)
2+
[![License: MIT and BSD](https://img.shields.io/badge/license-MIT%20and%20BSD-green.svg)](https://github.com/codingarray/CA_MotorShield_V1_Library/blob/master/LICENSE)
3+
4+
# Coding Array Motor Shield V1 Library
5+
6+
![Coding Array Motor Shield V1](./images/CA_MotorShield_V1.jpg)
7+
8+
## Overview
9+
10+
The `Coding Array Motor Shield V1 Library` is based on the Adafruit Motor Shield V2, but it has been developed with the removal of dependencies on Adafruit's `Adafruit_MS_PWMServoDriver` and `Adafruit_I2CDevice`. This library supports the control of up to four DC motors or two stepper motors, excluding servo motors. It offers microstepping and stacking capabilities for DC and stepper motors, allowing for flexible application across various motor control projects.
11+
12+
Incorporating the `PCA9685_RT` library (by RobTillaart, version 0.7.1), it supports the PCA9685 I2C LED driver and 16-channel PWM with 12-bit resolution. This integration allows for the 16 channels to be independently configured in 1/4096 steps, enabling fine-tuning of the PWM signal's duty cycle to better than 0.1%. The PWM channels can be individually started and stopped, optimizing power distribution across multiple servos or creating special effects with RGB LEDs.
13+
14+
## Development Background
15+
16+
The `Coding Array Motor Shield V1 Library` is grounded on the `Adafruit_MotorShield v2` library from Adafruit Industries and the `PCA9685_RT` library from Rob Tillaart. It was developed to address issues encountered during DC motor operation related to I2C communication errors and changing motor rotation direction with the Adafruit_MotorShield v2 library. Such issues were particularly apparent in the `void Adafruit_MotorShield::setPin(uint8_t pin, boolean value)` function, where setting multiple pins to HIGH or LOW posed problems.
17+
18+
## Compatible Products
19+
20+
### Coding Array Motor Shield V1
21+
url : http://www.codingarray.net
22+
23+
The Coding Array I2C Motor Driver Shield, a clone of the Adafruit Motor Shield V2, is specifically designed to offer a more user-friendly interface and facilitate easier wiring for enthusiasts and professionals alike. This enhancement ensures a smoother integration into projects, making it an ideal choice for those seeking convenience without compromising on functionality.
24+
25+
### Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit - v2.3
26+
url : https://www.adafruit.com/product/1438
27+
28+
The original Adafruit Motorshield kit is one of our most beloved kits, which is why we decided to make something even better. We have upgraded the shield kit to make the bestest, easiest way to drive DC and Stepper motors. This shield will make quick work of your next robotics project! We kept the ability to drive up to 4 DC motors or 2 stepper motors, but added many improvements:
29+
30+
## Related Links
31+
32+
- Adafruit Motor Shield V2 Library: https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
33+
- PCA9685_RT Library by RobTillaart: https://github.com/RobTillaart/PCA9685_RT
34+
35+
## License
36+
37+
This library was written by hanol JU for codingarray. It is licensed under both the BSD License and the MIT License; see the license.txt file for more information. All text above must be included in any redistribution.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*!
2+
* @file ConstantSpeed.ino
3+
*
4+
* @mainpage Example code for CA MotorShield Library.
5+
*
6+
* @section intro_sec Introduction
7+
*
8+
* This example shows how to control a stepper motor using the CA_MotorShield library,
9+
* demonstrating the simplest, fixed speed mode with no accelerations.
10+
* It is designed for the CA MotorShield, which is an enhancement over the Adafruit Motor Shield V2,
11+
* integrating features for improved motor control.
12+
*
13+
* Developed by CodingArray / hanol JU, based on the original work by
14+
* Limor Fried/Ladyada for Adafruit Industries and enhancements from Rob Tillaart's PCA9685_RT library.
15+
*
16+
* This library is released under the MIT license.
17+
* Please support CA MotorShield and open-source hardware by purchasing
18+
* products from CodingArray / www.codingarray.net.
19+
*
20+
* @section license License
21+
*
22+
* MIT License - all text here must be included in any redistribution.
23+
*
24+
*/
25+
26+
#include <CA_MotorShield.h>
27+
28+
// Create the motor shield object with the default I2C address
29+
CA_MotorShield STEP_Motor(0x60); // Adjust the I2C address as needed
30+
31+
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
32+
// to motor port #1 and #2 respectively
33+
CA_StepperMotor *StepMotor1 = STEP_Motor.getStepper(200, 1);
34+
35+
void forwardStep() {
36+
StepMotor1->onestep(FORWARD, SINGLE);
37+
}
38+
void backwardStep() {
39+
StepMotor1->onestep(BACKWARD, SINGLE);
40+
}
41+
42+
// Use functions to step
43+
CA_Stepper Astepper1 = CA_Stepper(forwardStep, backwardStep);
44+
45+
void setup() {
46+
Serial.begin(115200); // set up Serial library at 115200 bps
47+
Serial.println("Stepper test!");
48+
49+
STEP_Motor.begin(); // Initialize the motor shield
50+
STEP_Motor.setFrequency(1600); // Set PWM frequency for stepper motor
51+
52+
Astepper1.setSpeed(150); // Set the speed of the stepper motor
53+
}
54+
55+
void loop() {
56+
Astepper1.runSpeed(); // Continuously run the stepper motor at the set speed
57+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*!
2+
* @file MultipleSteppers.ino
3+
*
4+
* @mainpage Example code for running multiple steppers with CA MotorShield Library.
5+
*
6+
* @section intro_sec Introduction
7+
*
8+
* This example demonstrates how to control three stepper motors at once with
9+
* varying speeds using the CA_MotorShield library, an enhancement over the
10+
* Adafruit Motor Shield V2 library, incorporating features for improved motor control.
11+
*
12+
* Developed by CodingArray / hanol JU, building upon the original work by
13+
* Limor Fried/Ladyada for Adafruit Industries and Rob Tillaart's PCA9685_RT library contributions.
14+
*
15+
* This library and example are released under the MIT license.
16+
* Support open-source hardware by purchasing products from your preferred suppliers.
17+
*
18+
* @section license License
19+
*
20+
* MIT License - all text here must be included in any redistribution.
21+
*
22+
*/
23+
24+
#include <CA_MotorShield.h>
25+
26+
// Initialize CA_MotorShield objects for two shields
27+
CA_MotorShield AFMSbot(0x61); // Rightmost jumper closed
28+
CA_MotorShield AFMStop(0x60); // Default address, no jumpers
29+
30+
// Connect two steppers to the top shield
31+
CA_StepperMotor *myStepper1 = AFMStop.getStepper(200, 1);
32+
CA_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);
33+
34+
// Connect one stepper to the bottom shield
35+
CA_StepperMotor *myStepper3 = AFMSbot.getStepper(200, 2);
36+
37+
// Function wrappers for each motor
38+
void forwardStep1() { myStepper1->onestep(FORWARD, SINGLE); }
39+
void backwardStep1() { myStepper1->onestep(BACKWARD, SINGLE); }
40+
void forwardStep2() { myStepper2->onestep(FORWARD, DOUBLE); }
41+
void backwardStep2() { myStepper2->onestep(BACKWARD, DOUBLE); }
42+
void forwardStep3() { myStepper3->onestep(FORWARD, INTERLEAVE); }
43+
void backwardStep3() { myStepper3->onestep(BACKWARD, INTERLEAVE); }
44+
45+
// Wrap the steppers in CA_Stepper objects
46+
CA_Stepper stepper1(forwardStep1, backwardStep1);
47+
CA_Stepper stepper2(forwardStep2, backwardStep2);
48+
CA_Stepper stepper3(forwardStep3, backwardStep3);
49+
50+
void setup() {
51+
AFMSbot.begin(); // Start the bottom shield
52+
AFMStop.begin(); // Start the top shield
53+
54+
// Set speed and acceleration for each stepper
55+
stepper1.setMaxSpeed(100.0);
56+
stepper1.setAcceleration(100.0);
57+
stepper1.moveTo(24);
58+
59+
stepper2.setMaxSpeed(200.0);
60+
stepper2.setAcceleration(100.0);
61+
stepper2.moveTo(50000);
62+
63+
stepper3.setMaxSpeed(300.0);
64+
stepper3.setAcceleration(100.0);
65+
stepper3.moveTo(1000000);
66+
}
67+
68+
void loop() {
69+
// Change direction at the limits
70+
if (stepper1.distanceToGo() == 0) stepper1.moveTo(-stepper1.currentPosition());
71+
if (stepper2.distanceToGo() == 0) stepper2.moveTo(-stepper2.currentPosition());
72+
if (stepper3.distanceToGo() == 0) stepper3.moveTo(-stepper3.currentPosition());
73+
74+
// Run each stepper
75+
stepper1.run();
76+
stepper2.run();
77+
stepper3.run();
78+
}

examples/DCMotorTest/DCMotorTest.ino

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
This is a test sketch for the CA MotorShield library designed to demonstrate controlling DC motors.
3+
It showcases the capabilities of the CA MotorShield for enhanced control of DC motors.
4+
5+
For use with the CA MotorShield
6+
----> Replace "http://www.yourwebsite.com/products/1234" with the actual product page link to direct users to more information about the motor shield.
7+
8+
Developed by CodingArray / hanol JU, leveraging the foundational work of Limor Fried/Ladyada for Adafruit Industries and the PCA9685_RT library enhancements by Rob Tillaart.
9+
*/
10+
11+
#include <CA_MotorShield.h>
12+
13+
CA_MotorShield DC_Motor(0x60); // Create an object and pass the parameter
14+
15+
CA_DCMotor *motor1 = DC_Motor.getMotor(1); // Get motor 1
16+
CA_DCMotor *motor2 = DC_Motor.getMotor(2); // Get motor 2
17+
CA_DCMotor *motor3 = DC_Motor.getMotor(3); // Get motor 3
18+
CA_DCMotor *motor4 = DC_Motor.getMotor(4); // Get motor 4
19+
20+
void setup() {
21+
Serial.begin(115200);
22+
23+
DC_Motor.begin(); // Initialize the motor shield
24+
DC_Motor.setFrequency(1600); // Set the PWM frequency
25+
26+
// Set motor1 to move forward and set its speed
27+
motor1->setSpeed(150);
28+
motor1->run(FORWARD);
29+
30+
// Set motor2 to move forward and set its speed
31+
motor2->setSpeed(150);
32+
motor2->run(FORWARD);
33+
34+
// Set motor3 to move forward and set its speed
35+
motor3->setSpeed(150);
36+
motor3->run(FORWARD);
37+
38+
// Set motor4 to move forward and set its speed
39+
motor4->setSpeed(150);
40+
motor4->run(FORWARD);
41+
42+
delay(500); // Wait for 500 milliseconds
43+
44+
// Set motor1 to move backward and set its speed
45+
motor1->setSpeed(150);
46+
motor1->run(BACKWARD);
47+
48+
// Set motor2 to move backward and set its speed
49+
motor2->setSpeed(150);
50+
motor2->run(BACKWARD);
51+
52+
// Set motor3 to move backward and set its speed
53+
motor3->setSpeed(150);
54+
motor3->run(BACKWARD);
55+
56+
// Set motor4 to move backward and set its speed
57+
motor4->setSpeed(150);
58+
motor4->run(BACKWARD);
59+
60+
delay(500); // Wait for 500 milliseconds
61+
62+
// Reset all channels to their initial state
63+
DC_Motor.allChannelInitialize();
64+
}
65+
66+
void loop() {
67+
// Write code to repeat here
68+
}

0 commit comments

Comments
 (0)