|
1 |
| -/* |
2 |
| - Read and write settings and calibration data to an external I2C EEPROM |
3 |
| - By: Nathan Seidle |
4 |
| - SparkFun Electronics |
5 |
| - Date: December 11th, 2019 |
6 |
| - License: This code is public domain but you buy me a beer if you use this |
7 |
| - and we meet someday (Beerware license). |
8 |
| - Feel like supporting our work? Buy a board from SparkFun! |
9 |
| - https://www.sparkfun.com/products/14764 |
10 |
| -
|
11 |
| - This example demonstrates how to read and write various variables to memory. |
12 |
| -
|
13 |
| - The I2C EEPROM should have all its ADR pins set to GND (0). This is default |
14 |
| - on the Qwiic board. |
15 |
| -
|
16 |
| - Hardware Connections: |
17 |
| - Plug the SparkFun Qwiic EEPROM to an Uno, Artemis, or other Qwiic equipped board |
18 |
| - Load this sketch |
19 |
| - Open output window at 115200bps |
20 |
| -*/ |
21 |
| - |
22 |
| -#include <Wire.h> |
23 |
| - |
24 |
| -#include "SparkFun_External_EEPROM.h" // Click here to get the library: http://librarymanager/All#SparkFun_External_EEPROM |
25 |
| -ExternalEEPROM myMem; |
26 |
| - |
27 |
| -void setup() |
28 |
| -{ |
29 |
| - Serial.begin(115200); |
30 |
| - Serial.println("Qwiic EEPROM example"); |
31 |
| - |
32 |
| - Wire.begin(); |
33 |
| - |
34 |
| - if (myMem.begin() == false) |
35 |
| - { |
36 |
| - Serial.println("No memory detected. Freezing."); |
37 |
| - while (1) |
38 |
| - ; |
39 |
| - } |
40 |
| - Serial.println("Memory detected!"); |
41 |
| - |
42 |
| - Serial.print("Mem size in bytes: "); |
43 |
| - Serial.println(myMem.length()); |
44 |
| - |
45 |
| - //Yes you can read and write bytes, but you shouldn't! |
46 |
| - byte myValue1 = 200; |
47 |
| - myMem.write(0, myValue1); //(location, data) |
48 |
| - |
49 |
| - byte myRead1 = myMem.read(0); |
50 |
| - Serial.print("I read: "); |
51 |
| - Serial.println(myRead1); |
52 |
| - |
53 |
| - //You should use gets and puts. This will automatically and correctly arrange |
54 |
| - //the bytes for larger variable types. |
55 |
| - int myValue2 = -366; |
56 |
| - myMem.put(10, myValue2); //(location, data) |
57 |
| - int myRead2; |
58 |
| - myMem.get(10, myRead2); //location to read, thing to put data into |
59 |
| - Serial.print("I read: "); |
60 |
| - Serial.println(myRead2); |
61 |
| - |
62 |
| - float myValue3 = -7.35; |
63 |
| - myMem.put(20, myValue3); //(location, data) |
64 |
| - float myRead3; |
65 |
| - myMem.get(20, myRead3); //location to read, thing to put data into |
66 |
| - Serial.print("I read: "); |
67 |
| - Serial.println(myRead3); |
68 |
| -} |
69 |
| - |
70 |
| -void loop() |
71 |
| -{ |
72 |
| -} |
| 1 | +/* |
| 2 | + Read and write settings and calibration data to an external I2C EEPROM |
| 3 | + By: Nathan Seidle |
| 4 | + SparkFun Electronics |
| 5 | + Date: December 11th, 2019 |
| 6 | + License: This code is public domain but you buy me a beer if you use this |
| 7 | + and we meet someday (Beerware license). |
| 8 | + Feel like supporting our work? Buy a board from SparkFun! |
| 9 | + https://www.sparkfun.com/products/14764 |
| 10 | +
|
| 11 | + This example demonstrates how to read and write various variables to memory. |
| 12 | +
|
| 13 | + The I2C EEPROM should have all its ADR pins set to GND (0). This is default |
| 14 | + on the Qwiic board. |
| 15 | +
|
| 16 | + Hardware Connections: |
| 17 | + Plug the SparkFun Qwiic EEPROM to an Uno, Artemis, or other Qwiic equipped board |
| 18 | + Load this sketch |
| 19 | + Open output window at 115200bps |
| 20 | +*/ |
| 21 | + |
| 22 | +#include <Wire.h> |
| 23 | + |
| 24 | +#include "SparkFun_External_EEPROM.h" // Click here to get the library: http://librarymanager/All#SparkFun_External_EEPROM |
| 25 | +ExternalEEPROM myMem; |
| 26 | + |
| 27 | +void setup() |
| 28 | +{ |
| 29 | + Serial.begin(115200); |
| 30 | + Serial.println("Qwiic EEPROM example"); |
| 31 | + |
| 32 | + Wire.begin(); |
| 33 | + |
| 34 | + if (myMem.begin() == false) |
| 35 | + { |
| 36 | + Serial.println("No memory detected. Freezing."); |
| 37 | + while (1) |
| 38 | + ; |
| 39 | + } |
| 40 | + Serial.println("Memory detected!"); |
| 41 | + |
| 42 | + Serial.print("Mem size in bytes: "); |
| 43 | + Serial.println(myMem.length()); |
| 44 | + |
| 45 | + //Yes you can read and write bytes, but you shouldn't! |
| 46 | + byte myValue1 = 200; |
| 47 | + myMem.write(0, myValue1); //(location, data) |
| 48 | + |
| 49 | + byte myRead1 = myMem.read(0); |
| 50 | + Serial.print("I read: "); |
| 51 | + Serial.println(myRead1); |
| 52 | + |
| 53 | + //You should use gets and puts. This will automatically and correctly arrange |
| 54 | + //the bytes for larger variable types. |
| 55 | + int myValue2 = -366; |
| 56 | + myMem.put(10, myValue2); //(location, data) |
| 57 | + int myRead2; |
| 58 | + myMem.get(10, myRead2); //location to read, thing to put data into |
| 59 | + Serial.print("I read: "); |
| 60 | + Serial.println(myRead2); |
| 61 | + |
| 62 | + float myValue3 = -7.35; |
| 63 | + myMem.put(20, myValue3); //(location, data) |
| 64 | + float myRead3; |
| 65 | + myMem.get(20, myRead3); //location to read, thing to put data into |
| 66 | + Serial.print("I read: "); |
| 67 | + Serial.println(myRead3); |
| 68 | + |
| 69 | + String myString = "Hi, I am just a simple test string"; |
| 70 | + unsigned long nextEEPROMLocation = myMem.putString(30, myString); |
| 71 | + String myRead4 = ""; |
| 72 | + myMem.getString(30, myRead4); |
| 73 | + Serial.print("I read: "); |
| 74 | + Serial.println(myRead4); |
| 75 | + Serial.print("Next available EEPROM location: "); |
| 76 | + Serial.println(nextEEPROMLocation); |
| 77 | +} |
| 78 | + |
| 79 | +void loop() |
| 80 | +{ |
| 81 | +} |
0 commit comments