changing from UNO to Mega - head of robot going haywire

hello,

visited this forum after sometime. I changed from UNO to Mega and my robot head is
going haywire. what needs to be done?.

I presume the code has nothing to do with this change - so I am skeptical to change the code.

I use stepper commands, copied form another sketch which worked beautifully on UNO with smooth movement of head. I am not following 100% the code either as I could not find any explanation on commands/instructions. INT in UNO is 32 bit and on Mega its 64. if the code needs to be changed
let me know.

any leads please?

sunil vijaya

code below
#include <Stepper.h>

//motor head move
int step_mode = 4;
int stepsPerRevolution = 4096 * (step_mode / 4) ;

int mysteps = 1 * stepsPerRevolution;

// initialize the stepper library on pins 8 through 11:

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11, step_mode);

int coords[] = { -512, 1024, 256, -2048, 512, 256};

// when laser beam cut off sound alarm
int sensorPin = A0;
int sensorValue = 0;
int laserPin = 3; // laser beam

int buzzer = 2 ;

void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(10);
// initialize the serial port:
Serial.begin(9600);

// to sound buzzer if laser beam is cut off
pinMode (sensorPin, INPUT);
pinMode (buzzer, OUTPUT) ;//
pinMode (laserPin, OUTPUT);

// pinMode(5, INPUT_PULLUP); //Button 4 with internal pull up

}

void loop() {

// step one revolution in one direction:

Serial.println("clockwise");
myStepper.step(mysteps);
delay(500);

// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-mysteps);
delay(500);

// 2nd Example -> motor steps to the named points in the coords array
int i;
for (i = 0; i < 6; i++) {
int point = coords;
Serial.println("Next point ");
Serial.println(point);
myStepper.step(point);
delay(500);
}
//---------------------------------------------------------------------
// sound buzzer if laser beam is cut off
// sensorValue=analogRead(sensorPin);
// if(sensorValue<=1000) {digitalWrite(buzzer,HIGH);}

noTone(11);
tone(buzzer, 440, 200); // Send 1KHz sound signal...
delay(100); // ...for 1 sec

noTone(6);
tone(buzzer, 494, 500); // Send 1KHz sound signal...
delay(100); // ...for 1 sec

noTone(7);
tone(buzzer, 523, 300);
delay(100);

digitalWrite (laserPin, HIGH); // Turn Laser On
delay (500); // On For Half a Second

noTone(11);
tone(buzzer, 440, 200); // Send 1KHz sound signal...
delay(100); // ...for 1 sec

noTone(6);
tone(buzzer, 494, 1000); // Send 1KHz sound signal...
delay(100); // ...for 1 sec

// else {digitalWrite(buzzer,LOW); }
// sensorValue=1000;

}

SunilV:
I changed from UNO to Mega and my robot head is
going haywire.

[...]

INT in UNO is 32 bit and on Mega its 64. if the code needs to be changed
let me know.

On both an Uno and Mega an int is 16 bits.

What exactly do you mean by "going haywire"? What actually happens, and what should happen?

Post a diagram showing how you have everything connected. A photo of a pencil drawing will be great. Please don't use FRITZING.

And please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

...R

thanks robin for your response.

tried once to post but the photos files were too large.

yes you are right - in both uno and mega - int is 16 bit.

haywire - going really fast left nd right (clock and anti) on mega
and from 180 deg in uno to sometimes 360 deg in mega.

sorry not good at sketches - wiring as per code.

sunil v

SunilV:
tried once to post but the photos files were too large.

Reduce the images to 640x480 and there should be no problem

sorry not good at sketches - wiring as per code.

You really do need to post a wiring diagram because that is quite likely where the problem lies - especially if you have not changed the code when moving from the Uno to the Mega.

The business of making a drawing is a great way to find mistakes.

...R

thx robin.

shall try both.