|
| 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 |
0 commit comments