Printer's code doesn't work

Hi ! I made an infinite printer Imgur: The magic of the Internet

I used the code from github in GCodeParser’s folder. I had to change some code lines. GRemoteFull is a program to send the Gcode to the aruino.

At the beginning the pen goes to 0. It had work before, but I had to change something and it doesn’t work anymore. Here is the part where then pen goes to 0 :

	//init our points.
	current_units.x = 0.0;
	current_units.y = 0.0;
	current_units.z = 0.0;
	target_units.x = 0.0;
	target_units.y = 0.0;
	target_units.z = 0.0;
	
	pinMode(X_STEP_PIN, OUTPUT);
	pinMode(X_DIR_PIN, OUTPUT);
	pinMode(X_ENABLE_PIN, OUTPUT);
	pinMode(X_MIN_PIN, INPUT_PULLUP);
	pinMode(X_MAX_PIN, INPUT_PULLUP);
	
	pinMode(Y_STEP_PIN, OUTPUT);
	pinMode(Y_DIR_PIN, OUTPUT);
	pinMode(Y_ENABLE_PIN, OUTPUT);
	//pinMode(Y_MIN_PIN, INPUT_PULLUP);
	//pinMode(Y_MAX_PIN, INPUT_PULLUP);
	
	pinMode(Z_STEP_PIN, OUTPUT);
	pinMode(Z_DIR_PIN, OUTPUT);
	pinMode(Z_ENABLE_PIN, OUTPUT);
	//pinMode(Z_MIN_PIN, INPUT_PULLUP);
	//pinMode(Z_MAX_PIN, INPUT_PULLUP);
	
	//figure our stuff.
	calculate_deltasbis();
        goto_machine_zero();
}

void goto_machine_zero()
{
  Serial.println("init");
  move_to_max(X_MIN_PIN, X_STEP_PIN, X_DIR_PIN, 0);
 // move_to_max(Y_MIN_PIN, Y_STEP_PIN, Y_DIR_PIN, 0);
  Serial.println("ok");
}

void move_to_max(int limiter_pin, int stepper_pin, int stepper_dir_pin,int dir)
{
  /* Moves to the maximum possible position
  */
  if(limiter_pin == 11 || limiter_pin == 12){
  while(can_step(limiter_pin, limiter_pin, 0, 1, dir)){
    do_step(stepper_pin, stepper_dir_pin, 0);
    Serial.print("tapes");
    delay(1);
    
  }
  // slowly back unitl pin is released
  while(!can_step(limiter_pin, limiter_pin, 0, 1, dir)){
    do_step(stepper_pin, stepper_dir_pin, 1);
    Serial.print("recule");
    delay(100);
  }
 }
 else {
   do_step(stepper_pin, stepper_dir_pin, 0);
   Serial.print("bouges");
   }
}

void dda_move(long micro_delay)
{
	//enable our steppers
	digitalWrite(X_ENABLE_PIN, HIGH);
	digitalWrite(Y_ENABLE_PIN, HIGH);
	digitalWrite(Z_ENABLE_PIN, HIGH);
	
	//figure out our deltas
	max_delta = max(delta_steps.x, delta_steps.y);
	max_delta = max(delta_steps.z, max_delta);

	//init stuff.
	long x_counter = -max_delta/2;
	long y_counter = -max_delta/2;
	long z_counter = -max_delta/2;
	
	//our step flags
	bool x_can_step = 0;
	bool y_can_step = 0;
	bool z_can_step = 0;
	
	if (micro_delay >= 16383)
		milli_delay = micro_delay / 1000;
	else
		milli_delay = 0;

	//do our DDA line!
	do
	{
		x_can_step = can_step(X_MIN_PIN, X_MAX_PIN, current_steps.x, target_steps.x, x_direction);
		y_can_step = can_step(Y_MIN_PIN, Y_MAX_PIN, current_steps.y, target_steps.y, y_direction);
		z_can_step = can_step(Z_MIN_PIN, Z_MAX_PIN, current_steps.z, target_steps.z, z_direction);

		if (x_can_step)
		{
			x_counter += delta_steps.x;
			
			if (x_counter > 0)
			{
				do_step(X_STEP_PIN, X_DIR_PIN, x_direction);
				x_counter -= max_delta;
				
				if (x_direction)
					current_steps.x++;
				else
					current_steps.x--;
			}
		}

		if (y_can_step)
		{
			y_counter += delta_steps.y;
			
			if (y_counter > 0)
			{
				do_step(Y_STEP_PIN, Y_DIR_PIN, y_direction);
				y_counter -= max_delta;

				if (y_direction)
					current_steps.y++;
				else
					current_steps.y--;
			}
		}
		
		if (z_can_step)
		{
			z_counter += delta_steps.z;
			
			if (z_counter > 0)
			{
                                if(Z_ENABLE_SERVO==0){
				  do_step(Z_STEP_PIN, Z_DIR_PIN, z_direction);
                                }
				z_counter -= max_delta;
				
				if (z_direction)
					current_steps.z++;
				else
					current_steps.z--;
			}
		}
		
		
				
		//wait for next step.
		if (milli_delay > 0)
			delay(milli_delay);			
		else
			delayMicroseconds(micro_delay);
	}
	while (x_can_step || y_can_step || z_can_step);
	
	//set our points to be the same
	current_units.x = target_units.x;
	current_units.y = target_units.y;
	current_units.z = target_units.z;
	calculate_deltas();
}

bool can_step(byte min_pin, byte max_pin, long current, long target, byte direction)
{
	
        //stop us if we're on target
	if (target == current)
		return false;
	//stop us if we're at home and still going 
	else if (read_switch(min_pin) && !direction)
		return false;
	//stop us if we're at max and still going
	else if (read_switch(max_pin) && direction)
		return false;

	//default to being able to step
	return true;
}

void do_step(byte pinA, byte pinB, byte dir)
{
        switch (dir << 2 | digitalRead(pinA) << 1 | digitalRead(pinB)) {
            case 0: /* 0 00 -> 10 */
            case 5: /* 1 01 -> 11 */
                digitalWrite(pinA, HIGH);
                break;
            case 1: /* 0 01 -> 00 */
            case 7: /* 1 11 -> 10 */
                digitalWrite(pinB, LOW);
                break;
            case 2: /* 0 10 -> 11 */
            case 4: /* 1 00 -> 01 */   
                digitalWrite(pinB, HIGH);
                break;
            case 3: /* 0 11 -> 01 */
            case 6: /* 1 10 -> 00 */
                digitalWrite(pinA, LOW);
                break;
        }
	delayMicroseconds(5);
}


bool read_switch(byte pin)
{
	//dual read as crude debounce
	
	if ( SENSORS_INVERTING )
		return !digitalRead(pin) && !digitalRead(pin);
	else
		return digitalRead(pin) && digitalRead(pin);
}

long to_steps(float steps_per_unit, float units)
{
	return steps_per_unit * units;
}
}

This is the electronic setting : Imgur: The magic of the Internet
The pushbutton represent my limit sensor.

I don’t know if this is the correct way to make a post, I’m a beginner in Arduino’s coding and it’s my first post on a forum.

Don’t hesitate if you need more informations

Thank you all

It had work before, but I had to change something and it doesn't work anymore.

If the change was to the program then I assume that you don't have an earlier version or a backup. Lesson learned I hope.

If the change was mechanical or electrical what did you do last ?

First "big" project, no backup or earlier version so yes I learned :confused:

I only think it comes from the code because i checked if the electricity is passing everywhere and it does... I'll check the electricity again to be sure as soon as i can.

I don't think the issue is mechanical, since I haven't changed anything

I had to change something and it doesn't work anymore.

Why did you have to change something ? What does the program do when you run it ? What should it do ?

Well, I changed some cables, now it moves. But when the pen hits the limit sensor, the stepper motor keeps moving in an irregural jumpy way. If I push the limit sensor with my finger, then when I take my finger off, the motor stops.

If I push the limit sensor with my finger, then when I take my finger off, the motor stops

The motor needs to stop when the switch is pressed so something is wrong with your program logic or wiring.

I am aware of that, but I don't know where the problem is. I tried to use some comands to debug with "Serial.print" but the comand words don't appear each times. Maybe there is a problem with the software that sends the code on my arduino.

If I push the limit sensor with my finger, then when I take my finger off, the motor stops.

It sounds like the limit switch is wired wrongly or the program logic is the wrong way round.

Momotatore:
First "big" project, no backup or earlier version so yes I learned :confused:

Learn about git.