Nano 33 BLE with external EEPROM

Hello!

Since Nano33 BLE does't have an EEPROM, I am trying to store a value to external EEPROM on DS3231. The code compile without error but after upload, the Com port dissapear and my pc doesn't recognize arduino board anymore. To get the board back I need to press reset button twice and upload a new sketch. Here is a code that I found on a Forum and should work:

#include <RtcDS3231.h>
#include <Wire.h>

#define EEPROM_I2C_ADDRESS 0x57
byte sum = 123;
int readVal = 0; 

void setup() {
 

Serial.begin(9600);
 writeEEPROM(0, sum, EEPROM_I2C_ADDRESS);

}

void loop() {
  // put your main code here, to run repeatedly:
readVal = readEEPROM(0, EEPROM_I2C_ADDRESS);
Serial.println(readVal);
delay(5000);

}

void writeEEPROM(int address, byte sum, int i2c_address){
  // Begin transmission to I2C EEPROM
  Wire.beginTransmission(i2c_address);
 
  // Send memory address as two 8-bit bytes
  Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address & 0xFF)); // LSB
 
  // Send data to be stored
  Wire.write(sum);
 
  // End the transmission
  Wire.endTransmission();
 
  // Add 5ms delay for EEPROM
  delay(5);
}

byte readEEPROM(int address, int i2c_address){
  // Define byte for received data
  byte rcvData = 0x00;
 
  // Begin transmission to I2C EEPROM
  Wire.beginTransmission(i2c_address);
 
  // Send memory address as two 8-bit bytes
  Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address & 0xFF)); // LSB
 
  // End the transmission
  Wire.endTransmission();
 
  // Request one byte of data at current memory address
  Wire.requestFrom(i2c_address, 1);
 
  // Read the data and assign to variable
  rcvData =  Wire.read();
 
  // Return the data as function output
  return rcvData;
}

Does anyone have any working example for Nano 33 BLE?

You need to add Wire.begin() to setup() in your sketch.

When I do that, your sketch stores and reads 123 in my testing.

1 Like

Thank you cattledog. It works. I was searching a whole day for a library or code that would work on Nano 33 BLE and when the board stopped responding I just gave up.