NZRAM Library

This librariry provides access to special part of memory (called "non-zero" RAM or NZRAM) that can store data even if Z-Uno is in sleep mode. Z-Uno provides user up to 32 byes of NZRAM. Note that Z-Uno should still be powered to maintain non-zero memory. On power loss non-zero memory will contain garbage, so a special magic key or CRC is suggested to be used to check memory validity before trust it. Writing to and reading from non-zero memory is very fast and energy efficient (like access to normal variable), but in contrast to any other memory in Z-Uno it is not cleared on next wake up of Z-Uno. Use it to store some data you need to keep from previous wakeup but you don't want to write into non-volatile EEPROM (because it is very energy consuming compared to access to non-zero memory).
  • NZRAM.put()
  • NZRAM.get()
  • NZRAM.write()
  • NZ_BYTE()
#include "EEPROM.h"

// device will sleep until next service button press (or INT1 pulled to LOW)

// LED pin number
#define LED_PIN 13

#define MAGIC_VALUE 42

void setup() {
  byte n;
  pinMode(LED_PIN, OUTPUT);      // set LED pin as output
  // Check that NZRAM contain our magic value
  NZRAM.get(0x0, &n, 1);
  if (n == MAGIC_VALUE) {
    // correct magic value after wake up from sleep mode
    // trust NZRAM data
    NZRAM.get(0x1, &n, 1);
    NZRAM.put(0x1, &n, 1);
  } else {
    // incorrect magic, first boot after battery insert ot rebooted due to low battery
    // initialize NZRAM magic
    n = MAGIC_VALUE;
    NZRAM.put(0x0, &n, 1);
    n = 1;
    NZRAM.put(0x1, &n, 1);

void loop() {
  for (int i = 0; i < n; i++) {
    digitalWrite(LED_PIN, HIGH);   // turn LED on
    delay(100);                    // wait for 1 second
    digitalWrite(LED_PIN, LOW);    // turn LED off
    delay(1000);                   // wait for 1 second