Can someone help me solve this motor control issue

I am currently working on a project that is using a PS/2 mouse to determine the position of the robot. However, there is an issue with the code for the arduino that ends up only moving one motor instead of both, but it performs the correct function by stopping at the coordinate its set at. I don't believe that it is a memory issue, but I am no expert by a long shot. I am using an Arduino Mega for anyone asking. The file titled "Code 1" is a new prototype code I worked on, and have yet to test. The second attachment titled "Code 2" which is the code that is giving be this trouble. I have played with the code and haven't gotten it to work. At one point both motors would spin when I moved the if statement with the md.setspeeds to the top, however I no longer got any data from the mouse itself. The third code titled, "Basic Example" is a code that makes the motors turn consistently without any interruptions or issues. If anyone has an idea of what I could change or what could be done to solve this issue it would be greatly appreciated!

Code 1.txt (1.04 KB)

Code 2.txt (1.11 KB)

Basic Example.txt (319 Bytes)

Quick Update:

The second code turned out to have the same issue as the first leaving me in the same predicament as before.

Hello Everyone,

Here I am again asking for help with this code, however I have narrowed down the issue to basically the Arduino Mega not being able to multi task. The basic thing that I'm asking in the code is for the arduino to just read the mouse data, not to use it or display it to me in any way. While spinning the motors continuously. The issue is that, when doing this I end up with only one motor receiving power to spin while the other doesn't. Maybe I have done something wrong, maybe theirs and issue with the arduino (I tested this on two other ones, with the same problem though) or maybe theirs an issue with the motor controller shield (however this seems to spin the motors fine when its told to just spin them by itself) or maybe its something else. If anyone has any suggestions on how to go about this, I would be very thankful!

My code:

#include "DualVNH5019MotorShield.h"
#include <ps2.h>

PS2 mouse(6, 5);
DualVNH5019MotorShield md;

char mstat;
char mx;
char my;

void setup() {
// put your setup code here, to run once:

Serial.begin(9600);md.init();

}

void loop() {
// put your main code here, to run repeatedly:

mouse.write(0xeb); // give me data!
mouse.read(); // ignore ack
mstat = mouse.read();
mx = mouse.read();
my = mouse.read();

md.setSpeeds(400, 400);
}

JohnBonilla:
(Need answers ASAP PLEASE)

It is not nice to expect to get your problem dealt with before other people who were ahead of you in the queue.

Here I am again asking for help with this code,

That can only mean you have another Thread somewhere on the Forum that deals with the same program. So please click Report to Moderator and ask to have the two Threads merged so we can know what information you have already been given.

...R

(deleted)

Robin2:
It is not nice to expect to get your problem dealt with before other people who were ahead of you in the queue.
That can only mean you have another Thread somewhere on the Forum that deals with the same program. So please click Report to Moderator and ask to have the two Threads merged so we can know what information you have already been given.

...R

I'm sorry if you misunderstood me, but this wasn't me trying to jump ahead. What I meant is that I have posted various coding issues that aren't just about this one topic. I completely agree that I could be taken out of context, and therefore I will change the title. I am only asking for an answer quickly because I am working on a school project. So if you can help me I would very much appreciate it, and if not, thank you for showing me how I might come off so that I can fix it.

Delta_G:
If you really want help fast ( which is doubtful around here with ASAP in the title) then the biggest thing you can do is to help us help you. Don't make it harder than necessary to help you. Go read the "How to use this forum" sticky. Pay attention to the parts about how to post code so it's easy to work with and what sorts of details to include in your posts to get good help. What really separates the wheat from the chaff in this game is the tendency to read the instructions first. It's always the best policy if you want something to work faster.

Do you have a code that makes the motors spin the way you want without all the mouse stuff? What does that look like? Do you have a link to the datasheet or some information on that motor shield? Have you looked it over? Does it say anything about what pins it uses? Are you trying to use any of those pins for your mouse?

Thank you, I will make sure to do that next time I post a question! Yes the code that makes both the motors spin correctly is in a .txt file called basic example. This was the original guide that I used to make the robot and the motor shield distributor (It has all the specs in it if you scroll down):

I have looked over this issue, however found no solution as to why there might be an issue. I haven't tried changing the pins on the arduino to see if there may be an issue. However the might be the reason why one motor spins and the other won't.

Do you have a copy of the wiring schematicIf those motors both move off the same code it sounds to me like it’s a wiring issue.

JohnBonilla:
(It has all the specs in it if you scroll down):

The Instructables website is very tedious to navigate. Please post the relevant info here.

...R

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: