name: title class: center, middle, inverse layout: true --- name: inverse class: center, middle, inverse layout: true .header[.floatleft[.teal[Christopher Biggs] — Around the world in 80uA].floatright[.teal[@unixbigot] .logo[@accelerando_au]]] .footer[.floatleft[The Linux Of Things .hashtag.teal[lca2019] --- Jan 2019 Christchurch, NZ]] --- name: callout class: center, middle, italic, bulletul layout: true .header[.floatleft[.teal[Christopher Biggs] — Around the world in 80uA].floatright[.teal[@unixbigot] .logo[@accelerando_au]]] .footer[.floatleft[The Linux Of Things .hashtag.teal[lca2019] --- Jan 2019 Christchurch, NZ]] --- layout: true template: callout .header[.floatleft[.teal[Christopher Biggs] — Around the world in 80uA].floatright[.teal[@unixbigot] .logo[@accelerando_au]]] .footer[.floatleft[The Linux Of Things .hashtag[lca2019] --- Jan 2019 Christchurch, NZ]] --- class: center, middle, inverse template: title .fig100[ ] --- layout: true template: callout .crumb[ # Intro ] --- class: vtight # Who am I? ## Christopher Biggs — .teal[@unixbigot] — .logo[@accelerando_au] * Brisbane, Australia * Linux user since the very beginning (floppy discs at 2400 baud!) * Convenor, Brisbane Internet Of Things Meetup * Founder, .logo[Accelerando Consulting] * Accelerando is a "full service" consultancy - chips to cloud ??? I operate Accelerando Consulting which helps businesses use technology to reduce stress. Really, that's what I believe, that technology is the gradual process of freeing humanity from drudgery and fear, and I started Accelerando because I wanted to contribute to a future that I will be excited to live in. --- # Shameless Self-Promotion ## Brisbane (AU) Internet of Things Meetup * Evening Symposia 4th Mondays * Afternoon Workshops 2nd Saturdays * Visitors and speakers welcome! --- layout: true template: callout .crumb[ # Intro # Promise ] --- class: center, middle template: inverse # The Promise --- # Kill the clipboard -- ## Sensors everywhere* .footnote[Hold the creepy] -- ## Control everything -- ## Reduced cognitive load => Bliss --- layout: true template: callout .crumb[ # Intro # Promise # Problem ] --- class: center, middle template: inverse # The Problem --- # Wires are hard --- # But use 'em if you got 'em ## PoE, EoP, EoC... --- # Radio killed the Ethernet Star ## Wifi solves all our problems, right? -- ### Sure, for the first hour. --- layout: true template: callout .crumb[ # Welcome # Promise # Problem # Batteries 101 ] --- class: center, middle template: inverse # Batteries 101 --- # Batteries are pretty bad --- # Battery tech * Lead-Acid (cars, old solar) -- * Nickel Metal-Hydride (satellites, cameras) -- * Single-use Dry Cells - Carbon-Zinc, Alkaline-Manganese (dead cameras) -- * Lithium (everything from phones, to cars, to grid storage) --- # Thinking about Battery Capacity --- # Lets build a FarmBot sprinkler -- ## Water tank <==> Battery ## Water molecules <==> Electrons ## Hoses <==> Wires --- # Lets build a FarmBot sprinkler ## Height of tank (water pressure) <==> Potential Difference ### Joules per Coulomb aka "Volts" --- # Lets build a FarmBot sprinkler ## Amount of water flowing <==> Electric Current ### Coulombs per Second aka "Amperes" --- # Lets build a FarmBot sprinkler ## Tank capacity (litres) <==> Battery capacity ### Number of electrons, aka Coulombs, or, more usefully "Ampere-Hours" ---  # Our standard battery ## One "Penguin Chapstick" ### (1PC == 2000 MilliAmpere-Hours == 2.0Ah) --- # Lets ignore voltage, too, today. * One Lithium-Ion Cell is 3.7 Volts* * Most of our IoT electronics wants 3.3 Volts * USB's 5 Volts makes a handy charging voltage .footnote[ish. Varies ~4.1V full, down to ~3.0v empty] ---  # EVERYTHING IS A LIE -- * eg, Marked 5000mAh (2.5PC). -- * In reality, less than one PC. --- ## Lies are so prevalent they created a market * Inexpensive USB power loggers .fig50[ ]-- * or, make your own with a measurement module and your Pi Zero --- # But The Emperor (Penguin) Is Not Wearing Any Clothes ## Energy capacity is customarily quoted for 20-hour discharge ### Leaky pipes mean there is not a linear relationship --- # Thank you, Nerds ## Lithium battery improvements driven by: * Phones * Quadcopters * Electric Vehicles --- .fig70[ ] .spacedown[ # "Please do not recline your seat"] --- layout: true template: callout .crumb[ # Welcome # Problem # Metering # Batteries 101 # COTS ] --- class: center, middle template: inverse # Commerical Off-The-Shelf solutions --- .fig50[ ] .spacedown[ # Overdrawn at the Power Bank] ---  .spacedown[ # The Powerhouse of the Cell] --- .fig40[ ] .spacedown[ # A "Battery Managment System"] --- .fig40[ ] # Here comes the Sun --- .fig30[ ] .spacedown[ # Pi is irrational ] --- .fig60[ ] .spacedown[ #LiFePO4wered ## Thoughtful design ### (Still only runs a few hours)] --- layout: true template: callout .crumb[ # Welcome # Problem # Metering # Batteries 101 # COTS # Sleep ] --- class: center, middle template: inverse # Using sleep modes to reduce power usage --- # Computers are fast, objects are slow --- # Wake me when something interesting happens ## General shape of deep sleep * Configure one or more "wake interrupts" * Turn off as much of the chip as possible * Halt (or run very slowly) until an interrupt occurs --- # Arduino deep sleep * Interrupt pins * Serial communications * Sleep consumption as low as 6 *micro* Amperes (38 years / PC) * But watch out for the stock voltage regulator (eats 10mA) ---  # ESP 8266 sleep modes * "Modem sleep" just turns off the radio when not needed * Light sleep - cpu is "idling" * Deep sleep - cpu is halted * Wire the wake pin to the reset pin * Can deepsleep for up to 71mins * You can jury-rig a reset-on-some-event --- # ESP 32 Sleep modes * As for ESP8266 but deep-sleep is much more useful * Wake on defined transmition of any (one) IO pin * Wake on one-low or all-high on a number of IOpins * Watch out for complicated numbering of IO pins * Wake on touch sensor * Wake on signal from ultra-low-power coprocessor .fig30[ ] --- layout: true template: callout .crumb[ # Welcome # Problem # Metering # Batteries 101 # COTS # Sleep # ULP ] --- class: center, middle template: inverse # Using Ultra-Low-Power coprocessors --- # The ESP Ultra-Low-Power coprocessor * A slow, 4-register, 16-bit RISC processor * RTC "slow memory" can be accessed by main core * Load a program into slow memory and run it * Configure the ULP wake up interval * ULP can choose to go back to sleep, or wake the main cores * Fairly usable from RTOS and Arduino. * **Maybe** could be jury-rigged from Python, JS or Lua --- # ULP example (Arduino Code) .code[ ```c++ void setup() { esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (cause != ESP_SLEEP_WAKEUP_ULP) { Serial.printf("Not ULP wakeup (i.e. cold boot) initializing ULP\n"); ulp_load_binary(0, ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start) / sizeof(uint32_t)); ulp_max_count = 100; ulp_set_wakeup_period(0, 10 * 10000); } else { Serial.printf("ULP wakeup, inspect the status\n"); go_do_stuff(); } esp_deep_sleep_start(); // NOTREACHED } ```] --- # ULP example ctd. (ULP Code) .tinycode.fl[ ```c++ .bss .global max_count: max_count: .long 0 counter: .long 0 .text .global entry entry: /* Read counter, increment, save back to RAM */ move r3, counter ld r0, r3, 0 add r0, r0, 1 st r0, r3, 0 ``` ] .tinycode.fl[ ```c++ /* check for a change of state on some IO pin */ /* get count in r1 (code elided) */ sub r2, r0, r1 jump wake_up, eq /* Put ULP back to sleep */ .global exit exit: halt .global wake_up wake_up: /* Wake up the SoC and stop ULP program */ wake halt ``` ] --- layout: true template: callout .crumb[ # Welcome # Problem # Metering # Batteries 101 # COTS # Sleep # ULP # DIY ] --- class: center, middle template: inverse # Designing your own low power device --- # Aim for efficency * Sleep as much as possible * Use interrupts not polling where possible * Reduce unnecessary words * Reduce unnecessary words --- # Avoid nasty surprises * Simple resistor ladders leak power * Linear regulators eat power * Poor antennas cost watts * Beware USB programming bridges that are always on --- .fig60[ ] .spacedown[# Monitor your battery level ## ...but without wasting it ] --- .fig60[ ] .fig60[ ] .spacedown[ # Recharge in place ## Inexpensive single-chip Lithium battery chargers abound ] --- # Turn off unused modules * Got a radio transmitter? Switch it off when not in use * Need to receive? Work out how to do that on a schedule --- # Turn off unused chip features * Shut off bluetooth if you're not using it * Run only as fast as you need to --- # Not so flashy ## If you must use LED indicators: * Use low duty cycles (eg 100ms on, 900ms off) * Use low intensity (either in software or hardware) --- # Don't go *too* far .fig80[ ] --- layout: true template: callout .crumb[ # Welcome # Problem # Metering # Batteries 101 # COTS # Sleep # ULP # DIY # Results ] --- class: center, middle template: inverse # Case Study: 5 years between meals ## Maybe ---  # The problem: wireless utility metering retrofit * Monitor a physical rotating dial * Optical or magnetic sensing of rotations * Count rotations, transmit total periodically * Run in a cellar or meter box, forever --- .fig50[ ] # The solution * ESP-32 microcontroller * Wifi for setup and maintenance * LoRA for communication every 15 minutes * ULP coprocessor monitor 4 sensors * ULP wakes CPU after number of elapsed minutes and/or pulses --- .fig50[ ] # How's it stack up * 150mA when communicating over wifi * 100mA when communicating over for LoRA * 50mA when idle, with radio(s) on * 40mA when idle (radio off) * 80uA in deep sleep * Average under 1mA => battery life 1-5 years --- layout: true template: callout .crumb[ # Welcome # Problem # Metering # Batteries 101 # COTS # Sleep # ULP # DIY # Results # Coda ] --- .fig30[  ] # Recap .nolm.vtight[ * Wires are hard * Measure and understand your power usage * Batteries 101 * Off the shelf battery systems * The basics of "Deep Sleep" * The ESP32 Ultra-Low-Power Coprocessor * Designing your own battery-friendly systems * Projecting and monitoring your battery lifetime ] --- # Resources, Questions ## Related talks - [http://christopher.biggs.id.au/#talks](http://christopher.biggs.id.au/#talks) - Email: .blue[christopher @ biggs.id.au] - Twitter: .blue[@unixbigot] - BNE IoT Meetup: .blue[@iotbne] - Accelerando Consulting - IoT, DevOps, Big Data - .blue[@accelerando_au] https://accelerando.com.au/