Introduction
Ferroelectric RAM also known as FRAM, is a type of non-volatile memory that is not only much faster than flash memory and EEPROM, but it has a very high endurance -- each byte can be read and written 10,000,000,000,000 times. Therefore it makes for an excellent alternative to EEPROM for low-power, data-logging applications, where data loss can be prevented in the event of a power loss.
In this guide, learn to use FRAM with the Little Bird Uno R3 and a DHT11 temperature and humidity sensor. The latest temperature reading will be saved to the FRAM, and then retrieved on power start.Â
Complete this guide to get started with using FRAM for your data-logging applications.
In this guide, learn to use FRAM with the Little Bird Uno R3 and a DHT11 temperature and humidity sensor. The latest temperature reading will be saved to the FRAM, and then retrieved on power start.Â
Complete this guide to get started with using FRAM for your data-logging applications.
Tools
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#include <SPI.h> #include "Adafruit_FRAM_SPI.h" #include <SimpleDHT.h>
-
#include <SPI.h> #include "Adafruit_FRAM_SPI.h" #include <SimpleDHT.h> const uint8_t FRAM_CS = 10; Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI const uint8_t FRAM_SCK = 13; const uint8_t FRAM_MISO = 12; const uint8_t FRAM_MOSI = 11; const int pinDHT11 = 7; uint16_t addr = 0;
-
#include <SPI.h> #include "Adafruit_FRAM_SPI.h" #include <SimpleDHT.h> const uint8_t FRAM_CS = 10; Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI const uint8_t FRAM_SCK = 13; const uint8_t FRAM_MISO = 12; const uint8_t FRAM_MOSI = 11; const int pinDHT11 = 7; uint16_t addr = 0; SimpleDHT11 dht11(pinDHT11); void setup(void) { Serial.begin(9600); if (fram.begin()) { Serial.println("Found SPI FRAM!"); } else { Serial.println("No SPI FRAM found ... check your connections\r\n"); while (1); } }
-
#include <SPI.h> #include "Adafruit_FRAM_SPI.h" #include <SimpleDHT.h> const uint8_t FRAM_CS = 10; Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI const uint8_t FRAM_SCK = 13; const uint8_t FRAM_MISO = 12; const uint8_t FRAM_MOSI = 11; const int pinDHT11 = 7; uint16_t addr = 0; SimpleDHT11 dht11(pinDHT11); void setup(void) { Serial.begin(9600); if (fram.begin()) { Serial.println("Found SPI FRAM!"); } else { Serial.println("No SPI FRAM found ... check your connections\r\n"); while (1); } } void loop() { // start working... Serial.println("================================="); Serial.println("Sample DHT11..."); // read without samples. byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000); return; } Serial.print("Sample OK: "); Serial.print((int)temperature); Serial.print(" *C, "); Serial.print((int)humidity); Serial.println(" H"); // DHT11 sampling rate is 1HZ. delay(1500); }
-
#include <SPI.h> #include "Adafruit_FRAM_SPI.h" #include <SimpleDHT.h> const uint8_t FRAM_CS = 10; Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI const uint8_t FRAM_SCK = 13; const uint8_t FRAM_MISO = 12; const uint8_t FRAM_MOSI = 11; const int pinDHT11 = 7; uint16_t addr = 0; SimpleDHT11 dht11(pinDHT11); void setup(void) { Serial.begin(9600); if (fram.begin()) { Serial.println("Found SPI FRAM!"); } else { Serial.println("No SPI FRAM found ... check your connections\r\n"); while (1); } } void loop() { const unsigned long fiveMinutes = 5 * 60 * 1000UL; static unsigned long lastSampleTime = 0 - fiveMinutes; // initialize such that a reading is due the first time through loop() unsigned long now = millis(); if (now - lastSampleTime >= fiveMinutes) { lastSampleTime += fiveMinutes; // add code to take temperature reading here // read without samples. byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.println(err); delay(1000); return; } Serial.print((int)temperature); Serial.println(" *C "); } // add code to do other stuff here }
-
#include <SPI.h> #include "Adafruit_FRAM_SPI.h" #include <SimpleDHT.h> const uint8_t FRAM_CS = 10; Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI const uint8_t FRAM_SCK = 13; const uint8_t FRAM_MISO = 12; const uint8_t FRAM_MOSI = 11; const int pinDHT11 = 7; uint16_t addr = 0; SimpleDHT11 dht11(pinDHT11); void setup(void) { Serial.begin(9600); if (fram.begin()) { Serial.println("Found SPI FRAM!"); } else { Serial.println("No SPI FRAM found ... check your connections\r\n"); while (1); } } void loop() { const unsigned long fiveMinutes = 5 * 60 * 1000UL; static unsigned long lastSampleTime = 0 - fiveMinutes; // initialize such that a reading is due the first time through loop() unsigned long now = millis(); if (now - lastSampleTime >= fiveMinutes) { lastSampleTime += fiveMinutes; // add code to take temperature reading here // read without samples. byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.println(err); delay(1000); return; } Serial.print((int)temperature); Serial.println(" *C "); fram.writeEnable(true); fram.write8(0x0, temperature) fram.writeEnable(false); } // add code to do other stuff here }
-
#include <SPI.h> #include "Adafruit_FRAM_SPI.h" #include <SimpleDHT.h> const uint8_t FRAM_CS = 10; Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI const uint8_t FRAM_SCK = 13; const uint8_t FRAM_MISO = 12; const uint8_t FRAM_MOSI = 11; const int pinDHT11 = 7; uint16_t addr = 0; SimpleDHT11 dht11(pinDHT11); void setup(void) { Serial.begin(9600); if (fram.begin()) { Serial.println("Found SPI FRAM!"); } else { Serial.println("No SPI FRAM found ... check your connections\r\n"); while (1); } uint8_t value = fram.read8(0x0); Serial.print("Last Temperature:"); Serial.print(value); Serial.println(" *C "); } void loop() { const unsigned long fiveMinutes = 5 * 60 * 1000UL; static unsigned long lastSampleTime = 0 - fiveMinutes; // initialize such that a reading is due the first time through loop() unsigned long now = millis(); if (now - lastSampleTime >= fiveMinutes) { lastSampleTime += fiveMinutes; // add code to take temperature reading here // read without samples. byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.println(err); delay(1000); return; } fram.writeEnable(true); fram.write8(0x0, temperature); fram.writeEnable(false); } // add code to do other stuff here }