newbie in need of guidance

Hi everyone, I have ventured into the world of electronics and struggling to combine two sketches. I have went through all the basics of blinking an led, afmotor control, magnotrometer to name but a few. I am finding it hard to go from the basic of using a magnotromoeter and a dc motor control to combining them together to make the motor drive a base plate to the compass heading. There seems to be nothing in between the basics and expert if that makes any sense.

My problem is this.

I have an HMC5883L mag which I have set up and can get readings from in the serial monitor perfectly, a dc motor (AfMotor) to work in forward and reverse but I cant seem to marry the two codes up together to drive the motor to a certain compass heading.

I have downloaded Arduino reference library but this seems to be way out of my knowledge as there is no clear explantions of wording. Whilst I say this I understand that there is a lot of learning to be done for a newbie

Can anyone give me any pointers.?

Thanks for any time.

struggling to combine two sketches

…which you forgot to post

Is the magnetometer mounted on the moving plate?

If the magnetometer is on the plate I hope there is a lot of gearing between the plate and motor so the motor isn't spinning the plate at 1000 RPM!

Hi, the mag is on the plate. i have bought 6 rpm 12v dc motors and I am using a motor shield to control

sorry AWOL, here they are, sorry if they are not how the forum uses but they are from my IDE.

Mag:

#include <Wire.h>
//#include <DebugUtils.h>
#include <HMC58X3.h>
#include <AFMotor.h>
AF_DCMotor motor(1, MOTOR12_8KHZ); // create motor #2, 64KHz pwm

HMC58X3 magn;

void setup() {
Serial.begin(9600);
Wire.begin();
motor.setSpeed(200); // set the speed to 200/
// no delay needed as we have already a delay(5) in HMC5843::init()
magn.init(false); // Dont set mode yet, we’ll do that later on.
// Calibrate HMC using self test, not recommended to change the gain after calibration.
magn.calibrate(1, 32); // Use gain 1=default, valid 0-7, 7 not recommended.
// Single mode conversion was used in calibration, now set continuous mode
magn.setMode(0);

motor.run(FORWARD); // turn it on going forward
delay(1000);
motor.run(RELEASE); // stopped

}

void loop() {
int ix,iy,iz;
float fx,fy,fz;
delay(10);
// Get values, as ints and floats.
magn.getValues(&ix,&iy,&iz);
magn.getValues(&fx,&fy,&fz);
// also available HMC5843::getValues(float *xyz) you can pass to it an array of 3 floats

Serial.print(" Heading: ");
float heading = atan2(fy, fx);
if(heading < 0) {
heading += 2 * M_PI;
}
Serial.println(heading * 180/M_PI);
// x and y axis are swapped above with respect to the above paper as our Z axis points to the sky while in the paper it points to the bottom

delay(250);

}

Motor control is:

#include <AFMotor.h>

AF_DCMotor motor(1, MOTOR12_8KHZ); // create motor #2, 64KHz pwm

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(“Motor test!”);

motor.setSpeed(200); // set the speed to 200/255

Serial.print(“tick”);

motor.run(FORWARD); // turn it on going forward
delay(1000);

Serial.print(“tock”);
motor.run(BACKWARD); // the other way
delay(1000);

Serial.print(“tack”);
motor.run(RELEASE); // stopped
delay(1000);

for (;;);
}

void loop() {
}

Regards

Now, without the smiley, please

Not knowing much about your desires, I will make some rough suggestions: How about using a servo? If you decide to use the dc motor, how about a driver board to run the motor. Don't try motor powered from arduino (may work sometime, but not normal).

I have an adafruit motor driver board which is powered with a 12v power supply, I have both working separate but cant get them to work together.

Sorry about the smiley, not my doing, if it was me it would be a grumpy smile

My goal is to point a satellite dish at a desired heading, I will manually input the heading for the motor to go to but need the compass to work alongside as a reference to the heading the base is at.

if it was me it would be a grumpy smile

made me laugh. Ok, you have a motor control board that works with a motor. But can't be controlled by arduino.

I assume the board will control 2 motors.. Well maybe better than me assuming, can you give us a URL to that board?

goodchild1: Sorry about the smiley, not my doing, if it was me it would be a grumpy smile

7 below will get you started.

http://forum.arduino.cc/index.php/topic,148850.0.html

Oh no, not ZK again. If you have something useful to contribute, please do. Else, maybe go for a nice ride.

jackwp:

if it was me it would be a grumpy smile

made me laugh. Ok, you have a motor control board that works with a motor. But can't be controlled by arduino.

I assume the board will control 2 motors.. Well maybe better than me assuming, can you give us a URL to that board?

If you look at my post previous, Adafruit motor board, says it all really, not 2 dc motors 4 dc motors, steppers and servo's. I am on an arduino forum so one would presume it works with Arduino, or am i not thinking straight?? I must be in the wrong forum.

I see number 7, why pick up and pick faults with people who dont know how this all works, why pick faults - just help people.

I have gave my sketches and my problems but I am no further forward! other than embarressed.

Thanks for all the constructive replies though.

regards

goodchild1, we, none of us, wanted to embarrass you. If there is any embarrassment, it is to us. We only want to help, but sometime we ask questions that may seem inappropriate to you but we think are needed. If I, or we did embarrass you, I/we are sorry. Please let us help you. We want to help. Thanks, Jack

Hi Jackwp, Dont apologies,I must have taken the comments the wrong way. I guess you all can write code and understand code. its just so frustrating not knowing how to go forward. The basics have been completed and I am stuck on the next hurdle.

I think there needs to be more reference for people to learn. I know that people with c language have an advantage and pick things up quicker but I dont have this knowledge like may other people who want to learn..

Again, thanks for any help.

Well, I can write some code, and sometime it works (but not always). I understand some code, but not all. so, if my comment to zoomkat confused you, sorry. ZK and I have been sparring all day. Nothing to do with your posts. You are more than welcome here, and I/we will try our best to solve your problem.