Electric Dollar Store

The CAT24C512 is a high-endurance 512 Kbit (64 Kbyte EPROM). It is writable in 128-byte pages over I²C, and supports random-access reads at up to 400 KHz.

import sys
import time

from i2cdriver import I2CDriver, EDS

text = b"""\
CHAPTER 1. Loomings.

Call me Ishmael. Some years ago-never mind how long precisely-having little or no money in my
purse, and nothing particular to interest me on shore, I thought I would sail about a little
and see the watery part of the world. It is a way I have of driving off the spleen and
regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is
a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin
warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos
get such an upper hand of me, that it requires a strong moral principle to prevent me from
deliberately stepping into the street, and methodically knocking people's hats off-then, I
account it high time to get to sea as soon as I can. This is my substitute for pistol and ball.
With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship.
There is nothing surprising in this. If they but knew it, almost all men in their degree, some
time or other, cherish very nearly the same feelings towards the ocean with me.

There now is your insular city of the Manhattoes, belted round by wharves as Indian isles by
coral reefs-commerce surrounds it with her surf. Right and left, the streets take you
waterward. Its extreme downtown is the battery, where that noble mole is washed by waves, and
cooled by breezes, which a few hours previous were out of sight of land. Look at the crowds of
water-gazers there.

Circumambulate the city of a dreamy Sabbath afternoon. Go from Corlears Hook to Coenties Slip,
and from thence, by Whitehall, northward. What do you see?-Posted like silent sentinels all
around the town, stand thousands upon thousands of mortal men fixed in ocean reveries. Some
leaning against the spiles; some seated upon the pier-heads; some looking over the bulwarks of
ships from China; some high aloft in the rigging, as if striving to get a still better seaward
peep. But these are all landsmen; of week days pent up in lath and plaster-tied to counters,
nailed to benches, clinched to desks. How then is this? Are the green fields gone? What do they
here?

But look! here come more crowds, pacing straight for the water, and seemingly bound for a dive.
Strange! Nothing will content them but the extremest limit of the land; loitering under the
shady lee of yonder warehouses will not suffice. No. They must get just as nigh the water as
they possibly can without falling in. And there they stand-miles of them-leagues. Inlanders
all, they come from lanes and alleys, streets and avenues-north, east, south, and west. Yet
here they all unite. Tell me, does the magnetic virtue of the needles of the compasses of all
those ships attract them thither?

Once more. Say you are in the country; in some high land of lakes. Take almost any path you
please, and ten to one it carries you down in a dale, and leaves you there by a pool in the
stream. There is magic in it. Let the most absent-minded of men be plunged in his deepest
reveries-stand that man on his legs, set his feet a-going, and he will infallibly lead you to
water, if water there be in all that region. Should you ever be athirst in the great American
desert, try this experiment, if your caravan happen to be supplied with a metaphysical
professor. Yes, as every one knows, meditation and water are wedded for ever.
"""

if __name__ == '__main__':
    i2 = I2CDriver(sys.argv[1])

    d = EDS.EPROM(i2)
    d.write(0, text)        # Write the block of text starting at address 0
    n = len(text)
    rd = d.read(0, n)       # Read it back
    print(rd.decode())               # Display it
#include <Wire.h>

class eprom {
  uint8_t a;
public:
  void begin(byte _a = 0x50) {
    a = _a;
  }
  void write(uint16_t addr, const byte *buf, int len) {
    Wire.beginTransmission(a);
    Wire.write(addr >> 8);
    Wire.write(addr);
    Wire.write(buf, len);
    Wire.endTransmission();
    delay(5000);
  }
  void read(byte *buf, uint16_t addr, int len) {
    Wire.beginTransmission(a);
    Wire.write(addr >> 8);
    Wire.write(addr);
    Wire.endTransmission(false);
    Wire.requestFrom(a, (uint8_t)len);
    for (int i = 0; i < len; i++)
      buf[i] = Wire.read();
  }
} EPROM;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(100000L);

  EPROM.write(0, "This is a test\n", 15);
}

void loop() {
  char buf[15];
  EPROM.read(buf, 0, sizeof(buf));
  Serial.write(buf, sizeof(buf));
  delay(1000);
  for (;;);
}
from machine import I2C
import struct

class EPROM:
    """ EPROM is a CAT24C512 512 Kbit (64 Kbyte) flash memory """
    def __init__(self, i2, a = 0x50):
        self.i2 = i2
        self.a = a

    def write(self, addr, data):
        """ Write data to EPROM, starting at address addr """
        for i in range(0, len(data), 128):
            self.i2.writeto(self.a, (
                struct.pack(">H", addr + i) +
                data[i:i + 128]))
            while self.a not in self.i2.scan():
                pass
        
    def read(self, addr, n):
        """ Read n bytes from the EPROM, starting at address addr """
        self.i2.writeto(self.a, struct.pack(">H", addr), False)
        return self.i2.readfrom(self.a, n)

text = b"""\
CHAPTER 1. Loomings.

Call me Ishmael. Some years ago-never mind how long precisely-having
little or no money in my purse, and nothing particular to interest me on
shore, I thought I would sail about a little and see the watery part of
the world."""

def main():
    i2 = I2C(1, freq = 100000)

    d = EPROM(i2)
    d.write(0, text)        # Write the block of text starting at address 0
    n = len(text)
    rd = d.read(0, n)       # Read it back
    print(rd)               # Display it

Default I²C address 0x50 (0b1010000)
Current consumption (typ.) 0.002 mA
Vcc 1.8 - 5.5 V