apohero
Posts: 9
Joined: Mon Jan 07, 2013 10:37 am

SPI LCD on Pi

Mon Jan 07, 2013 11:32 am

Hi there,
i bought a sainsmart 1,8" display to connect to my pi and followed the instruction here: http://www.youtube.com/watch?v=nMQJmVDgAl8
But its not working :(
So i wanted to know if someone already has connected a SPI LCD to the pi successfully and maybe has a simple hello world prog for testing?
thanks

apo

jfornango
Posts: 113
Joined: Fri Sep 14, 2012 7:46 pm
Location: St. Louis, MO USA

Re: SPI LCD on Pi

Mon Jan 14, 2013 6:01 pm

so... right off the bat, I noticed that this screen in the video is not a sainsmart device. That will change things a bit from the vid. Also, in looking at the Pi pins in use in the video, you will notice that he is using I2C, not SPI, so your hookup and code will be completely different. (if you based your hookups on the video, that's your main problem)

I looked up the sainsmart for its pinouts, and here is what I found:
1. GND : Power Ground
2. VCC : 5V power input
3. CS : Chipselect for LCD,
4. SDA : LCD Data for SPI
5. SCL : SCLK for TFT Clock
6. RS/DC : Command/Data Selection
7. RESET : LCD controller reset, active low
8. CS (SD-CS) : Chipselect for TF Card,
9. CLK (SD-Clock): SPI Clock
10. MOSI (SD-DI) : SPI Master out Slave in
11. MISO (SD-DO) : SPI Master in Slave out

Note that pins 8 - 11 are for the SD card slot on the back of screen module and aren't discussed here.

To get SPI video, I think your GPIO hookups will work as follows: (if someone has more experience, please feel free to correct me)

Sainsmart........................RPi GPIO
1. GND..............................6. GND
2. VCC..............................2. +5 VDC
3. CS................................24. SPI CS 0
4. SDA.............................19. SPI MISO
5. SCL..............................23. SPI SCLK
6. RS/DC..........................22. GPIO 25
7. RESET.........................18. GPIO 24

As far as programming goes, I'll be honest, I'm clueless. No experience in that arena yet.
I'm only wearing black until they find something darker.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: SPI LCD on Pi

Mon Jan 14, 2013 8:18 pm

Pin 19 on the Raspberry Pi is MOSI (Master Out Slave In). The MISO (Master In Slave Out) is an SPI input on pin 21.

You do want to use Raspberry Pi pin 19 MOSI connected to the LCD SDA on pin 4.

You can refer to the AdaFruit web site and GitHub for programming.

Enjoy!
Bill

apohero
Posts: 9
Joined: Mon Jan 07, 2013 10:37 am

Re: SPI LCD on Pi

Tue Jan 15, 2013 11:12 am

Hi and thanks for the reply.
I found a nice page from the adafruit site mentioned http://marks-space.com/2013/01/08/raspb ... re-sensor/

Maybe I can use this to make the sainsmart display work. But I'm a little bit confused about the TFT/cs in the picture. He connected it to GPIO8(CE0). Or can I use your wirings?

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: SPI LCD on Pi

Tue Jan 15, 2013 1:25 pm

CE0 is Pin 24, so it is the same wiring. Just a naming difference.

One thing to note on the page you linked. The schematic is wrong for wiring the RF module. It shows the resistor in the ground path for the module. The resistor should be to the switch, but the ground should be connected directly to the RF module.

Enjoy!
Bill

apohero
Posts: 9
Joined: Mon Jan 07, 2013 10:37 am

Re: SPI LCD on Pi

Tue Jan 15, 2013 6:15 pm

Hi, I've connected everything said like above (just the display). I edited the code on the framebuffer line to /dev/fb0, cause i couldn't find fb1. The display seems to be initialized (i made some debug output). But i can't see anything, only the background light is flickering each time a command is send to display.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: SPI LCD on Pi

Tue Jan 15, 2013 8:08 pm

/dev/fb0 is the primary display frame buffer for the Raspberry Pi. /dev/fb1 is the frame buffer for the TFT.

If you read the previous blog entry on the same site -- Raspberry Pi and TFT Display -- it covers the kernel frame buffer driver being used for /dev/fb1. Without this kernel driver, the python code from the subsequent blog entry will not work.

Enjoy!
Bill

apohero
Posts: 9
Joined: Mon Jan 07, 2013 10:37 am

Re: SPI LCD on Pi

Tue Jan 15, 2013 9:00 pm

Yeah exactly. I saw that kernel patch right after i posted here. Right now the pi is updating and my pc is downloading the kernel patch. I will you when its finished....

User avatar
mwilliams03
Posts: 126
Joined: Mon Oct 29, 2012 2:56 pm

Re: SPI LCD on Pi

Wed Jan 16, 2013 3:47 pm

Here is the link you should follow <which I think you have already found>;
http://marks-space.com/2012/11/23/raspberrypi-tft/
At the bottom of the blog, I also list what programs you can use to push stuff to the device.

Kamal's site will be very helpful as well, he updated the drivers for the ST7735R controller, which your TFT uses;
http://www.whence.com/rpi/


I have attached some python code that you can use to test.
It uses pygame to write to framebuffer 1.
I think Pygame is install by default on the pi image.

Plus you can edit it to display your own stuff.

Just run it with;
sudo python drawing.py


I hope this helps
Attachments
drawing.tar
(10 KiB) Downloaded 659 times
Mark -- OzzMaker.com -- Creator of;
+ BerryIMU
+ Berry GPS-IMU
+BerryGPS-GSM
+ PiScreen - A 3.5" TFT for the Rasspberry Pi

apohero
Posts: 9
Joined: Mon Jan 07, 2013 10:37 am

Re: SPI LCD on Pi

Wed Jan 16, 2013 5:49 pm

ok so far.... I'got the following step
1. "compile the kernel" (i skipped the update things)
I cloned the kamal things, took the config from my pi and made the following configs:
ST7735 framebuffer support (FB_ST7735) [N/m/y/?] (NEW) y
ST7735 panel is ‘red tab’ type? (FB_ST7735_PANEL_TYPE_RED_TAB) [Y/n/?] (NEW) y
ST7735 framebuffer mapping to SPI0.0 (FB_ST7735_MAP) [N/m/y/?] (NEW) y
-> ST7735 RST gpio pin number (FB_ST7735_MAP_RST_GPIO) [-1] (NEW) 25
-> ST7735 D/C gpio pin number (FB_ST7735_MAP_DC_GPIO) [-1] (NEW) 24

ST7735 SPI bus number (FB_ST7735_MAP_SPI_BUS_NUM) [0] (NEW) 0
ST7735 SPI bus chipselect (FB_ST7735_MAP_SPI_BUS_CS) [0] (NEW) 0
ST7735 SPI bus clock speed (Hz) (FB_ST7735_MAP_SPI_BUS_SPEED) [4000000] (NEW) 4000000
-> ST7735 SPI bus mode (0, 1, 2, or 3) (FB_ST7735_MAP_SPI_BUS_MODE) [0] (NEW) 3

...I'm unsure with the bold ones.
The compiling, copying, blacklisting, module-inserting worked fine. Rebooted....but still no fb1 (Display is connected as usual)

The next thing i could test ist take the debian version he mentioned and make the updatethings before. I also noticed that reset and dc mismatch your wirings. Is this correct?
The line ST7735 SPI bus mode (0, 1, 2, or 3) (FB_ST7735_MAP_SPI_BUS_MODE) [0] (NEW) 3 is default 0 on my pi, not 3. I set it as above. Thats all I see... :(

User avatar
mwilliams03
Posts: 126
Joined: Mon Oct 29, 2012 2:56 pm

Re: SPI LCD on Pi

Wed Jan 16, 2013 7:27 pm

What Raspbian version are you using?
I used 2012-10-28-wheezy-raspbian.img


Try building the drivers as modules, By doing this;
ST7735 framebuffer support (FB_ST7735) [N/m/y/?] (NEW) M.

The answers you gave in bold are correct.
The diagram has RST as 25 and D/C as 24. In saying this, you can change these pins if you like, you just need to make sure that when you answer these, they actually match what is physically wired up on the Pi.
> ST7735 RST gpio pin number (FB_ST7735_MAP_RST_GPIO) [-1] (NEW) 25
-> ST7735 D/C gpio pin number (FB_ST7735_MAP_DC_GPIO) [-1] (NEW) 24


If after compiling as modules doesn't work.. send me the output of these;
cat /etc/modules
cat /etc/modprobe.d/raspi-blacklist.conf
lsmod
dmesg | grep 'fb\|2708'


And the config file you used to patch the kernel.
grep 'fb\|2708' .config
Mark -- OzzMaker.com -- Creator of;
+ BerryIMU
+ Berry GPS-IMU
+BerryGPS-GSM
+ PiScreen - A 3.5" TFT for the Rasspberry Pi

apohero
Posts: 9
Joined: Mon Jan 07, 2013 10:37 am

Re: SPI LCD on Pi

Thu Jan 17, 2013 11:03 am

Hi and thanks for this perfect support!

I was using 2012-07-15-wheezy-raspbian, so its a bit older (maybe too old?). I downloaded the version mentioned in the tutorial and will make that rpi-update stuff(or can i skip that by using 2012-12-16-wheezy-raspbian/?).
I'll try that with modules switched on.

thanks again

User avatar
mwilliams03
Posts: 126
Joined: Mon Oct 29, 2012 2:56 pm

Re: SPI LCD on Pi

Thu Jan 17, 2013 3:12 pm

I havent used 2012-12-16... but someone posted this on my blog;

Ok, I finally managed it. Important: If you use raspbian 2012-12-16 DON’T UPDATE THE FIRMWARE! (don’t use rpi-update). The firmware is already new enough for the driver.
I had to set up a new raspbian-wheezy 2012-12-16 (on a slooowww 2gb sd-card) and did all steps except rpi-update. This keeps me the 3.2.27 kernel. (apt-get update; apt-get upgrade is o.k.)
Then I had to do a small modification. First I use menuconfig:

klaus@LittlX:~/src/raspberrypi-linux$ sudo make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig

The st7735 driver is in:
Device Drivers -> Graphics support -> Support for frame buffer devices
And then the driver has to be build as an module (don’ use ‘y’, use ‘M’ instead)

ST7735 LCD panel framebuffer support
[*] ST7735 ‘red tab’ panel type?
ST7735 framebuffer mapping to GPIO/SPI
(25) ST7735 RST gpio pin number
(24) ST7735 D/C gpio pin number
(0) ST7735 SPI bus number
(0) ST7735 SPI bus chipselect
(4000000) ST7735 SPI bus clock speed (Hz)
(3) ST7735 SPI bus mode (0, 1, 2, or 3)

Do the rest steps mentioned. it should work!

Reply ↓
Mark -- OzzMaker.com -- Creator of;
+ BerryIMU
+ Berry GPS-IMU
+BerryGPS-GSM
+ PiScreen - A 3.5" TFT for the Rasspberry Pi

apohero
Posts: 9
Joined: Mon Jan 07, 2013 10:37 am

Re: SPI LCD on Pi

Thu Jan 17, 2013 8:06 pm

hey...... my pi wants to say something...

http://postimage.org/image/qh30d6yed/

apohero
Posts: 9
Joined: Mon Jan 07, 2013 10:37 am

Re: SPI LCD on Pi

Thu Jan 17, 2013 8:18 pm

after i took the newest wheezy and build the kernel with the driver as module, the fb1 appeared. But the drawing example didn't cause the display to work it was just flickering. Then i rewired the pi (DC ->GPIO24 and RES->GPIO25) and voilá there was the drawin.YES!!!
Inspired by that I tried the mplayer example...and wow I was watching "wreckit ralph" (low framerate but cool).
The next things I will do is checking out why my terminal is no more reacting on "ctrl-c" when running the drawing example (or any other pygame example),and how to get the fbterm-login working (now saying that it reloads too fast and "wait 5 minutes" again and again).

Thanks a lot for the really really good help! Best support I ever got!

gima
Posts: 1
Joined: Fri Nov 29, 2013 12:51 am

Re: SPI LCD on Pi

Fri Nov 29, 2013 1:01 am

Correct me if I'm wrong, but as I understand, the 3- and 4-wire serial protocols of the ST7735R are not SPI, even though the datasheet says so. They are protocols that are defined solely in the datasheet.

I found the tossing of the words "SPI" and "MOSI" misleading, and ended up creating simple, isolated demonstration on how to use the display driver. It's available here: https://github.com/gima/st7735r

Return to “Interfacing (DSI, CSI, I2C, etc.)”