Unable to use SPI display. Help please.

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
thule
Posts: 10
Joined: Thu Dec 22, 2016 9:32 pm

Unable to use SPI display. Help please.

Post by thule » Thu Dec 22, 2016 9:51 pm

Hi all

Recently I installed micropython on esp8266 nodemcu dev board 1.1. I connected it as follows.

VCC -> 3V3
GND -> GND
CS -> D0 (nodemcu) or (GPIO 16)
RESET -> 3V3
A0 -> D1(nodemcu) or (GPIO 5)
SDA -> D7(nodemcu) or (GPIO 13), actually this is MOSI
LED -> 3V3
SCK -> D5(nodemcu) or (GPIO 14)

>>> os.listdir('.')
['boot.py', 'abcd.txt', 'serv.py', 'webrepl_cfg.py', 'ssd1306.mpy', 'ssd1306.py', 'st7735.mpy', 'st7735.py', 'ili9341.mpy', 'ili9341.py']



I tried both the following:
import ili9341
from machine import Pin, SPI
spi = SPI(miso=Pin(12), mosi=Pin(13, Pin.OUT), sck=Pin(14, Pin.OUT))
display = ili9341.ILI9341(spi, cs=Pin(0), dc=Pin(5), rst=Pin(4))
display.fill(ili9341.color565(0xff, 0x11, 0x22))
display.pixel(120, 160, 0)



from machine import Pin, SPI
import st7735
spi = SPI(miso=Pin(12), mosi=Pin(13, Pin.OUT), sck=Pin(14, Pin.OUT))
display = st7735.ST7735(128, 128, spi, Pin(2), Pin(4), Pin(5))
display.fill(0x7521)
display.pixel(64, 64, 0)


Neither of the things show up any display. Both of them do light up the screen. When fill is running or when I use display.pixel in a loop or when I run display.text() it does flicker. However nothing shows up on screen.

Any ideas what my folly is :-(

Thanks

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Unable to use SPI display. Help please.

Post by deshipu » Fri Dec 23, 2016 2:29 pm

What is the screen you are using?

thule
Posts: 10
Joined: Thu Dec 22, 2016 9:32 pm

Re: Unable to use SPI display. Help please.

Post by thule » Fri Dec 23, 2016 5:38 pm

That would have been helpful right! I took the picture of the screen and forgot to attach it!

Here it is.

https://ibin.co/36OBFkWsGlyC.jpg
[or]
https://imagebin.ca/v/36OBFkWsGlyC

Thanks a lot for your help.

thule
Posts: 10
Joined: Thu Dec 22, 2016 9:32 pm

Re: Unable to use SPI display. Help please.

Post by thule » Fri Dec 23, 2016 5:40 pm

Something similar to the one on ebay as below.
http://www.ebay.com/itm/251494743565?_t ... EBIDX%3AIT

Thanks

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Unable to use SPI display. Help please.

Post by deshipu » Fri Dec 23, 2016 10:02 pm

The auction you linked claims that it's a ST7735S, however, it also claims that it's compatible to the Nokia 5110, which doesn't make much sense, because that one is black-and-white...

Where did you get that st7735 library you are using here? Have you tried using https://github.com/adafruit/micropython ... b-display/ instead?

thule
Posts: 10
Joined: Thu Dec 22, 2016 9:32 pm

Re: Unable to use SPI display. Help please.

Post by thule » Sat Dec 24, 2016 11:36 pm

I didn't think much of the 5110. Hopefully it is just a st7735 display. I used the st7735.py from your post.
- Clean reflash

- connected to it from screen as ttyUSB0

- connect to wifi -> open webrepl and loaded the following files
>>> os.listdir('.')
['boot.py', 'webrepl_cfg.py', 'st7735.py', 'rgb.py', 'rgb.mpy', 'st7735.mpy']

- then did
from machine import Pin, SPI
import st7735
spi = SPI(mosi=Pin(13), sck=Pin(14))
display = st7735.ST7735(spi, dc=Pin(12), cs=Pin(15), rst=Pin(16))
display.fill(0x7521)
display.pixel(64, 64, 0)

And the problem came!
>>>
>>> from machine import Pin, SPI
>>> import st7735
>>> spi = SPI(mosi=Pin(13), sck=Pin(14))
>>> display = st7735.ST7735(spi, dc=Pin(12), cs=Pin(15), rst=Pin(16))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'ST7735'
>>> display.fill(0x7521)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'display' is not defined
>>> display.pixel(64, 64, 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'display' is not defined
>>>

I did a read and print_to_screen of the file st7735.py and it does have ST7735 inheriting from DisplaySPI and with __init__ and all. So I don't know why it refuses to create the display object from st7735.ST7735! I have been away from python for a couple of years and may be I am missing something obvious!

Thanks for you time.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Unable to use SPI display. Help please.

Post by marfis » Sun Dec 25, 2016 8:03 pm

you seem to have copied the precompiled 7735 mpy file and the source 7735 python files.

This is not a good practise since you now have to know which file is actually imported... (I dont know which import order uPy follows here).

I guess that one of those st7735 files does not have your missing class as attribute.

So delete the mpy files and try again. Once you sorted out that issue you can always precompile the st7735.py file again (and delete your original file on the board)

thule
Posts: 10
Joined: Thu Dec 22, 2016 9:32 pm

Re: Unable to use SPI display. Help please.

Post by thule » Tue Dec 27, 2016 1:52 pm

Hi Marfis

You are correct. I deleted the mpy and now the st7735 subclassing works. However up on deleting all the compiled versions and retrying the code, still nothing is visible on the screen. Just to clarify, I am using the code below.

from machine import Pin, SPI
import st7735
spi = SPI(mosi=Pin(13), sck=Pin(14))
display = st7735.ST7735(spi, dc=Pin(12), cs=Pin(15), rst=Pin(16))
display.fill(0x7521)
display.pixel(64, 64, 0)

Just to try, I also tried ILI9341 - in case the branding is wrong. That didn't help either!
Thanks

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Unable to use SPI display. Help please.

Post by deshipu » Thu Dec 29, 2016 9:46 am

I don't think you have a logic analyzer or an oscilloscope to be able to see what is happening on the data lines?

thule
Posts: 10
Joined: Thu Dec 22, 2016 9:32 pm

Re: Unable to use SPI display. Help please.

Post by thule » Thu Dec 29, 2016 3:57 pm

Hi Deshipu

I don't have one. Also my knowledge doesn't go that far sadly. I have more then one of these SPI displays. I tried the other one too. Still no luck! This display also lights up.

https://imagebin.ca/v/373mtjqqyaqy
https://ibin.co/373mtjqqyaqy.jpg

I am not sure where to proceed! Is there a way to find out what chip is on the display side, from micropython? I guess a bit like the hardware probing available in linux - dmesg command? It's probably too much to ask an embedded system for that.

Thanks

Post Reply