Monday, 13 December 2021

store the double and Float value in I2C eeprom using arduino

 


#include <Wire.h>

#define address 0x50

char va="as";

int val = 100;

byte data;

double lati1 =32.45678;

String lati = String(lati1);  

String myString = "Hello World";


unsigned int len = myString.length() + 1;



void setup()

 Wire.begin();

 Serial.begin(9600);

 delay(1000); 

byte buff[len];

 //WRITE!!!!*******************************

 Wire.beginTransmission(address);

 Wire.write(0x00);      //First Word Address

 Wire.write(0x00);      //Second Word Address


myString.getBytes(buff, len);


for (int i = 0; i < len; i++)

{  Wire.write(buff[i]);      //Write an 'A'

  Serial.println(buff[i]);

}



 delay(10);


 Wire.endTransmission();

 delay(10);


 //READ!!!!*********************************

 Wire.beginTransmission(address);

 Wire.write(0x00);      //First Word Address

 Wire.write(0x00);      //Second Word Address

 Wire.endTransmission();

 delay(10);


 Wire.requestFrom(address, 1);

 delay(10);

 data = Wire.read();

 Serial.write(data);      //Read the data and print to Serial port

 Serial.println();

 delay(10);

}


void loop()

{

}

No comments:

Post a Comment

Storing the long number(16bits / 32bits) in external flash of arduino or STM32 .

 #include <Wire.h> #define flashaddress 0x50 int liters = 10058 , add1=10 , add2,time1=55; // value of liters save in flash byte data ...