# SHARP Memory Displays
#spi #SharpMemory
## Parts
- [Adafruit SHARP Memory Display Breakout](https://www.adafruit.com/product/4694) - 2.7" 400x240 Monochrome
## Wiring
The most challenging part of putting together the [[tenet-brick|Tenet Brick]] was figuring out exactly how to connect the SHARP display to the Pi such that the driver software could write data to it. It took a little forensics and a constant reminder that the constants in the software are pin number, not GPIO number. Anyway, have a diagram:

- Pi pin 16 (`GPIO23`) connects to SHARP `CS`.
- Pi pin 17 (`3V3`) connects to SHARP `3V3`.
- Pi pin 18 (`GPIO24`) connects to SHARP `DISP`.
- Pi pin 19 (`MOSI`) connects to SHARP `DI`.
- Pi pin 20 (`GND`) connects to SHARP `GND`.
- Pi pin 22 (`GPIO25`) connects to SHARP `EIN`.
- Pi pin 23 (`SCLK`) connects to SHARP `CLK`.
## Code
The SHARP Memory Display Breakout communicates using SPI
([Serial Peripheral Interface](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface)), which is not a protocol that Raspberry Pi knows how to use for our display data.
In order to make this transition, we need a piece of software that knows both how to read the Raspberry Pi's display buffer and how to write to the SHARP display over SPI.
We're going to download an application and a service file from someone's GitHub repository. I know, you wouldn't [download a car](https://www.youtube.com/results?search_query=you+wouldn%27t+download+a+car), but you _can_ and _should_ download free and open-source software to make an awful little chonker of a tty calculator.
The application is going to run at system startup (that's what the service file does), and while it's running it's going to copy pixels from the Raspberry Pi's regular display buffer onto the SHARP display over SPI. It will do this quite fast, maybe not as fast as a standard HDMI monitor, but still fast enough for our purposes.
These steps are essentially a rewrite of hra1129's [guide on GitHub](https://github.com/hra1129/ShaRPIKeebo-customize-for-japanese/blob/main/sharp_memory_display/readme_en.txt).
### 1. Flashing and getting situated
First, start by flashing an SD card with Raspbian (terminal mode, not desktop mode).
Connect the Pi to an HDMI monitor, a keyboard, and to the SHARP display breakout. Plug in the SD card. Then, connect power.
### 2. Libraries
We need to install some libraries that our custom software requires:
```sh
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install pulseaudio libpulse-dev python3-pip python3-pil pigpiod
$ git clone https://github.com/bitbank2/ArmbianIO.git
$ cd ArmbianIO/
$ make
$ sudo reboot
```
### 3. Boot Configuration
Next, we need to make sure the Pi has a usable SPI bus, and that it will still render display data even when it doesn't detect an HDMI monitor:
```sh
$ sudo nano /boot/config.txt
```
Use the arrow keys to navigate through the file, and make sure the following settings are correct. Note that the original config file may have these commented-out, or set to different values:
```
framebuffer_width=400
framebuffer_height=240
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=85
#dtoverlay=vc4-kms-v3d
dtparam=spi=on
```
When you're finished, press `Ctrl+x` to exit, `y` to save the file before exiting, and `Enter` to save the file with the same filename.
For reference, [here is the entire config.txt](https://github.com/spilliams/tenet/blob/main/writers-brick/config.txt) my pi is running, and [here is the one hra1129 recommends](https://github.com/hra1129/ShaRPIKeebo-customize-for-japanese/blob/8bff846c94760b49020fe74b6dcce30ac16745cf/sharp_memory_display/config.txt).
### 4. System Service
Copy hra1129's `sharpikeebo_lcd` application from the [sharpikeebo_lcd folder](https://github.com/hra1129/ShaRPIKeebo-customize-for-japanese/tree/main/sharp_memory_display/sharpikeebo_lcd) to your Pi.
```sh
$ wget "https://github.com/hra1129/ShaRPIKeebo-customize-for-japanese/raw/main/sharp_memory_display/sharpikeebo_lcd/sharpikeebo_lcd"
...
Saving to: 'sharpikeebo_lcd'
...
```
Copy the application into its place of honor:
```sh
$ sudo cp ~/sharpikeebo_lcd /usr/local/bin/
```
Create a service file:
```sh
$ sudo nano /etc/systemd/system/sharpikeebo_lcd.service
```
It should have the following contents:
```service
[Unit]
Description=sharpikeebo_lcd
Requires=pigpiod.service
After=pigpiod.service
[Service]
ExecStart=/usr/local/bin/sharpikeebo_lcd -noblink -invert --
Type=simple
Restart=on-failure
[Install]
WantedBy=default.target
```
(If you don't like the boot splash screen saying "morpheans sharpikeebo", you can turn that off by modifying line 7 of the service file to `ExecStart=/usr/local/bin/sharpikeebo_lcd -noblink -invert -nosplash --`)
When you're finished writing the service file, press `Ctrl+x` to exit, `y` to save the file before exiting, and `Enter` to save the file with the same filename.
Modify the application and the service file to make sure they're runnable:
```sh
$ sudo chmod 755 /usr/local/bin/sharpikeebo_lcd
$ sudo chmod 755 /etc/systemd/system/sharpikeebo_lcd.service
```
Enable and start the service!
```sh
$ sudo systemctl enable sharpikeebo_lcd
Created symlink /etc/systemd/system/default.target.wants/sharpikeebo_lcd.service -> /etc/systemd/system/sharpikeebo_lcd.service.
$ sudo systemctl start sharpikeebo_lcd
```
Your SHARP display should now be mirroring everything that's on the HDMI monitor. And, if you unplug the HDMI monitor, it should continue to work!
### 5. Readability
I did not find the default font to be very readable, especially at such a small size.
I looked through the `/usr/share/consolefonts/` directory (which is large.
`less` is your friend here. Try `ls /usr/share/consolefonts/ | less` and use the up and down arrows to scroll, or `f` and `b` to page forward and back, respectively. Press `q` to exit `less`.).
I tried out a few alternatives with `setfont /usr/share/consolefonts/FILE.psf.gz`, and once I found one I liked I wrote it into the console setup by running
```sh
$ sudo nano /etc/default/console-setup
```
I changed it so it read
```txt
...
FONTFACE="Terminus"
FONTSIZE="8x14"
...
```
When you're finished, press `Ctrl+x` to exit, `y` to save the file before exiting, and `Enter` to save the file with the same filename.
This was the font face and size for all of the photos in this post, although now that I've used it some I realize I should probably bump up the size a little...