Unusual behaviour with photon while flashing

hi ,
i want to control my dc motors with my photon . everything works fine . the thing is whenever i flash my code , the motors (which were previously in stop condition)starts rotating unusually when the photon is connecting to cloud.

We’d need more background on your setup.

  • What does “rotating unusally” mean?
  • Which pins are you using?
  • Are you running SYSTEM_THREAD(ENABLED)?
  • How does your code look?
  • What drivers are you using?
  • Which debugging effort have you already invested?

And from previous encounters, when you get answers, responding to them would be the least the community would deserve.

sorry for previous behaviour.
so actually i am making a robot having two motors.
by ‘rotating unusually’ i mean there is no specific pattern of how both motors are rotating .

my code:
void forward(){                //Moves robot forward
    Serial.println("forward");
    digitalWrite(in1,HIGH);
    digitalWrite(in2,LOW);
    digitalWrite(in3,HIGH);
    digitalWrite(in4,LOW);
    analogWrite(en1,175);
    analogWrite(en2,175);
    
  }  


void backward(){                //Moves robot backward
    Serial.println("backward");
    digitalWrite(in1,LOW);
    digitalWrite(in2,HIGH);
    digitalWrite(in3,LOW);
    digitalWrite(in4,HIGH);
    analogWrite(en1,175);
    analogWrite(en2,175);
  } 

void leftward(){                   //Rotates robot left
    Serial.println("leftward");
    digitalWrite(in1,LOW);
    digitalWrite(in2,HIGH);
    digitalWrite(in3,HIGH);
    digitalWrite(in4,LOW);
    analogWrite(en1,175);
    analogWrite(en2,175);
  }


void rightward(){                      //Rotates robot right
    Serial.println("rightward");
    digitalWrite(in1,HIGH);
    digitalWrite(in2,LOW);
    digitalWrite(in3,LOW);
    digitalWrite(in4,HIGH);
    analogWrite(en1,175);
    analogWrite(en2,175);
}
  
void stop(){                      //Stops the robot
    Serial.println("STOP");
    digitalWrite(in1,LOW);
    digitalWrite(in2,LOW);
    digitalWrite(in3,LOW);
    digitalWrite(in4,LOW);
    analogWrite(en1,0);
    analogWrite(en2,0);
}

void stop_delay(){                      //Stops the robot
    Serial.println("STOP for 3 SECONDS");
    digitalWrite(in1,LOW);
    digitalWrite(in2,LOW);
    digitalWrite(in3,LOW);
    digitalWrite(in4,LOW);
    analogWrite(en1,0);
    analogWrite(en2,0);
    delay(3000);
} 
  #define in1 4  //  The D4 Pin of particle photon is connected to the input pin 1(IC pin no. 2) of  L293D motor driver 
  #define in2 5  //  The D5 Pin of particle photon is connected to the input pin 2(IC pin no. 7) of  L293D motor driver 
    
  #define in3 6  //  The D6 Pin of particle photon is connected to the input pin 3(IC pin no. 10) of  L293D motor driver 
  #define in4 7  //  The D7 Pin of particle photon is connected to the input pin 4(IC pin no. 15) of  L293D motor driver 
  #define en1 2  //  Enable pin 1 (used for speed control through PWM)
  #define en2 3  //  Enable pin 2 (used for speed control through PWM)`Preformatted text`

void setup (){
    pinMode(in1,OUTPUT);
    pinMode(in2,OUTPUT);
    pinMode(in3,OUTPUT);
    pinMode(in4,OUTPUT);
    pinMode(en1,OUTPUT);
    pinMode(en2,OUTPUT);
    stop();
}
void loop() {
    
    forward();
    backward();
    leftward();
    rightward();

        }

what does SYSTEM_THREAD(ENABLED) mean?

You can/should use the pin names rather than anonymous numbers for your pin assignments.
And you are using pins that are (during bootup) also used as JTAG pins with the respective pull resistors - this may well be the reason for the behaviour you are seeing.
See here
https://docs.particle.io/datasheets/wi-fi/photon-datasheet/#jtag-and-swd

See here
https://docs.particle.io/reference/device-os/firmware/photon/#system-thread

i didn’t enabled SYSTEM_THREAD .i already made my pcb for this .so is there any solution on software side for this

Unfortunately not in user code and I’m not sure how to entirely disable JTAG/SWD on the STM32 directly.

Hmm, what should I say - designing the PCB without considering the datasheet of the Photon and testing on breadboard/protoboard :confused:

1 Like