NRF52840 express long term storage

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
chasekaplan
 
Posts: 14
Joined: Tue Jun 01, 2021 10:11 am

NRF52840 express long term storage

Post by chasekaplan »

Hi! I'm wrapping up a summer project and I'm trying to figure out how to store two variables when the integrated button on the feather nrf52840 is clicked and how to retain those two variables during setup when the feather is powered back on. Someone recommended arduino-NVM but I am incredibly confused on how to use it. If someone could show me an example of how to just store and retain the most recent state of the color variable(uint16_t) and message variable(char[50]) as described above and shown in the code below it would be much appreciated.

Thanks for the help,
Chase

Code: Select all

#include <Adafruit_NeoMatrix.h>

#include <bluefruit.h>


#include <EEPROM.h>
#include <avr_eeprom.h>



Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, 2, 1, 3, NEO_TILE_TOP   + NEO_TILE_LEFT   + NEO_TILE_ROWS   + NEO_TILE_PROGRESSIVE + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800);
// BLE Service
BLEDis bledis;
BLEUart bleuart;
uint16_t color = matrix.Color(0, 0, 255);
//var ints
int x = matrix.width();
bool incomplete = true;
char message[50] = "Good Morning Huskies";
int maxDisp;

void setup() {
  // Config Neopixels Matrix
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(40);
  matrix.setTextColor(color); // Blue for Bluefruit
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
  Serial.begin(115200);
  pinMode('D7', INPUT);    // declare pushbutton as input

  while (!Serial) delay(10); // for nrf52840 with native usb
  // Init Bluefruit
  Bluefruit.configPrphBandwidth(BANDWIDTH_LOW);
  Bluefruit.configCentralBandwidth(BANDWIDTH_LOW);
  Bluefruit.configAttrTableSize(1000);
  Bluefruit.configUuid128Count(2);
  Bluefruit.begin(1, 0);
  Bluefruit.setTxPower(4); // Check bluefruit.h for supported values

  // Configure and Start Device Information Service
  bledis.setManufacturer("Adafruit Industries");
  bledis.setModel("Bluefruit Feather52");
  bledis.begin();

  // Configure and start BLE UART service
  bleuart.begin();

  // Set up and start advertising
  startAdv();
}

void startAdv(void) {
  // Advertising packet
  Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
  Bluefruit.Advertising.addTxPower();

  // Include bleuart 128-bit uuid
  Bluefruit.Advertising.addService(bleuart);
  /* Start Advertising
     - Enable auto advertising if disconnected
     - Interval:  fast mode = 20 ms, slow mode = 152.5 ms
     - Timeout for fast mode is 30 seconds
     - Start(timeout) with timeout = 0 will advertise forever (until connected)

     For recommended advertising interval
     https://developer.apple.com/library/content/qa/qa1931/_index.html
  */
  Bluefruit.Advertising.restartOnDisconnect(true);
  Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
  Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
  Bluefruit.Advertising.start(1); // 0 = Don't stop advertising after n seconds
}
void scrollText(void) {
  while (incomplete) {
    matrix.fillScreen(0);
    matrix.setCursor(x, 0);
    matrix.print(message);
    if (--x < -maxDisp) {
      x = matrix.width();
      incomplete = false;
    }
    matrix.show();
    delay(50);
  }
}

void loop() {
  incomplete = true;
  // Echo received data
  if (digitalRead('D7') == LOW) {
    //VARS WILL BE STORED HERE
  }
  else if (Bluefruit.connected() && bleuart.notifyEnabled()) {
    if (bleuart.available()) {
      memset(&message[0], 0, sizeof(message));
      for (int i = 0; i <= 2 * sizeof(bleuart.read()); i++) {
        strcat(message, (char*)bleuart.read());
      }
      maxDisp = sizeof(message) * 4 + matrix.width();
      if ((message[0] == 'C') && (message[1] == '=')) {
        long number = (long) strtol( &message[2], NULL, 16);
        color = (matrix.Color(number >> 16, number >> 8 & 0xFF, number & 0xFF));
        matrix.setTextColor(color);
        return;
      }
      else {
        scrollText();
      }
    }
  }
  else {
    scrollText();
  }
}
Here's a video of my project running if you're interested (yes it's a burger king crown my High School wouldn't let me use anything better): https://youtu.be/Rp9wEtAi4e0

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: NRF52840 express long term storage

Post by mikeysklar »

Ha, I love the Burger King crown holding the flexible matrix. Nice.

arduino-NVM might be a an option. Hopefully it will not interfere with the BLE stack.

You cannot use the standard EEPROM AVR NVM with the Nordic nRF52 itself.

https://github.com/d00616/arduino-NVM/t ... _and_write

If things are just not working out add some FRAM.

https://www.adafruit.com/?q=non-volatil ... =BestMatch

User avatar
chasekaplan
 
Posts: 14
Joined: Tue Jun 01, 2021 10:11 am

Re: NRF52840 express long term storage

Post by chasekaplan »

Yeah, I feel that the crown just exudes class. I'll probably end up going back to Arduino-NVM per your suggestion I just need to figure out how to implement it properly since EEPROM is an entirely new concept to me. Thanks!

User avatar
chasekaplan
 
Posts: 14
Joined: Tue Jun 01, 2021 10:11 am

Re: NRF52840 express long term storage

Post by chasekaplan »

So anytime I try to store using flash or EEPROM, the board just crashes and I have to put it into bootloader mode to get it to do anything. Don't think I'm going to be able to use this library due to soft device incompatibility. If anyone has any suggestions please let me know. I really don't want to put an external storage device on this so I'm open to anything that is doable. Thanks.

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: NRF52840 express long term storage

Post by mikeysklar »

It appears that our nRF52 bootloaders are already using an Adafruit port of LittleFS. This would also allow for persistant storage. You might be able to find some more on using this in a NVM fashion.

https://github.com/littlefs-project/littlefs

https://github.com/adafruit/Adafruit_nR ... t_LittleFS

User avatar
chasekaplan
 
Posts: 14
Joined: Tue Jun 01, 2021 10:11 am

Re: NRF52840 express long term storage

Post by chasekaplan »

I saw that and I appreciate the suggestion I just, unfortunately, have no clue how to use LittleFS or any storage system like that. I tried to find documentation but found very few examples that I could pull from.

User avatar
hathach
 
Posts: 1271
Joined: Tue Apr 23, 2013 1:02 am

Re: NRF52840 express long term storage

Post by hathach »

it is implemented just like an SD, you only need to declare the file using the InternalFS, here are a few examples
https://github.com/adafruit/Adafruit_nR ... _ReadWrite

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”