So basically I'm getting some weird static I think the issue is perhaps related to connecting things to the wrong pins on the arduino mega. I'm new to this and am quite confused but I have some C++ experience so its mostly the wiering that confuses me.
So I started simple. It would be a bit of effort to photograph the screen so I'd rather just describe it. If a photo is required though I will provide one. Essentially there are 8 distinct squares that show up - no matter what I draw it seems. There are 2 vertical squares and 4 horizontal ones. Each square has inverted pixels to its neighbour. I've been trying to find this issue but I'm honestly overwhelmed and nothing quite like this seems to show up.
I'm sure I've named the pins correctly since I tested them with buttons beforehand.
There is nothing wrong with selecting a Paged constructor. But you have to use the firstPage(), nextpage() style instead of the sendBuffer() style
You could have used a HW_SPI constructor if you connect to the HW SPI pins 51, 52, 53
but there is not much advantage because the ST7920 does not play cricket on the SPI bus.
Obviously you connect PSB pin to GND to select SPI interface on the ST7920.
Yeah so I did some more fiddling around found I actually had two issues. I put my pins in the correct part (in the 50 -53 range) and used the correct constructor, but I also was having voltage issues. I originally made the decision to draw power from the same place with the back light as I was with the VCC and stuff. I now am drawing them from different power sources (VCC from 5v and BLA from 3.3v) and it works like a dream.
Thanks for the help.
So now I can get something on the screen I'm a little more interested in making the most of this device. I looked at the ST7920 documentation and saw that you can do various complex things with the other pins (the D labeled ones), but I'm getting ahead of myself. My new question is, what exactly did you mean by the following:
the ST7920 does not play cricket on the SPI bus
Is there a different method I should be using, would you ever recommend coding a custom driver/library yourself? I have experience with programming a teensy with a PCD8544 in c99 at uni - because where else do you use c99 - just so you know where I'm coming from.
I presume you are using an Ebay ST7920 module with a 20x1 pin header.
You can use SPI interface i.e. PSB=0, RS, RW, E pins.
Or 8-bit parallel PSB=1, DB0-DB7, RS, RW, E pins.
Or 4-bit parallel PSB=1, DB4-DB7, RS, RW, E pins.
It is a no-brainer. SPI uses less pins.
Quite honestly. You have lots of spare pins on a Mega2560.
You can select any GPIO pins to bit-bash SPI in software (SW).
There is no advantage in using the HW SPI pins.
The ST7920 does not behave well. A cricket-loving SPI device would ignore the bus traffic if her CS pin is de-selected. The ST7920 will print even when CS pin is de-selected.
Which is why it is wise to use SW_SPI on non-HW SPI pins.
Please edit your link. There is an extraneous period.
Yes, you can use 8-bit parallel if you want e.g. if you already have a pcb that is designed for KS0108 i.e. 20x1 header socket.
If you are using random wires, SPI uses less wires.
Your module should work at 5V without any wires to 3, 17 but you need wires to the backlight.
It seems faiirly expensive £17 in Brit money. £11.20 from Hobby Components i.e. genuine UK seller.
Obviously much cheaper from China but you have a LONG wait.
My ST7920 display does not work in SPI mode without the CS pin connected to the processor. I modified my display to work on 3.3V and only tested this with 3.3V power and I/O.
Display works great with U8g or U8g2 display graphics libraries. I did look for Adifruit GFX graphics library driver support, but only found two such ST7920 libraries on github. Unfortunately, both did not work with my display, however it looks like it would be easy to modify one of Adafruit's display drivers (such as PCD8544 Nokia 5110 LCD Library) for the ST7920 display. Will try doing that later.
U8g2lib and any other library requires the RS, RW, E pins on your ST7920. (and PSW = GND)
This is a typical wiring that uses the HW SPI pins on a Uno.
|LCD pin|LCD pin name|Arduino|
|--|--|--|
|#01| GND| GND|
|#02| VCC |VCC (5V)|
|#04| RS | D10/CS or any pin|
|#05| R/W| D11/MOSI|
|#06| E | D13/SCK|
|#15| PSB| GND (for SPI mode)|
|#19| BLA | D9, VCC or any pin via 300ohm resistor|
|#20| BLK | GND|
Yes, you must connect the CS pin (i.e pin#4 (RS) on your Ebay module) for the ST7920 to work.
However you can't share ST7920 with other SPI devices on the HW SPI bus.
U8g2lib provides SPI constructors as well as Parallel.
There are some ST7920 libraries that support both HW SPI and SW SPI. e.g. U8g2lib
There are several ST7920 libraries that support HW SPI. e.g. ST7920_SPI from cbm80amiga