Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReadMe.md 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # Arduino External EEPROM Library v3.4 #
  2. Original library by http://github.com/JChristensen/extEEPROM
  3. ## Introduction ##
  4. **Arduino External EEPROM Library**
  5. This library will work with most I2C serial EEPROM chips between 2k bits and 2048k bits (2M bits) in size. Multiple EEPROMs on the bus are supported as a single address space. I/O across block, page and device boundaries is supported. Certain assumptions are made regarding the EEPROM device addressing. These assumptions should be true for most EEPROMs but there are exceptions, so read the datasheet and know your hardware.
  6. The library should also work for EEPROMs smaller than 2k bits, assuming that there is only one EEPROM on the bus and also that the user is careful to not exceed the maximum address for the EEPROM.
  7. The **extEEPROM Library** has been tested with:
  8. - Microchip 24AA02E48 (2k bit)
  9. - 24xx32 (32k bit, thanks to Richard M)
  10. - Microchip 24LC256 (256k bit)
  11. - Microchip 24FC1026 (1M bit, thanks to Gabriele B on the Arduino forum)
  12. - ST Micro M24M02 (2M bit)
  13. - Atmel AT24C256C (32k x 8, thanks to Searobin)
  14. The **extEEPROM Library** will **NOT** work with Microchip 24xx1025 as its control byte does not conform to the following assumptions.
  15. **Device addressing assumptions:**
  16. - The I2C address sequence consists of a control byte followed by one address byte (for EEPROMs <= 16k bits) or two address bytes (for EEPROMs > 16k bits).
  17. - The three least-significant bits in the control byte (excluding the R/W bit) comprise the three most-significant bits for the entire address space, i.e. all chips on the bus. As such, these may be chip-select bits or block-select bits (for individual chips that have an internal block organization), or a combination of both (in which case the block-select bits must be of lesser significance than the chip-select bits).
  18. - Regardless of the number of bits needed to address the entire address space, the three most-significant bits always go in the control byte. Depending on EEPROM device size, this may result in one or more of the most significant bits in the I2C address bytes being unused (or "don't care" bits).
  19. - An EEPROM contains an integral number of pages.
  20. Note that the Arduino Wire library has a buffer size of 32 bytes. This limits the size of physical I/Os that can be done to EEPROM. For writes, one or two bytes are used for the address, so writing is therefore limited to 31 or 30 bytes. Because the **extEEPROM Library** will handle I/O across block, page and device boundaries, the only consequence this has for the user is one of efficiency; arbitrarily large blocks of data can be written and read; however, carefully chosen block sizes may reduce the number of physical I/Os needed.
  21. ## Installation ##
  22. ### Install with the Library Manager
  23. - For Arduino IDE versions 1.6.2 and up, add library by selecting "Manage Libraries..." from the "Include Library" submenu within the Sketch menu.
  24. - The library manager will open and you will find a list of libraries that are already installed or ready for installation. Scroll the list to find **extEEPROM** library and click on it.
  25. - Select the version of the library you want to install.
  26. - Click on install and wait for the IDE to install the new library. Downloading may take time depending on your connection speed.
  27. - Once it has finished, an Installed tag should appear, You can close the library manager.
  28. ### Manual Install
  29. - Go to http://github.com/PaoloP74/extEEPROM, click the **Download ZIP** button and save the ZIP file to a convenient location on your PC.
  30. - Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, usually **extEEPROM-master**.
  31. - Rename the folder to just **extEEPROM**.
  32. - Copy the renamed folder to the Arduino sketchbook\libraries folder.
  33. ## Examples ##
  34. The following example sketch is included with the **extEEPROM Library**:
  35. - **eepromReadWrite**
  36. - **eepromTest:** Writes 32-bit integers to the entire EEPROM address space, starting at address 0 and continuing to the topmost address. These are then read back in and verified; any discrepancies are reported to the serial monitor.
  37. - **eepromTest_Wire1**
  38. ## Usage notes ##
  39. The **extEEPROM Library** is designed for use with Arduino version 1.0 or later.
  40. To use the **extEEPROM Library**, the standard [Arduino Wire library](http://arduino.cc/en/Reference/Wire) must also be included. For brevity, this include is not repeated in the examples below:
  41. ```c++
  42. #include <Wire.h> //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
  43. ```
  44. ## Enumerations ##
  45. ### eeprom_size_t
  46. ##### Description
  47. EEPROM device size in k-bits. Many manufacturers' EEPROM part numbers are designated in k-bits.
  48. ##### Values
  49. - kbits_2
  50. - kbits_4
  51. - kbits_8
  52. - kbits_16
  53. - kbits_32
  54. - kbits_64
  55. - kbits_128
  56. - kbits_256
  57. - kbits_512
  58. - kbits_1024
  59. - kbits_2048
  60. ### twiClockFreq_t
  61. ##### Description
  62. I2C bus speed.
  63. ##### Values
  64. - extEEPROM::twiClock100kHz
  65. - extEEPROM::twiClock400kHz
  66. ## Constructor ##
  67. ### extEEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr)
  68. ##### Description
  69. Instantiates an external EEPROM object.
  70. ##### Syntax
  71. `extEEPROM myEEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr);`
  72. ##### Parameters
  73. **devCap** *(eeprom_size_t)*: The size of one EEPROM device in k-bits. Choose a value from the eeprom_size_t enumeration above.
  74. **nDev** *(byte)*: The number of EEPROM devices on the bus. Note that if there are multiple EEPROM devices on the bus, they must be identical and each must have its address pins strapped properly.
  75. **pgSize** *(unsigned int)*: The EEPROM page size in bytes. Consult the datasheet if you are unsure of the page size.
  76. **busAddr** *(byte)*: The base I2C bus address for the EEPROM(s). 0x50 is a common value and this parameter can be omitted, in which case 0x50 will be used as the default.
  77. ##### Example
  78. ```c++
  79. extEEPROM myEEPROM(kbits_256, 2, 64); //two 24LC256 EEPROMS on the bus
  80. extEEPROM oddEEPROM(kbits_8, 1, 16, 0x42); //an EEPROM with a non-standard I2C address
  81. ```
  82. ## Methods ##
  83. ### begin(twiClockFreq_t freq, TwoWire *_comm)
  84. ##### Description
  85. Initializes the library. Call this method once in the setup code. begin() does a dummy I/O so that the user may interrogate the return status to ensure the EEPROM is operational.
  86. ##### Syntax
  87. `myEEPROM.begin(twiClockFreq_t freq);`
  88. or
  89. `myEEPROM.begin(twiClockFreq_t freq, TwoWire *_comm);`
  90. ##### Parameters
  91. **freq** *(twiClockFreq_t)*: The desired I2C bus speed, `extEEPROM::twiClock100kHz` or `extEEPROM::twiClock400kHz`. Can be omitted in which case it will default to `twiClock100kHz`.
  92. **NOTE:** When using 400kHz, if there are other devices on the bus they must all support a 400kHz bus speed. **Secondly**, the other devices should be initialized first, as other libraries may not support adjusting the bus speed. To ensure the desired speed is set, call the extEEPROM.begin() function *after* initializing all other I2C devices.
  93. **_comm** *(TwoWire * )*: The Used I2C TwoWire channel . Can be omitted in which case it will default to the first Arduino I2C channel `Wire`. If another of the possible I2C channel is used its pointer shall be passed as parameter.
  94. **NOTE:** If another I2C channel is unse, and not the default one, the first parameters **freq** MUST be defined.
  95. ##### Returns
  96. I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes.
  97. ##### Examples
  98. ```c++
  99. extEEPROM myEEPROM(kbits_256, 2, 64);
  100. byte i2cStat = myEEPROM.begin(extEEPROM::twiClock400kHz);
  101. if ( i2cStat != 0 ) {
  102. //there was a problem
  103. }
  104. ```
  105. ##### Use of other I2C channel
  106. ```c++
  107. extEEPROM myEEPROM(kbits_256, 2, 64);
  108. byte i2cStat = myEEPROM.begin(extEEPROM::twiClock400kHz, &Wire1);
  109. if ( i2cStat != 0 ) {
  110. //there was a problem
  111. }
  112. ```
  113. ### write(unsigned long addr, byte *values, unsigned int nBytes)
  114. ##### Description
  115. Write one or more bytes to external EEPROM.
  116. ##### Syntax
  117. `myEEPROM.write(unsigned long addr, byte* values, byte nBytes);`
  118. ##### Parameters
  119. **addr** *(unsigned long)*: The beginning EEPROM location to write.
  120. **values** _(byte*)_: Pointer to an array containing the data to write.
  121. **nBytes** *(unsigned int)*: The number of bytes to write.
  122. ##### Returns
  123. I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
  124. ##### Example
  125. ```c++
  126. byte myData[10];
  127. //write 10 bytes starting at location 42
  128. byte i2cStat = myEEPROM.write(42, &data, 10);
  129. if ( i2cStat != 0 ) {
  130. //there was a problem
  131. if ( i2cStat == EEPROM_ADDR_ERR) {
  132. //bad address
  133. }
  134. else {
  135. //some other I2C error
  136. }
  137. }
  138. ```
  139. ### write(unsigned long addr, byte value)
  140. ##### Description
  141. Writes a single byte to external EEPROM.
  142. ##### Syntax
  143. `myEEPROM.write(unsigned long addr, byte value);`
  144. ##### Parameters
  145. **addr** *(unsigned long)*: The EEPROM location to write.
  146. **values** _(byte)_: The value to write.
  147. ##### Returns
  148. Same as multiple-byte write() above.
  149. ##### Example
  150. ```c++
  151. //write the value 16 to EEPROM location 314.
  152. byte i2cStat = myEEPROM.write(314, 16);
  153. ```
  154. ### read(unsigned long addr, byte *values, unsigned int nBytes)
  155. ##### Description
  156. Reads one or more bytes from external EEPROM into an array supplied by the caller.
  157. ##### Syntax
  158. `myEEPROM.read(unsigned long addr, byte *values, byte nBytes);`
  159. ##### Parameters
  160. **addr** *(unsigned long)*: The beginning EEPROM location to read from.
  161. **values** _(byte*)_: Pointer to an array to receive the data.
  162. **nBytes** *(unsigned int)*: The number of bytes to read.
  163. ##### Returns
  164. I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
  165. ##### Example
  166. ```c++
  167. byte myData[10];
  168. //read 10 bytes starting at location 42
  169. byte i2cStat = myEEPROM.read(42, &data, 10);
  170. if ( i2cStat != 0 ) {
  171. //there was a problem
  172. if ( i2cStat == EEPROM_ADDR_ERR) {
  173. //bad address
  174. }
  175. else {
  176. //some other I2C error
  177. }
  178. }
  179. ```
  180. ### read(unsigned long addr)
  181. ##### Description
  182. Reads a single byte from external EEPROM.
  183. ##### Syntax
  184. `myEEPROM.read(unsigned long addr);`
  185. ##### Parameters
  186. **addr** *(unsigned long)*: The EEPROM location to read from.
  187. ##### Returns
  188. The data read from EEPROM or an error code *(int)*. To distinguish error values from valid data, error values are returned as negative numbers. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space.
  189. ##### Example
  190. ```c++
  191. int myData;
  192. //read a byte from location 42
  193. int readValue = myEEPROM.read(42);
  194. if ( readValue < 0 ) {
  195. //there was a problem
  196. if ( -readValue == EEPROM_ADDR_ERR) {
  197. //bad address
  198. }
  199. else {
  200. //some other I2C error
  201. }
  202. }
  203. else {
  204. //data read ok
  205. }
  206. ```
  207. "Arduino External EEPROM Library" by Jack Christensen is licensed under [CC BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/).
  208. ![CC BY-SA](http://mirrors.creativecommons.org/presskit/buttons/80x15/png/by-sa.png)