SPIDriver

A better SPI adapter

Jul 10, 2018

Project update 5 of 9

Last Chance To Back SPIDriver!

It’s been great running the SPIDriver campaign, thanks so much for all your support and comments. If you haven’t yet backed it, I have to remind you that the campaign ends the day after tomorrow. Thanks again!

Using the External LCD

The "SPIDriver Expert" package includes an external LCD display. It’s actually the same display that’s used by the SPIDriver itself, but broken out so you can tinker with it.

As soon as it’s plugged in, the backlight comes on. As you can see, it draws about 30 mA.

The LCD’s display controller is a ST7735, and there is a handy module to drive it in the SPIDriver Python samples directory. Loading it from Python gives us an lcd object that’s talking to the panel using SPIDriver:

>>> from spidriver import SPIDriver
>>> from st7735s import ST7735
>>> lcd = ST7735(SPIDriver("/dev/ttyUSB0"))

So far nothing has changed on the LCD. You can initialize it like this:

>>> lcd.start()

The start method sets up all the registers of the LCD’s controller. The details are quite fiddly, but it’s actually only 50 lines of Python.

It worked! The LCD is displaying an image of a sort. It’s just the random contents of the display’s RAM at startup, so it just looks like noise. But it’s alive, and the next step is to send it an image:

>>> lcd.loadimage("grace-hopper.jpg")

You can load your own images of course. The module takes care of rotating, resizing and formatting them for the LCD panel.

Reading Somebody Else’s Flash

The adapter module also has a socket to connect to the flash clip (also part of the pledge package). Here it’s connected to a random board I had lying around, hooked onto its SPI flash.

The board is being powered from SPIDriver’s 3.3 V supply, which is why the target current is now 60 mA.

Reading SPI flash is really easy, just send command 03, followed by 3 bytes of address. So to read the first 128 bytes of flash:

>>> s = SPIDriver("/dev/ttyUSB0")
>>> s.sel()
>>> s.write(bytes([0x03, 0x00, 0x00, 0x00]))
>>> hexdump(s.read(128))
00000000: FF 00 4C 61 74 74 69 63  65 00 69 43 45 63 75 62  ..Lattice.iCEcub
00000010: 65 32 20 32 30 31 34 2E  31 32 44 65 76 2E 32 36  e2 2014.12Dev.26
00000020: 38 39 39 00 50 61 72 74  3A 20 69 43 45 34 30 55  899.Part: iCE40U
00000030: 4C 31 4B 2D 43 4D 33 36  41 00 44 61 74 65 3A 20  L1K-CM36A.Date: 
00000040: 4E 6F 76 20 35 20 32 30  31 34 20 31 31 3A 31 31  Nov 5 2014 11:11
00000050: 3A 32 00 FF 31 00 7E AA  99 7E 51 00 01 05 92 00  :2..1.~..~Q.....
00000060: 20 62 01 6F 82 00 00 72  00 70 11 00 01 01 00 00   b.o...r.p......
00000070: 00 00 00 00 00 00 00 00  00 10 00 00 00 00 00 00  ................

Sign up to receive future updates for SPIDriver.

Subscribe to the Crowd Supply newsletter, highlighting the latest creators and projects