Turn VIN output off?

Hi,

Simple question with an expected disappointing result.

Can I turn on and off the output 5v from the VIN pin using firmware? I’m powering the photon by USB.

I have a couple of servos that are powered by the VIN and it just seems pointless to leave them live in between uses. It would help to stop the servos jittering too.

Cheers

Tim

No, that’s not possible.

To stop the jittering you could call Servo.detach()
But the proper way to depower servos would be via a FET. That would even work if you had the servos powered off an external supply and the Photon via Vin.

For your Servo detach suggestion, would this work?

Servo timservo; 
Servo louservo;// create servo object to control a servo
                // a maximum of eight servo objects can be created
    
int timpos = 0;    // variable to store the servo position for timservo
int loupos = 0;    // variable to store the servo position for louservo
     
void setup()
{
  //Setup the Servo to the function 
  Particle.function("timservo", updatetimServo);
  //Set pin D0 to be an output
  pinMode(D0, OUTPUT);
    
  //Setup the Servo to the function 
  Particle.function("louservo", updatelouServo);
  //Set pin D0 to be an output
  pinMode(D1, OUTPUT);
  //Setup the Servo to the function 
  Particle.function("bothservo", updatebothServo);
  //Take control over the LED on the board
  RGB.control(true);
  //Turn off the LED - we dont want it flashing behind the photo frame at night
  //There may be a better way to do this like turning it off, I found it just as easy to set the colour to nothing
  RGB.color(0, 0, 0);
}
     
void loop()
{
  // We don't need to do anything here
}
     
//This function is triggered by IFTTT - the 'command' word represents the object used to store the 'position' we send to the function.
//The 'position' we send represents where we want the servo to move to
int updatetimServo(String command)
{
  //Attach the servo to D0
**timservo.attach(D0);**
  //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
  uint8_t timpos = command.toInt();
  //This tells the servo, attached to D0 to move to the position defined in the 'command' object that was passed when we triggered this function from IFTTT
  timservo.write(timpos);
  //Flash the LED on so we can see that a message has been recieved - just because we can
  RGB.color(255, 0, 0);
  //Remember to add the delay for 2 seconds, otherwise the LED will just flash for a period of time too small for us to see
  delay(2000);
  //Now set the LED back to off
  RGB.color(0, 0, 0);
  //We return something to signify the end of the function - doesn't really matter what it is
**timservo.detach();**
  return 1;
}
      
//This function is triggered by IFTTT - the 'command' word represents the object used to store the 'position' we send to the function.
//The 'position' we send represents where we want the servo to move to
int updatelouServo(String command)
{
  //Attach the servo to D1
**louservo.attach(D1);**
  //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
  uint8_t loupos = command.toInt();
  //This tells the servo, attached to D1 to move to the position defined in the 'command' object that was passed when we triggered this function from IFTTT
    
  delay(5000);

  louservo.write(loupos);
  //Flash the LED on so we can see that a message has been recieved - just because we can
  RGB.color(0, 0, 255);
  //Remember to add the delay for 2 seconds, otherwise the LED will just flash for a period of time too small for us to see
  delay(2000);
  //Now set the LED back to off
  RGB.color(0, 0, 0);
  //We return something to signify the end of the function - doesn't really matter what it is
**louservo.detach();**
  return 1;
}
    
//This function is triggered by IFTTT - the 'command' word represents the object used to store the 'position' we send to the function.
//The 'position' we send represents where we want the servo to move to
int updatebothServo(String command)
{
  //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
  uint8_t loupos = command.toInt();
  uint8_t timpos = command.toInt();
  //This tells the servo, attached to D1 to move to the position defined in the 'command' object that was passed when we triggered this function from IFTTT
    
  timservo.write(loupos);
  //Flash the LED on so we can see that a message has been recieved - just because we can
  RGB.color(255, 0, 0);
  //Remember to add the delay for 2 seconds, otherwise the LED will just flash for a period of time too small for us to see
  delay(2000);
  //Now set the LED back to off
  RGB.color(0, 0, 0);
  //We return something to signify the end of the function - doesn't really matter what it is
    
  delay(5000);
    
  louservo.write(loupos);
  //Flash the LED on so we can see that a message has been recieved - just because we can
  RGB.color(0, 0, 255);
  //Remember to add the delay for 2 seconds, otherwise the LED will just flash for a period of time too small for us to see
  delay(2000);
  //Now set the LED back to off
  RGB.color(0, 0, 0);
  //We return something to signify the end of the function - doesn't really matter what it is
  return 1;
}

Generally speaking the idea would be like that, but I would recommend against all these delays in the function handlers.
I’d rather put the control logic into loop() and just set the target target servo and position inside the handler.

And just for good practice, try to return a meaningful value like return timpos;, return loupos; and timpos*1000 + loupos;
And e.g. return -1; on error.

Thanks, I’ll have a go at that! For some reason, with the code as above, I’m still getting servo jitter… actually it’s just a constant whine. Do you know why that could be?

That depends how you controlled them.
Your updatebothServo() doesn’t detach.

Some servos don’t like to go all the way to 180° or to zero. Do you get jitter when setting them to 90°?

Yes, pretty much anywhere.

I’ve actually removed that function now.

Here’s the updated code:

    Servo timservo; 
    Servo louservo;// create servo object to control a servo
                    // a maximum of eight servo objects can be created
    
    int timpos = 0;    // variable to store the servo position for timservo
    int loupos = 0;    // variable to store the servo position for louservo
     
    void setup()
    {
    
    //Setup the Servo to the function 
    Particle.function("timservo", updatetimServo);
    //Set pin D0 to be an output
    pinMode(D0, OUTPUT);
    
    //Setup the Servo to the function 
    Particle.function("louservo", updatelouServo);
    //Set pin D0 to be an output
    pinMode(D1, OUTPUT);
    //Take control over the LED on the board
    RGB.control(true);
    //Turn off the LED - we dont want it flashing behind the photo frame at night
    //There may be a better way to do this like turning it off, I found it just as easy to set the colour to nothing
    RGB.color(0, 0, 0);
    }
     
    void loop()
    {
    // We don't need to do anything here
     
    }
     
    //This function is triggered by IFTTT - the 'command' word represents the object used to store the 'position' we send to the function.
    //The 'position' we send represents where we want the servo to move to
    int updatetimServo(String command)
    {
        
    //Attach the servo to D0
    timservo.attach(D1);
    //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
    uint8_t timpos = command.toInt();
    //This tells the servo, attached to D0 to move to the position defined in the 'command' object that was passed when we triggered this function from IFTTT
    timservo.write(timpos);
    //Flash the LED on so we can see that a message has been recieved - just because we can
    RGB.color(255, 0, 0);
    //Remember to add the delay for 2 seconds, otherwise the LED will just flash for a period of time too small for us to see
    delay(2000);
    //Now set the LED back to off
    RGB.color(0, 0, 0);
    //detach the servo
    timservo.detach();
    //We return something to signify the end of the function - doesn't really matter what it is
    return 1;
     
    
      }
      
    
      
    //This function is triggered by IFTTT - the 'command' word represents the object used to store the 'position' we send to the function.
    //The 'position' we send represents where we want the servo to move to
    int updatelouServo(String command)
    {
        
    //Attach the servo to D1
    louservo.attach(D0);
    //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
    uint8_t loupos = command.toInt();
    //This tells the servo, attached to D1 to move to the position defined in the 'command' object that was passed when we triggered this function from IFTTT
    
    delay(5000);
    
    louservo.write(loupos);
    //Flash the LED on so we can see that a message has been recieved - just because we can
    RGB.color(0, 0, 255);
    //Remember to add the delay for 2 seconds, otherwise the LED will just flash for a period of time too small for us to see
    delay(2000);
    //Now set the LED back to off
    RGB.color(0, 0, 0);
    //detach the servo
    louservo.detach();
    //We return something to signify the end of the function - doesn't really matter what it is
    return 1;
     
    
      }

How close is your servo (and the signal wire) to your Photon/Electron’s antenna? Electronic interference could add to jitter, depending on the type of servo.

How much mass are you moving on the servo? Does removing the load eliminate the chatter?

Thanks! I checked and realised that the screw that was holding the servo was too tight and it was rubbing against the edge, causing the jitter… half a turn and issue sorted. Thanks so much both of you (@ScruffR) for your help!

1 Like

one last question… if it’s not too much @ScruffR @BulldogLowell - I don’t want to have to take my product apart again if I can avoid it. Is there a way for me to set-up the wifi credentials on the Photon without having to push the SETUP button? Can I set it to listening mode? If so, how would you go about that bearing in mind that I’m relatively useless at the most advanced functions.

I’m not clear on what you want to do…

Are you asking if you can put the Photon into listening mode if it is unable to connect to a known Wi-Fi network?

@timtiernan, can you start another topic for your question please.