User Tools

Site Tools


oak:tutorials:breadboard_power

This is an old revision of the document!


Oak: 9V Powered Breadboard


{{http://digistump.com/wiki/_media/oak/tutorials/module_board_sleep.png?600|

The Oak is packed with a lot of features, including built-in Wifi, in a small package, making it ideal for somewhat remote projects. Projects where you won't always have access to a 110V / USB power source. That's exactly where a powered breadboard comes in. Being powered by batteries though has it's own set of issues, namely power conservation.

Components used

Part Quantity Identification
Oak with soldered headers 1
Breadboard Power Supply Module 1
9V to Barrel Jack Cable 1
9V Battery 1
Jumper Wires 2

This tutorial will cover using a breadboard power module (DC), as well as Oak power conservation via a sleep function. There are more ways to conserve Oak power including cutting out the onboard LED power, but those are beyond the scope of this example.

Different breadboard power modules should “Spark” your ingenuity for powering the sensors as well. This particular power module offers many options. In addition to power by USB or by DC barrel connector, it has a wide range of outputs as well. This unit powers the rails on each side of the breadboard. But wait there's more! You can also choose between 3.3V, 5V and off. One side can be 3.3V to power your Oak and your 3.3v sensors, the other side you can run 5V power for those things that require it.

Concepts

Sleep

The ESP8266 chip that is the heart of the Oak has the ability to put your device into a sleep mode to conserve power by way of 4 different Deep Sleep modes: WAKE_RF_DEFAULT, WAKE_RFCAL, WAKE_NO_RFCAL, and WAKE_RF_DISABLED. This tutorial will explore the basics of WAKE_RF_DEFAULT, which relies on the internal Oak timer (which remains active while in Deep Sleep) to wake the device automatically.

In order to recover from ANY Deep Sleep mode you MUST jumper the Reset pin and the Wake pin, otherwise the Oak can't trigger itself to wake up. If you fail to connect these two pins, the only option you have to wake the device is to manually enter Config Mode. In this tutorial, the Reset and Wake pins are connected via a yellow jumper wire

When the Oak wakes up from a deep sleep, it will ALWAYS start at the top of the loop function. ALWAYS. Plan accordingly.

In our example below the First Blink Sketch incorporates a Particle.publish to track our Oak's state, a switch the Oak between sleep and non-sleep mode via in if statement, and a button attached to a trigger pin.

The Oak pin diagram can be found here: http://digistump.com/wiki/oak/tutorials/pinout

Circuit


{{http://digistump.com/wiki/_media/oak/tutorials/module_board_sleep.png?600|

Note: There is a yellow jumper between the Reset and Wake pins to enable to Oak to wake itself out of Deep Sleep, otherwise you will be stuck in Deep Sleep mode until you manually put the Oak into Config Mode via a jumper wire from Pin 1 to GND at start-up for a few seconds.

Code

This is the simple code from the First Blink sketch, and an added line for “Deep Sleep”

#include <ESP8266WiFi.h>
#include "stdlib.h"

#define SLEEP_PIN 5
int sleepTimeS = 10; // Use this to easily change the sleep time

void setup()
{                
  pinMode(1, OUTPUT); //LED on Oak
  pinMode(5, INPUT);
}

void loop()
{
  digitalWrite(1, HIGH);
  delay(1000);
  digitalWrite(1, LOW);
  delay(1000);

  // Check to see if sleep mode selected
  
  if (digitalRead(SLEEP_PIN) == LOW) {
     Particle.publish("Oak Setup", "Entering Deep Sleep", 60, PRIVATE);
     ESP.deepSleep(sleepTimeS*1000000, WAKE_RF_DEFAULT); // Sleep
  }
  else
  {
     Particle.publish("Oak Setup","Entering Non Sleep Mode",60,PRIVATE);
  }
}


http://digistump.com/wiki/_media/oak/tutorials/power_sleep_image.jpg?600|

When you run the above code, with your button in an open state, your onboard LED will blink once, then it puts the Oak in a timed Deep Sleep mode, meaning your onboard LED will cease to blink, until the Oak wakes itself up. blinks the LED once, and immediately goes back to sleep. Not enough time for your Oak to reconnect to the internet and send any information. Closing the button circuit however keeps your Oak from sleeping.

To show you how to typically connect a sensor to a powered breadboard, take a look at the Ultrasonic example below for the connection details. As this is the same sketch as in the starter lesson, take a look there for the sketch details.

US-100 Ultrasonic

int trigPin = 2; // Trigger Pin
int echoPin = 4; // Echo Pin
int LEDPin = 1; // Onboard LED
unsigned long Time_Echo_us = 0; 
unsigned long Len_mm  = 0; 
char post_Distance[16];

void setup() {
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(LEDPin, OUTPUT); // Use LED indicator for visual feedback
 }

void loop() {
 digitalWrite(trigPin, LOW); 
 delay(100); 
 digitalWrite(trigPin, HIGH);
 delay(10); 
 digitalWrite(trigPin, LOW);
 Time_Echo_us = pulseIn(echoPin, HIGH);  
 Len_mm = (Time_Echo_us*34/100)/2;
 sprintf(post_Distance, "%04d", Len_mm);
 Particle.publish("distance in mm:", post_Distance);
               
 if((Len_mm < 3000) && (Len_mm > 1)) {   // Length effective range (1, 3000).
 
 digitalWrite(LEDPin, HIGH); 
 }
 else { 
 digitalWrite(LEDPin, LOW); 
 }                           
 delay(1000);                                
 
}

}

When you initially power the oak via a breadboard power supply, you might think that you are “losing” a power pin on the Oak. As can see this isn't the case at all, as the power supply powers the rail, and your other connected devices, so there's no lose of pins.


http://digistump.com/wiki/_media/oak/tutorials/power_supply_sensor.png?600|

Conclusion

Creating IoT is good, creating IoT that are portable, without the need to run pesky wires, for your internet connection, or power is even better. In cases like this, energy is at a premium, and needs to be conserved at all costs, and luckily the Oak allows us to do just that with its sleep modes.

What sensors will you replace the button with to keep you Oak awake long enough to send data, and then go back to sleep?

oak/tutorials/breadboard_power.1471203434.txt.gz · Last modified: 2016/08/14 12:37 by brohan