Skip to content

Commit 6d827ec

Browse files
committed
Update add example in readme to be a python script instead of bare terminal entry.
1 parent 1d42efc commit 6d827ec

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ These commands must be run when the running status is `STOPPED`.
6161
* `swr` - Used to software start a programmed sequence (ie do not wait for a hardware trigger at sequence start).
6262
* `adm <starting instruction address (in hex)> <number of instructions (in hex)>` - Enters mode for adding pulse instructions in binary.
6363
* This command over-writes any existing instructions in memory. The starting instruction address specifies where to insert the block of instructions. This is generally set to 0 to write a complete instruction set from scratch.
64-
* The number of instructions must be specified with the command. The Pi Pico will then wait for enough bytes (6 times the number of instructions) to be read, and will not respond during this time unless there is an error. This mode can not be be terminated until that many bytes are read.
64+
* The number of instructions must be specified with the command, which is used to determine the total number of bytes to be read (6 6 times the number of instructions).
65+
* This command returns `Ready\r\n` to signify it is ready for binary data. The Pico will then read the total number of bytes. This mode can not be terminated until that many bytes are read.
6566
* Each instruction is specified by a 16 bit unsigned integer (little Endian, output 15 is most significant) specifying the state of the outputs and a 32 bit unsigned integer (little Endian) specifying the number of clock cycles.
6667
* The number of clock cycles sets how long this state is held before the next instruction.
6768
* If the number of clock cycles is 0, this indicates an indefinite wait.
@@ -86,25 +87,23 @@ The basis of the functionality for this serial interface was developed by Carter
8687
## Clock Sync
8788
Firmware supports the use of an external clock. This prevents any significant phase slip between a pseudoclock and this digital output controller if their clocks are phase synchronous. Without external buffering hardware, clock must be LVCMOS compatible.
8889

89-
## Example:
90-
Below program sets one output high for 1 microsecond, then low while setting the next output high for 1 microsecond (64 in hex = 100 in decimal) for 6 outputs, then stopping:
90+
## Examples:
91+
Below python script sets one output high for 1 microsecond, then low while setting the next output high for 1 microsecond (64 in hex = 100 in decimal) for 6 outputs, then stopping. `do` is a pyserial handle to the pico.
9192

92-
Commands (`\n` explicitly denotes newline/pressing enter):
93+
```python
94+
bits = [1, 2, 3, 8, 10, 20, 0, 0]
95+
cycles = [100, 100, 100, 100, 100, 100, 0, 0]
9396

94-
```
95-
add\n
96-
1 64\n
97-
2 64\n
98-
4 64\n
99-
8 64\n
100-
10 64\n
101-
20 64\n
102-
0 0\n
103-
0 0\n
104-
end\n
105-
```
97+
do.write('add\n'.encode())
98+
for bit, cycle in zip(bits, cycles):
99+
do.write(f'{bit:x} {cycle:x}\n'.encode())
106100

101+
do.write('end\n'.encode())
102+
resp = do.readline().decode()
103+
assert resp == 'ok\r\n'
104+
```
107105

106+
Output of the above sequence.
108107
<img width="470" alt="documentation" src="https://github.com/pmiller2022/prawn_digital_output/assets/75953337/932b784f-346f-4598-8679-b857578e0291">
109108

110109
This is a python script that employs the binary write `adm` command.

0 commit comments

Comments
 (0)