Skip to content

Commit a0298d5

Browse files
committed
Expand beginner docs and add detailed example sketch guide
1 parent 013dc8b commit a0298d5

5 files changed

Lines changed: 203 additions & 0 deletions

File tree

docs/guide/common-tasks.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Common Tasks (Beginner Friendly)
22

3+
If this is your first run on real hardware, start with [First Hour Setup](first-hour.md), then use [Example Sketches Guide](example-sketches.md) when validating behavior.
4+
35
## Save one number and read it back
46

57
```cpp
@@ -47,6 +49,7 @@ flash.readByteArray(addr, rx, sizeof(rx));
4749
2. Ensure `begin()` is called in `setup()`.
4850
3. Print `getJEDECID()` and `error(VERBOSE)`.
4951
4. Run `FlashDiagnostics` example sketch.
52+
5. Compare results against [Example Sketches Guide](example-sketches.md).
5053

5154
## Improve speed safely
5255

docs/guide/example-sketches.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Example Sketches Guide (Troubleshooting + Learning)
2+
3+
The bundled examples are one of the best parts of this library. This page explains what each one does, what success looks like, and what failures mean.
4+
5+
## `FlashDiagnostics/FlashDiagnostics.ino`
6+
7+
### What it tests
8+
9+
- Chip identity (`getJEDECID`, capacity, max page, unique ID)
10+
- Power operations (`powerDown`, `powerUp`)
11+
- Erase operations (`eraseChip`, `eraseSection`, sector/block erase)
12+
- Data I/O for many types (byte, char, word, short, long, float, struct, array, string)
13+
14+
### Why run it first
15+
16+
It gives broad signal quickly: if this sketch fails, fix hardware/config before writing app logic.
17+
18+
### Expected success signs
19+
20+
- JEDEC ID prints non-zero.
21+
- Function tests report pass.
22+
- Read values match written values.
23+
24+
### Common failure patterns
25+
26+
- Fails immediately: wiring/CS/board SPI mismatch.
27+
- Write tests fail: region not erased, `WP/HOLD` pin state, unstable power.
28+
- Mixed intermittent failures: clock too fast, shared SPI bus interference.
29+
30+
---
31+
32+
## `TestFlash/TestFlash.ino`
33+
34+
### What it is
35+
36+
Interactive serial command tester for direct operation-by-operation checks.
37+
38+
### Best use
39+
40+
Use this when you want to isolate a single failing operation (`writeByte`, `eraseSector`, `readStr`, etc.) without full diagnostics noise.
41+
42+
### Tips
43+
44+
- Set Serial Monitor to expected line ending mode from sketch notes.
45+
- Test simple operations first (`getID`, `writeByte` + `readByte`).
46+
- Move to erase and string operations after basics pass.
47+
48+
---
49+
50+
## `getAddressEx/getAddressEx.ino`
51+
52+
### What it teaches
53+
54+
How to use `getAddress()` and `sizeofStr()` to allocate addresses safely without hardcoding offsets.
55+
56+
### Troubleshooting value
57+
58+
If this fails, you may have pre-written data conflicts or boundary behavior confusion.
59+
60+
---
61+
62+
## `readWriteString/readWriteString.ino`
63+
64+
### What it teaches
65+
66+
Simple `writeStr`/`readStr` workflow.
67+
68+
### Troubleshooting value
69+
70+
Great for catching string-specific issues (length metadata, readback integrity, sector erase assumptions).
71+
72+
---
73+
74+
## `Struct_writer/Struct_writer.ino`
75+
76+
### What it teaches
77+
78+
Write/read complete structs repeatedly, including nested members and arrays.
79+
80+
### Troubleshooting value
81+
82+
Use this for data-model persistence validation. If this fails while primitive tests pass, inspect struct layout assumptions and erase coverage.
83+
84+
---
85+
86+
## `FlashDiagnostics/Diagnostics_functions.ino`
87+
88+
### What it is
89+
90+
Helper routines used by diagnostics output (formatting, timing presentation, pass/fail display).
91+
92+
### Why it matters
93+
94+
Helps you understand what diagnostics output lines map to which underlying test sections.
95+
96+
## Recommended order for beginners
97+
98+
1. `FlashDiagnostics.ino`
99+
2. `TestFlash.ino` (targeted operation isolation)
100+
3. `readWriteString.ino`
101+
4. `getAddressEx.ino`
102+
5. `Struct_writer.ino`
103+
104+
## What to capture when asking for help
105+
106+
- Board and core version
107+
- Chip part number
108+
- Wiring summary (including `WP/HOLD` if flash)
109+
- Example sketch name
110+
- Error code (`error()` value) and serial output snippet

docs/guide/first-hour.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# First Hour Setup (Arduino Beginner Path)
2+
3+
This walkthrough is for first-time users bringing up an external SPI memory chip.
4+
5+
## 0-10 min: Hardware sanity check
6+
7+
At minimum, connect:
8+
9+
- `VCC` and `GND`
10+
- `SCK`, `MISO`, `MOSI`
11+
- `CS` (chip select)
12+
13+
### Flash-specific pin note
14+
15+
Many flash chips also expose `WP` (write protect) and `HOLD`. If these are floating, writes can fail or communication can be unstable. Check your chip datasheet and set valid levels.
16+
17+
### ESP32 note
18+
19+
Some ESP32 boards already use onboard flash on default SPI pins. Use an explicit CS pin and, if needed, the custom pin constructor.
20+
21+
## 10-20 min: Minimal identity test
22+
23+
Upload a minimal sketch that does:
24+
25+
1. `begin()`
26+
2. `getJEDECID()`
27+
3. `error(VERBOSE)` on failure
28+
29+
```cpp
30+
#include <SPIMemory.h>
31+
32+
SPIFlash flash(10);
33+
34+
void setup() {
35+
Serial.begin(115200);
36+
while (!Serial) {}
37+
38+
if (!flash.begin()) {
39+
Serial.print("begin failed, err=0x");
40+
Serial.println(flash.error(VERBOSE), HEX);
41+
return;
42+
}
43+
44+
Serial.print("JEDEC: 0x");
45+
Serial.println(flash.getJEDECID(), HEX);
46+
}
47+
48+
void loop() {}
49+
```
50+
51+
If JEDEC is zero or invalid, stop and re-check wiring and CS pin.
52+
53+
## 20-35 min: First write/read
54+
55+
For flash:
56+
57+
1. Erase region (`eraseSector`)
58+
2. Write one value (`writeULong`)
59+
3. Read back (`readULong`)
60+
61+
```cpp
62+
uint32_t addr = 0;
63+
flash.eraseSector(addr);
64+
flash.writeULong(addr, 123456789UL);
65+
uint32_t out = flash.readULong(addr);
66+
```
67+
68+
## 35-50 min: Run diagnostics sketch
69+
70+
Run `examples/FlashDiagnostics/FlashDiagnostics.ino`.
71+
72+
- This validates many read/write/erase and power operations.
73+
- It is the fastest way to separate hardware issues from application-code issues.
74+
75+
## 50-60 min: Move to your real use case
76+
77+
Pick one:
78+
79+
- Logging numbers: use primitive write/read calls.
80+
- Saving settings: use `writeAnything/readAnything` with a struct.
81+
- Storing user text: use `writeStr/readStr`.
82+
83+
Then use [Common Tasks](common-tasks.md) and [Example Sketches Guide](example-sketches.md).

docs/guide/quickstart.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
If you are new to Arduino external memory chips, start here.
66

7+
For a step-by-step first session, use [First Hour Setup](first-hour.md).
8+
79
## 1. Install the library
810

911
### Arduino Library Manager
@@ -70,8 +72,11 @@ Recommended beginner order:
7072
3. `examples/getAddressEx/getAddressEx.ino`
7173
4. `examples/Struct_writer/Struct_writer.ino`
7274
75+
Use [Example Sketches Guide](example-sketches.md) for a full breakdown of what each sketch tests, what success looks like, and how to use failures for troubleshooting.
76+
7377
## 5. If it fails
7478
7579
- Call `flash.error(VERBOSE)`.
7680
- Check [Errors and Diagnostics](../api/errors.md).
7781
- Run diagnostics example and capture output.
82+
- Follow the troubleshooting workflow in [Example Sketches Guide](example-sketches.md).

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ nav:
1414
- Home: index.md
1515
- Getting Started:
1616
- Quick Start: guide/quickstart.md
17+
- First Hour Setup: guide/first-hour.md
1718
- Common Tasks: guide/common-tasks.md
19+
- Example Sketches Guide: guide/example-sketches.md
1820
- Core Concepts: guide/concepts.md
1921
- Build Configuration: guide/configuration.md
2022
- Compatibility Matrix: guide/compatibility.md

0 commit comments

Comments
 (0)