Lower consumption on MKR1200 by reducing clock speed

Hello,

I'm relatively new to Arduino and try to find smart ways to reduce power consumption on my MKR1200.
I'm collecting weight from HX711 and temperature/humidity from DHT22 every hour, using deepsleep (from arduinolowpower.h) between 2 measures (1 measure ~ 5 seconds)
Power supplies at regulated 5V comes from solar power management module from waveshare equipped with 3.7 battery.
I've disconnected the green power led and it now runs in deepsleep at 6mA, which seems to me quite high.

I've read that reducing clock speed from 48Mhz down to 32khz could help lowering power consumption but can't find the appropriate arduino code for MKR1200 to do so.

Can you confirm this action on clock would help reducing power when in deepsleep mode ?
Is there a place to get this code or at least some explanations adapted to MKR1200 ?
I understand clock settings have strong impact on PC communication with arduino board, so I do want to play with fire changing stuffs without knowing a minimum.

Thanks for your help

You are correct reducing the clock speed will reduce current but from what I can determine not by that much on this board. You need to disable all of the LEDs. Before you start changing "stuffs" purchase a few spares, they do not take kindly to abuse. If you really want some help post an annotated schematic, not a frizzy picture. It is also important to post links to "Technical Information" on each of the hardware items you are using. There are several MKR boards that show up when looking for one.

Hello gilshultz,

I'll try to be more precise

Note consumption is 5.3mA in deepSleep with the hereafter code and also 5.3mA if I simply run a deepSleep in a 1 line sketch.

Code is as follow

// Target : every 60mn send Sigfox message with weather datas & weight & battery status, use of deepsleep mode, one interrupt for weight tare and one interrupt to stop sketch and connect PC to USB (for maintenance purposes)


#include <SigFox.h>
#include <DHT_U.h>
#include <HX711.h>
#include <ArduinoLowPower.h>

const int DHTPIN1 = 0;     // Digital pin connected to the DHT sensor external
const int DHTPIN2 = 2;     // Digital pin connected to the DHT sensor internal

const int calibration_balance = -2550;     // load rate
const int ENTREE_ANALOGIQUE = 0;   // analog input to measure battery voltage
const int broche_DT = 5; // HX711 circuit wiring - Data connecteur D5/D6 (5 for sparkfun)
const int broche_SCK = 6;// HX711 circuit wiring - Clock connecteur D5/D6 (6 for sparkfun)
const int delayMS = 10*60*1000;  // Set delay between sensor readings
// Pin used to trigger a wakeup :
const int BOUTON_TARE = 4;
const int BOUTON_PC = 1;

HX711 balance;                      // create scale
DHT_Unified dht1(DHTPIN1, DHT22);   // create sensor temp/humi ext 
DHT_Unified dht2(DHTPIN2, DHT22);   // créate sensor temp/humi int

volatile byte interrupt = 0;
float tare = 0;

void setup() { ////////////////////////////////////////////////////////////////////////////////////
  
delay(1000);
balance.begin(broche_DT, broche_SCK);
delay(1000);
balance.set_scale(calibration_balance); //calibration factor to get hectograms units

/////////// interrupts settings ////////////////
// Pins used to trigger a wakeup
pinMode(BOUTON_TARE, INPUT_PULLUP);
pinMode(BOUTON_PC, INPUT_PULLUP);
// Attach a wakeup interrupt on pin 4, calling "tarage"
LowPower.attachInterruptWakeup(BOUTON_TARE, tarage, FALLING);
LowPower.attachInterruptWakeup(BOUTON_PC, connexionPC, FALLING);

pinMode(3, OUTPUT); // power saving on unused digital I/O ???
}
  

////////////////////////////////////////////////////////////////////////////////////////

// SigFox message structure
typedef struct __attribute__ ((packet)) sigfoxmessage {

  int8_t temp1;
  int8_t temp2;
  uint8_t humi1;
  uint8_t humi2;
  int16_t poids;
  int16_t tare;
  uint8_t tension;
  uint8_t lastMessageStatus;
} SigfoxMessage;


void loop() { //////////////////////////////////////////////////////////////////////////

SigFox.begin();
SigFox.reset();
dht1.begin();
dht2.begin();
delay(2000);

///////////////////// Voltage reading ////////////////////
float valeurLue = analogRead(ENTREE_ANALOGIQUE) ; // read voltage on analog port
// converts reading into voltage in centi-Volts units
uint8_t tensionLue = map(valeurLue, 0, 1023, 0, 50);

///////////////////// temperature/humidity reading ////////////////////
sensors_event_t event1;
dht1.temperature().getEvent(&event1);
float t1 = event1.temperature;
dht1.humidity().getEvent(&event1);
float h1 = event1.relative_humidity;

sensors_event_t event2;
dht2.temperature().getEvent(&event2);
float t2 = event2.temperature;
dht2.humidity().getEvent(&event2);
float h2 = event2.relative_humidity;

//////////////////////////// weight reading ///////////////////////////

if (interrupt == 1) // if grounding on pin 4 then tare the scale
  {
  tare = balance.get_units(10);
  delay(2000);
  REG_EIC_INTFLAG = EIC_INTFLAG_EXTINT4; // empty interrupt events queue  
  delay(2000);
  interrupt=0;
  } 

if (interrupt == 2) // si grounding on pin 4 then wait for PC connection
  {
  Serial.begin(9600);
  delay(2000);
  Serial.println("Connexion...");
  while (digitalRead(BOUTON_PC)== HIGH) {};
  for (int i=1; i<=50000;i++);
  REG_EIC_INTFLAG = EIC_INTFLAG_EXTINT1; // empty interrupt events queue    
  delay(2000);
  interrupt=0;
  } 

float p = balance.get_units(10); // get weight in hectograms
delay(1000);

///////////////////// SigFox message sending ////////////////////

  SigfoxMessage msg; 
  msg.temp1 = (int8_t)t1;
  msg.temp2 = (int8_t)t2;
  msg.humi1 = (uint8_t)h1;
  msg.humi2 = (uint8_t)h2;
  msg.poids = (int16_t)p;
  msg.tare = (int16_t)tare;
  msg.tension = (uint8_t)tensionLue;

    SigFox.beginPacket();
        SigFox.write((uint8_t*)&msg,sizeof(msg));
        msg.lastMessageStatus = SigFox.endPacket();

SigFox.end();
delay(1000);

///////////////////// Go to sleep ////////////////////
LowPower.deepSleep(delayMS);

}

void tarage() // called in interrupt mode when grounding pin 4
{
interrupt = 1;          // to trigger scale tare when getting back in loop (tare action within this subprogram doesn't work)
}

void connexionPC() // called in interrupt mode when grounding pin 1
{
interrupt = 2;  
}

Here is a a small Picture of the layout

Hi
You can reduce the clock with this code:

GCLK->GENDIV.reg = GCLK_GENDIV_DIV(divisor) |  // Divide the 48MHz clock source by divisor 48: 48MHz/48=1MHz
                     GCLK_GENDIV_ID(0);            // Select Generic Clock (GCLK) 0
    while (GCLK->STATUS.bit.SYNCBUSY);             // Wait for synchronization

For example, by dividing the clock by 16 (so 3Mhz) I have reduced my project consumption down to roughly 2.5mA.

Can you please explain how you disconnected the green power LED ?
:slight_smile:
'

Remember, when you reduce the processor clock speed, you lengthen the time for your program to execute the same code. Current is reduced, but power to do the job is the same.

Simply with a cutter on the PCB by disconnecting one pin of the LED !

Hello pcaunegre,

Thanks for the code. I've tried it in a simple loop with deep sleep during 1mn + wake up for 10s.
Although consumption in wake mode decreases, it doesn't in sleep mode (still 5.3mA !) whatever the dividor value.
On your own project, can you confirm you've succeed in getting power saving during sleep mode ?

Hi Paul,

Thanks for your advice. Yes I'm aware of it. My target is to reduce the power specially in sleep mode as it represents more than 99% of the time in my code.
By lowering the frequency of 48Mhz clock as proposed by pcaunegre, it doesn't change the sleep consumption, so I guess deep sleep is managed from another clock.

Any idea ?

Hello faf68,

Have you removed the green led ?
I was not using the low power mode, I just reduced by 16 the clock freq.
Note though that I measured the current through the 3V input.
Using the vin that goes through a regulator may waste some more current.
Pascal

Yes I physically removed the green led and it has saved a lot (~7mA)
I'm using a 5V solar/battery power source plugged into the MKR Carrier 5V input.
I'm aware this is less efficient than a 3V direct input but my power source is only 5V, and moreover DHT22 temperature sensor only works with more than 3.3V, so as far as I understand, I have to do with 5V and not lower :slight_smile: