Hi, all,
I am working on a project driving a DC motor with a encoder.
I am wondering if the serial I2C communication between arduino and motor shield will have influence on the attachInterrupt fonction.
If I write " mymotor.setspeed(100) " in the loop, the Count fonction in the attachInterrupt will be activated.
On the other hand, if I run a DC motor with this shield, once I connect the encoder to the PIN3 ( leonardo interrupt int0 ), the motor will be cut off. It's really bizarre.
Could anyone help me with that?
Thanks~
Motor Shield V2 interrupt problem
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88152
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 interrupt problem
Pins 2 and 3 are the i2c bus on the Leonardo. They are required for communication with the shield.
You should try interrupt 2, 3 or 4.
http://arduino.cc/en/Main/arduinoBoardLeonardo
You should try interrupt 2, 3 or 4.
http://arduino.cc/en/Main/arduinoBoardLeonardo
TWI: 2 (SDA) and 3 (SCL). Support TWI communication using the Wire library.
External Interrupts: 3 (interrupt 0), 2 (interrupt 1), 0 (interrupt 2), 1 (interrupt 3) and 7 (interrupt 4). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
- waverider995
- Posts: 5
- Joined: Thu Apr 09, 2015 2:09 pm
Re: Motor Shield V2 interrupt problem
Thanks a lot!
It seems that's only interrupt 4 (pin7) works on a leonardo.
It seems that's only interrupt 4 (pin7) works on a leonardo.
- adafruit_support_bill
- Posts: 88152
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 interrupt problem
Interrupts 2 and 3 are on pins 0 and 1. These pins are also used for serial communication, so if you do anything with the serial port, you can't use these for interrupts.It seems that's only interrupt 4 (pin7) works on a leonardo.
- waverider995
- Posts: 5
- Joined: Thu Apr 09, 2015 2:09 pm
Re: Motor Shield V2 interrupt problem
So if I want to control 2 DC motors + 2 encoders, using your motor shield, I'd better to change to an arduino Mega?
- adafruit_support_bill
- Posts: 88152
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 interrupt problem
A Mega would work. An UNO would probably work also. The i2c bus for the Uno is on A4 and A5. The 2 external interrupt pins are on pins 2 and 3.
- waverider995
- Posts: 5
- Joined: Thu Apr 09, 2015 2:09 pm
Re: Motor Shield V2 interrupt problem
Thanks a lot !
That really helps!
That really helps!
Please be positive and constructive with your questions and comments.