Author Topic: 2 Questions  (Read 5198 times)

pidow

  • Newbie
  • *
  • Posts: 5
2 Questions
« on: March 07, 2017, 11:10:52 pm »
Hello !
Fisrt sorry for my bad english :/
 i have 2 questions:

First:
i have a digispark, and i have connect servo MG995.
i use this lib :SimpleServo.h (https://github.com/digistump/DigisparkArduinoIntegration/blob/master/libraries/DigisparkSimpleServo/SimpleServo.h)
It's work fine.. BUT it's seems that motor start at 60° to 180° and not 0 to 180°
i try to use negative value to go back, but not work.. i have try many lib, but this only one who work so fine !

Second:
I wish reduce electricity consumption.
Is possible to disable some function, like LED on PCB ? using sleep mode ? In my loop function, i use delay(), do you have a sleep () ?
I wish not use pin to wake it. I'm newbie so be kind :)

Thx a lot ! MERCI !

Arnaud

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: 2 Questions
« Reply #1 on: March 08, 2017, 02:31:20 am »
Welcome!

Not all servos can travel 180°... a lot of them are only around 120°, which seems about right for yours. If you try to turn the servo without the power connected, it will do more than 180° of movement, but a lot of servos only have feedback for around 120° of their movement.

To 'disconnect' the LED, you should be able to cut the trace between the power  LED and the diode (there is a white mark on the silkscreen where to cut). I'm not sure the simplest way to do sleep stuff on the Digispark...

pidow

  • Newbie
  • *
  • Posts: 5
Re: 2 Questions
« Reply #2 on: March 08, 2017, 03:02:54 am »
Hi thx for your reply !
I have try a lot of librairy, and some librairy and i saw the motor goes on 180° So i think that was possible. MG995 servo motor was write to 180° (http://www.servodatabase.com/servo/towerpro/mg995)

I guess it was a configuration in library ?

So no possibility to disable unused function by software ?
thx !

pidow

  • Newbie
  • *
  • Posts: 5
Re: 2 Questions
« Reply #3 on: March 16, 2017, 12:15:44 am »
Hi
Thx for all information. Servo work fine now ! thx a lot !
> I use it only 2 time per day to open and close the doors of the chicken house.

That why i wish to reduce other electricity consumption.
do you have idea to do it ?
thx !

pidow

  • Newbie
  • *
  • Posts: 5
Re: 2 Questions
« Reply #4 on: March 17, 2017, 01:43:59 am »
I must find a solution to get power to servo only when it's necessary. may be with a relay ? is power of digispark is enough to activate a relay ? like this :https://www.amazon.fr/SODIAL-Trigger-Relais-Optocoupleur-Arduino/dp/B00YGPYD0S/ref=sr_1_4?ie=UTF8&qid=1489740251&sr=8-4&keywords=relai+arduino

The system waiting 90% of time. I wish know if i can reduce to the digispark power consume by disable unneed function.
I wish know if it's possible to put digispark in a "sleep".

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: 2 Questions
« Reply #5 on: March 18, 2017, 12:56:56 am »
That relay board should work with the digispark as the optoisolator trigger means the digispark doesn't have to do much work. However, it will probably consume the same amount of power as the servo when it's not doing anything. Have you tried measuring how much current the servo actually draws when it isn't being used? As a quick test, I just checked the idle power of a random hobby servo I had, and it was drawing ~6ma with no load on it. Compared to the ~30mA the digispark as drawing... that isn't anything to worry about!

The power LED on the digispark draws between 2-3ma. So if you cut that trace, you get red of nearly 3ma of unnecessary power drain. If you use a mosfet (or a transistor as Ralf suggested) to control the servo power, you will get back whatever power your servo draws when idling, and won't have the overhead of the relay control board. If there is any weight or pressure on the servo though, it will not hold it's position.

If you use the sleep code shown below in your own code, you'll get the standby power consumption of the digispark down from 30ma down to 18ma. The rest must be due to the regulator and usb circuitry... I haven't been able to get the power consumption lower and should be able to (as the attiny85 chip on the digispark in sleep mode draws less than 1ma). My current thoughts are you would need to get away from the digispark, and design your own circuit around the attiny85, so you could get the really low power requirements. But hopefully someone else may have ideas as to get the lower levels lower. However, I haven't yet been able to get the digispark below 18ma (and that's with the power led trace cut), in sleep mode, and with the P1 led off).

For longer sleep periods like what you talking about, you would set the watchdog to it's maximum of 8 seconds, and then simply keep re-triggering the system_sleep for as many times as you need until the system should be active again. How you would do so I can't say immediately, as I don't know what your requirements are. if it is simply a matter of "eight hours after I press the button, move the servo" then you could simply use a for loop. If it was a matter of sleeping until the light reading across a light sensor reached a particular level, then it would be a bit tricker... possibly a series of sleeps (for say five minutes), and then a couple of checks of the LDR to get a stable reading and see what the light level is, and trigger the servo etc.

Can you provide more information about your requirements and setup? You've said it is only used twice a day, and for moving a servo. Is there a particular reason it needs to be powered all the time? (i.e. does it happen automatically on it's own, or do you press a button, and the servo moves? meaning you could instead be powering the digispark when you press the button, and moving the servo then?) How are you powering the digispark? (usb powerbank? battery?) If it's a USB powerbank, have you considered adding a USB solar panel to charge the powerbank?



Code: [Select]
/*
 Sleepy blink code for the Digispark
*/

#define LED_PIN 1

#include <avr/sleep.h>

// Variables for the Sleep/power down modes:
volatile boolean f_wdt = 1;

// Routines to set and clear bits (used in the sleep code)
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

// the setup function runs once when you press reset or power the board
void setup()
{
  // initialize digital pin LED_PIN as an output.
  pinMode(LED_PIN, OUTPUT);

  setup_watchdog(6); // approximately 1 second sleep
}

// the loop function runs over and over again forever
void loop()
{
  digitalWrite(LED_PIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  system_sleep();  // Send the unit to sleep
  //delay(1000);                       // wait for a second
  digitalWrite(LED_PIN, LOW);    // turn the LED off by making the voltage LOW
  system_sleep();  // Send the unit to sleep
  //delay(1000);                       // wait for a second
}


// SLEEP CODE HELPER FUNCTIONS

// set system into the sleep state
// system wakes up when wtchdog is timed out
void system_sleep()
{
  cbi(ADCSRA, ADEN);                   // switch Analog to Digitalconverter OFF

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
  sleep_enable();

  sleep_mode();                        // System actually sleeps here

  sleep_disable();                     // System continues execution here when watchdog timed out

  sbi(ADCSRA, ADEN);                   // switch Analog to Digitalconverter ON

}

// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii)
{

  byte bb;
  int ww;
  if (ii > 9 ) ii = 9;
  bb = ii & 7;
  if (ii > 7) bb |= (1 << 5);
  bb |= (1 << WDCE);
  ww = bb;

  MCUSR &= ~(1 << WDRF);
  // start timed sequence
  WDTCR |= (1 << WDCE) | (1 << WDE);
  // set new watchdog timeout value
  WDTCR = bb;
  WDTCR |= _BV(WDIE);
}

// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect)
{
  f_wdt = 1; // set global flag
}



« Last Edit: March 18, 2017, 01:54:44 am by PeterF »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: 2 Questions
« Reply #6 on: March 18, 2017, 05:31:23 pm »
Damn! and here I was hoping you'd say "silly person, you can get the digispark down to 2ma idle" or something similar. I'm disappointed in you Ralf!  ;D :lol:

I still can't believe the digispark as configured is chewing that much power when powered via the 5v pin... I'm half tempted to lift the output pin on the regulator up to see if that is being backfed and chewing up power. And then there is the pullup resistor for the USB (P3? whatever...) which will be pulling a little energy. But still... it's drawing over 18 times what a plain Attiny85 would be drawing... not happy Jan! :-O

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: 2 Questions
« Reply #7 on: March 19, 2017, 08:28:37 pm »
Hm... thanks for that Ralf! I had been looking at the datasheets again, and it wasn't making any sense, but your results answer that part of the problem now!  Your cloned circuit power consumption is more in line with that I thought the 'active' power consumption should be, and the digispark is... lets just say well above that (which is understandable given its intended use) ;) That extra 14 mA consumed by the digispark explains my results... so snipping the regulator *should* drop the power consumption down from from 18ma all the way down to 4ma (approximately and theoretically, of course!)... with the bulk of the remaining power useage probably being the USB pullup.