So we search the code for “ST7920” and from the available constructors, we select to use the HWSPI one. We uncomment this line like this and we are ready to upload the sketch to the Arduino. After a few seconds, the sketch is up and running.
![]()
Dredging up an old post, but I can't for the life of me find a solid example of someone using the 128x64 Serial-enabled GLCD with an Arduino. Apparently people are replacing the Sparkfun firmware but until I get an AVR programming solution I'd like to mess around a bit. This code is the closest I can come to plug-and-play code that I can modify and play around with to teach myself how this all works.I'm using a Duemilanove (serial ports are 0 (RX) and 1 (TX)).Can someone add some more comments to the code so I know what's going on? I have the screen connected to the Arduino as described and substituted 'NewSoftSerial lcdSerialPort(0, 1);' into the code to account for the location of my serial port. I have the NewSoftSerial library installed into my Arduino/libraries folder.I've tried the NewSoftSerialTest sketch as well and I see nothing after the Sparkfun logo splash.I'm sure there's just a stupid mistake that I'm making that can be easily rectified.FWIW, script does work. Ports 0 and 1 are the ports that Arduino's built-in Serial library uses.
![]()
Your code that calls Serial.print(val) works only because you are connected to pins 0 and 1. The problem with that, is that everytime you want to update your code, you have to disconnect the LCD from 0 and 1 or it interferes with the upload from the Arduino IDE.To get around this, we use NewSoftSerial. It is very similar to the built-in Serial, except that you can use pins other than 0 and 1.So.1.
Move your NewSoftSerial lcdSerialPort(0, 1) to some other pins like NewSoftSerial lcdSerialPort(8, 9). Move your LCD wires to 8 and 9 also.2. Replace your Serial.print(val) statement with lcdSerialPort.print(val);Now you can update your code without disconnecting the LCD. And you can take advantage of the convenience functions that I created (drawBox, drawCircle, etc.)Additionally, you can send debugging output to Serial.print and you can see them in the Arduino IDE's serial port monitor.Note that there's been a lot of activity in the comments under the product. You might read through them here:I got it up and running pretty quick. If memory serves, there was something quirky about the baud rate.
Check into that if it doesn't work. Hopper1068 wrote:Ports 0 and 1 are the ports that Arduino's built-in Serial library uses. Your code that calls Serial.print(val) works only because you are connected to pins 0 and 1. The problem with that, is that everytime you want to update your code, you have to disconnect the LCD from 0 and 1 or it interferes with the upload from the Arduino IDE.To get around this, we use NewSoftSerial. It is very similar to the built-in Serial, except that you can use pins other than 0 and 1.Thanks for the explanation here, this makes sense. I had been disconnecting the TX line per a recommendation read on the Sparkfun product comments, now I know how to get around that.So.1. Move your NewSoftSerial lcdSerialPort(0, 1) to some other pins like NewSoftSerial lcdSerialPort(8, 9).
Move your LCD wires to 8 and 9 also.2. Replace your Serial.print(val) statement with lcdSerialPort.print(val);Now you can update your code without disconnecting the LCD. And you can take advantage of the convenience functions that I created (drawBox, drawCircle, etc.)Additionally, you can send debugging output to Serial.print and you can see them in the Arduino IDE's serial port monitor.Is there a reason that the clearScreen in my code doesn't work?Note that there's been a lot of activity in the comments under the product. You might read through them here:I got it up and running pretty quick. If memory serves, there was something quirky about the baud rate. Check into that if it doesn't work.I've been through those comments and the comments on the standalone backpack a few times, most people recommend SummoningDark's firmware and there's not a ton of discussion using the screen as-is.
Is there a reason that the clearScreen in my code doesn't work?Are you seeing any output? I just now took my original code from this thread, hooked up the LCD as described in the comments of that code, and it worked first try. You should see a big X, circle, box and hello world on the display.I forgot that you need to power the LCD with 6-7vdc.
Powering everything off of the Arduino pins (and therefore the USB line) won't work (only 5vdc). That's why I pump 7vdc into the Arduino's external power, and then power the LCD off of the Raw or Vin pin next to Gnd (which spits out whatever voltage you're pumping in the external power jack).The datasheet has a lot of good info on this board.
Identify the display
You need to know the controller and the size of your display (Note: 'Controllerless'displays are not supported by U8g2).In this example, we will use a ST7920 128x64 display. It has a ST7920 controllerwith a 128x64 LCD .
For U8g2 you have to select a matching constructor for the correct initialization ofthe display. Select a constructor from this page:C++ Setup/Arduino Constructor List
Often the constructor is also mentioned in the examples. But you may need touncomment the matching constructor.
For this example, locate the ST7920 128x64 section.
Select a physical bus
Graphics information has to be sent to the display. This information is received bythe display controller through a physical bus (usually two or more data lines),
a communication protocol and a command sequence. Often a display supports morethan one physical bus. You have to select and setup the correct bus.
The physical bus is selected by connecting special pins to GND (Low) or +5V (High).This SSD1306 oled, the PCB has several solder pads (labeled as BS0, BS1 and BS2)to setup the physical bus:
A small table on the left side gives hints about what setting will setup which bus.Typically the busses are:
At this point of time, it is often a good idea to read the datasheet of the displaycontroller or the manual for your display for instruction on how to setup a specificbus.
Sometimes the bus is just fixed and can not be changed. For this oled withSSD1306 controller nothing can be changed:
The type of the bus can be guessed from the number of pins and their lables. Inthis case, it seems to be a I2C bus because of the SCL and SDA lables.
For our initial example the PCB looks like this:
According to the ST7920 datasheet, the PSB pin selects between the 8-Bit and theserial (SPI) bus. For the serial bus, pin 'RS' is 'Chip-Select', pin 'E' willbe the clock input and pin 'RW' acts as data line.
Note: In the picture, PSB is connected to BLK, which in turn is connected to GND.This will select the serial bus for the ST7920 display.
Identify digital lines
The display must be connected to the Arduino board in order to transferdata from the Arduino board to the display. Depending on the selectedphysical bus, several pins have to be connected to the outputs of theArduino board.
In general, U8g2 can use any outputs of your Arduino Board.So it does not matter which output pin is used (However it might be cleverto select specific pins for hardware accelerated bus communication).
My suggestion is to write down the wiring. Here is the example for the ST7920 display.
Note: RS (as labled on the PCB) actually means 'Register Select', however for SPI mode the RS pin becomes 'Chip Select'.
Remember to connect PSB pin with GND. Also apply correct voltage to the V0 inputfor this type of display (see datasheet).
U8g2 initialization
U8g2 needs to know which output pin is connected to which input of the display:The pin numbers are provided as list of arguments to the U8g2 constructor.The position within the list is important and indicates the function/purposeof the pin.
From the table here, the constructorhas the following template (with
u8g2 as object name):
After something which is called 'rotation', the constructor expects the pin numberfor the clock line, the data line and the chip select line (cs). The resetline can be provided optionally.
The examples include similar constructor calls. You can uncomment one of themand update the pin numbers, if required:
A complete example will look like this:
U8g2 supports three different drawing modes:
Full screen buffer modePros and Cons
![]() Setup
Use the U8g2 constructor from here. The constructormust include the 'F' character. For example:
U8G2_ST7920_128X64_ F_SW_SPI(rotation, clock, data, cs [, reset])
Usage
ExamplePage buffer mode (Picture Loop)Pros and Cons
Setup
Use the U8g2 constructor from here. The constructormust include the '1' or '2' character. For example:
U8G2_ST7920_128X64_ 1_SW_SPI(rotation, clock, data, cs [, reset])
Usage
Note: Always create the same picture inside theloop body. See details here.
ExampleU8x8 character modePros and Cons
Setup
Use the U8x8 constructor from here. For example:
U8X8_ST7565_EA_DOGM128_4W_SW_SPI u8x8(clock, data, cs, dc [, reset])
Usage
All draw commands directly write to the display.
Example![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |