3
3
A MicroPython library for 74HC595 8-bit shift registers.
4
4
5
5
There's both an SPI version and a bit-bang version, each with a slightly
6
- different interface.
6
+ different interface. See below.
7
7
8
8
![ demo] ( docs/demo.jpg )
9
9
10
+
11
+ ### Installation
12
+
13
+ Using mip via mpremote:
14
+
15
+ ``` bash
16
+ $ mpremote mip install github:mcauser/micropython-74hc595
17
+ $ mpremote mip install github:mcauser/micropython-74hc595/examples
18
+ ```
19
+
20
+ Using mip directly on a WiFi capable board:
21
+
22
+ ``` python
23
+ >> > import mip
24
+ >> > mip.install(" github:mcauser/micropython-74hc595" )
25
+ >> > mip.install(" github:mcauser/micropython-74hc595/examples" )
26
+ ```
27
+
28
+ Manual installation:
29
+
30
+ Copy ` src/sr74hc595_bitbang.py ` and ` src/sr74hc595_spi.py ` to the root directory of your device.
31
+
32
+
10
33
## SPI Version
11
34
12
35
You can use either HSPI or SPI. This version is significantly faster than the
13
36
bit-bang version, but is limited to writing whole bytes of data.
14
37
38
+
15
39
### SPI Example
16
40
17
41
** Basic Usage**
18
42
19
43
``` python
20
44
from machine import Pin, SPI
21
- from sr_74hc595_spi import SR
45
+ from sr74hc595 import SR74HC595_SPI
22
46
23
47
spi = SPI(1 , 100000 )
24
48
rclk = Pin(5 , Pin.OUT )
25
49
26
50
oe = Pin(33 , Pin.OUT , value = 0 ) # low enables output
27
51
srclr = Pin(32 , Pin.OUT , value = 1 ) # pulsing low clears data
28
52
29
- sr = SR (spi, rclk, 2 ) # chain of 2 shift registers
53
+ sr = SR74HC595_SPI (spi, rclk, 2 ) # chain of 2 shift registers
30
54
31
55
sr.pin(2 ,1 ) # set pin 2 high of furthest shift register
32
56
sr.pin(2 ) # read pin 2
@@ -120,14 +144,14 @@ at the expense of the performance you get using SPI.
120
144
121
145
``` python
122
146
from machine import Pin
123
- from sr_74hc595_bitbang import SR
147
+ from sr74hc595 import SR74HC595_BITBANG
124
148
125
149
ser = Pin(23 , Pin.OUT )
126
150
rclk = Pin(5 , Pin.OUT )
127
151
srclk = Pin(18 , Pin.OUT )
128
152
129
153
# construct without optional pins
130
- sr = SR (ser, srclk, rclk)
154
+ sr = SR74HC595_BITBANG (ser, srclk, rclk)
131
155
132
156
sr.clear() # raises RuntimeError because you haven't provide srclr pin
133
157
sr.enable() # raises RuntimeError because you haven't provide oe pin
@@ -136,7 +160,7 @@ sr.enable() # raises RuntimeError because you haven't provide oe pin
136
160
oe = Pin(33 , Pin.OUT , value = 0 ) # low enables output
137
161
srclr = Pin(32 , Pin.OUT , value = 1 ) # pulsing low clears data
138
162
139
- sr = SR (ser, srclk, rclk, srclr, oe)
163
+ sr = SR74HC595_BITBANG (ser, srclk, rclk, srclr, oe)
140
164
141
165
sr.bit(1 ) # send high bit, do not latch yet
142
166
sr.bit(0 ) # send low bit, do not latch yet
@@ -209,6 +233,7 @@ the current state of the `ser` pin and copy it to the shift register memory.
209
233
_clock()
210
234
```
211
235
236
+
212
237
## Chaining
213
238
214
239
You can connect multiple 74HC595 shift registers together to form a chain.
@@ -225,11 +250,13 @@ The `QH\`` output pin on the first shift register goes into the next shift regis
225
250
When clocking in data, the values appear on the closest shift register to the
226
251
micro controller first, before overflowing into each chained shift register.
227
252
253
+
228
254
## Parts
229
255
230
- * [ TinyPICO] ( https://www.tinypico.com/ ) $20.00 USD
231
- * [ 74HC595 DIP-16] ( https://www.aliexpress.com/item/32834183196.html ) $0.77 AUD - 10pcs
232
- * [ 74HC595 breakout] ( https://www.aliexpress.com/item/32807747744.html ) $0.88 AUD
256
+ * [ TinyPICO] ( https://www.tinypico.com/ )
257
+ * [ 74HC595 DIP-16] ( https://s.click.aliexpress.com/e/_DnLBdpL )
258
+ * [ 74HC595 breakout] ( https://s.click.aliexpress.com/e/_Der4vyZ )
259
+
233
260
234
261
## Connections
235
262
@@ -253,12 +280,14 @@ SRCLR | Shift Register Clear | Active low. Drive high to clear contents.
253
280
QA-QH | Outputs | 8 output pins
254
281
QH\` | Serial Output | Connect to the next 74HC595 SER pin
255
282
283
+
256
284
## Links
257
285
258
286
* [ TinyPICO Getting Started] ( https://www.tinypico.com/gettingstarted )
259
287
* [ micropython.org] ( http://micropython.org )
260
288
* [ 74HC595 datasheet] ( docs/sn74hc595n.pdf )
261
289
290
+
262
291
## License
263
292
264
293
Licensed under the [ MIT License] ( http://opensource.org/licenses/MIT ) .
0 commit comments