Jump to content

NanoPi M4V2: SPI - SSD1351 1.5 Inch RGB OLED Display


TCB13
Go to solution Solved by TCB13,

Recommended Posts

Hello,

 

I'm trying to find out how to use a 1.5 Inch RGB OLED Display that uses the SSD1351 IC on a NanoPi M4 however I don't seem to be able to turn on the SPI.

 

I used armbian-config to enable the gpio overlay:

 

[ ] dwc3-0-host
[ ] i2c7
[ ] i2c8
[*] pcie-gen2
[ ] rk3328-opp-1.4ghz
[ ] rk3328-opp-1.5ghz
[ ] rk3399-opp-2ghz
[ ] spi-jedec-nor
[*] spi-spidev
[ ] uart4
[ ] w1-gpio

 

And the SPI isn't showing up on /dev:

 

ls /dev/spi*
ls: cannot access '/dev/spi*': No such file or directory

 

Wasn't this enough to be able to use the SPI1 on this board?

 

SBC: NanoPi M4V2

System: 5.10.35-rockchip64 #21.05.1 SMP PREEMPT Fri May 7 13:53:11 UTC 2021 aarch64 GNU/Linux

Display: https://www.ebay.com/itm/203101646517

Datasheet: https://www.waveshare.com/w/upload/5/5b/1.5inch_RGB_OLED_Module_User_Manual_EN.pdf

 

Thank you.

Link to comment
Share on other sites

So the M4V2 is a supported board. that the SPI isn't working is probably worth a post by itself in the Rockchip 3399 Subforum.

 

At a glance, I tried turning on the SPI on my M4V2 and didn't see any spidev devices pop up, but might need to pull out the serial console to see if u-boot is throwing any warnings about the overlay.

 

Taking a look at the overlay, I'm not sure it looks correct, as it looks like even if it applies the SPI channel is disabled.

 

        fragment@4 {
                target = <0xffffffff>;

                __overlay__ {
                        #address-cells = <0x01>;
                        #size-cells = <0x00>;

                        spidev {
                                compatible = "spidev";
                                status = "disabled";
                                reg = <0x00>;
                                spi-max-frequency = <0x989680>;
                        };
                };
        };

 

 

Link to comment
Share on other sites

7 hours ago, tparys said:

So the M4V2 is a supported board. that the SPI isn't working is probably worth a post by itself in the Rockchip 3399 Subforum.

 

At a glance, I tried turning on the SPI on my M4V2 and didn't see any spidev devices pop up, but might need to pull out the serial console to see if u-boot is throwing any warnings about the overlay.

 

Taking a look at the overlay, I'm not sure it looks correct, as it looks like even if it applies the SPI channel is disabled.

 


        fragment@4 {
                target = <0xffffffff>;

                __overlay__ {
                        #address-cells = <0x01>;
                        #size-cells = <0x00>;

                        spidev {
                                compatible = "spidev";
                                status = "disabled";
                                reg = <0x00>;
                                spi-max-frequency = <0x989680>;
                        };
                };
        };

 

 

 

Thank you for your feedback!

Link to comment
Share on other sites

@piter75,

 

On 6/6/2021 at 9:21 AM, piter75 said:

@TCB13 I am a bit late to the party but I figured it may still be needed ;-)

 

spi-spidev is a special / dynamic overlay. Besides enabling it you need to also configure it and armbian-config cannot currently do that.

 

For configuration options have a look here:

https://github.com/armbian/build/blob/master/patch/kernel/archive/rockchip64-5.10/general-rockchip-overlays.patch#L98-L126

You can also consult the local README file located in: /boot/dtb/rockchip/overlay/README.rockchip-overlays

 

Your comment was crucial to fix my "issue". I enabled the overlay and then as described on the file edited `/boot/armbianEnv.txt` in order to include:

 

param_spidev_spi_bus=1
param_spidev_max_freq=100000000

 

Now the SPI shows up:

~# ls -la /dev/spi*
crw------- 1 root root 153, 0 Sep 16 18:51 /dev/spidev1.0

 

Also passes the spidev_test (https://raw.githubusercontent.com/torvalds/linux/master/tools/spi/spidev_test.c)

~# ./spidev_test
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)

 

(Had to adjust the path)

 

Thank you for the tip!


 

Link to comment
Share on other sites

Now unfortunately luma-oled seems to be yet another problem. I wired up my LCD as:


MOSI > GPIO1_A7 > SPI1_RXD > M4 Pin 21   > LCD DIN Pin (blue)
SCK > GPIO1_B1 > SPI1_CLK > M4 Pin 23     > LCD CLK Pin (yellow)
CS > GPIO1_B2  > SPI1_CSn0 > M4 Pin 24    > LCD CS Pin (orange)

 

DC > GPIO1_A0(3V) > M4 Pin 7        >   LCD DC Pin (green)

RST > GPIO1_A1(3V) > M4 Pin 11    >   LCD RST Pin (white)

 

Display: https://www.ebay.com/itm/203101646517

Datasheet: https://www.waveshare.com/w/upload/5/5b/1.5inch_RGB_OLED_Module_User_Manual_EN.pdf

 

From my understanding I had to get GPIO1_A0 and GPIO1_A1 in the system so the lib could use them.

According to this https://hev.cc/2927.html GPIO mapping I tried:

 

ls -la /dev/spi*
crw------- 1 root root 153, 0 Sep 16 18:51 /dev/spidev1.0

echo 32 > /sys/class/gpio/export
echo 33 > /sys/class/gpio/export

ls -la /sys/class/gpio/
total 0
drwxr-xr-x  2 root root       0 Jan 18  2013 .
drwxr-xr-x 76 root root       0 Jan 18  2013 ..
--w--w----  1 root dialout 4096 Sep 16 20:51 export
lrwxrwxrwx  1 root root       0 Sep 16 20:50 gpio32 -> ../../devices/platform/pinctrl/gpiochip1/gpio/gpio32
lrwxrwxrwx  1 root root       0 Sep 16 20:50 gpio33 -> ../../devices/platform/pinctrl/gpiochip1/gpio/gpio33
lrwxrwxrwx  1 root root       0 Jan 18  2013 gpiochip0 -> ../../devices/platform/pinctrl/gpio/gpiochip0
lrwxrwxrwx  1 root root       0 Jan 18  2013 gpiochip128 -> ../../devices/platform/pinctrl/gpio/gpiochip128
lrwxrwxrwx  1 root root       0 Jan 18  2013 gpiochip32 -> ../../devices/platform/pinctrl/gpio/gpiochip32
lrwxrwxrwx  1 root root       0 Jan 18  2013 gpiochip64 -> ../../devices/platform/pinctrl/gpio/gpiochip64
lrwxrwxrwx  1 root root       0 Jan 18  2013 gpiochip96 -> ../../devices/platform/pinctrl/gpio/gpiochip96
--w--w----  1 root dialout 4096 Sep 16 19:19 unexport

 

Now I tried the luma-oled examples (running as root):

 

python3 3d_box.py --display ssd1351 --interface spi --spi-port 0 --spi-device 1 --gpio-reset 33 --gpio-data-command 32 --width 128 --height 128
usage: 3d_box.py >(....)
3d_box.py: error: GPIO access not available

 

I'm not even sure if this part "--gpio-reset 33 --gpio-data-command 32" is correct. I've tried both the virtual pin number and the hardware number without luck.

 

Also tried to install https://github.com/friendlyarm/RPi.GPIO_NP without much luck:

 

apt-get update
apt-get install python-dev
git clone https://github.com/friendlyarm/RPi.GPIO_NP
cd RPi.GPIO_NP
python3 setup.py install
python3 setup.py install

python3 luma.examples/examples/3d_box.py --display=ssd1351 --interface=spi --width=128 --height=128 --spi-bus-speed=16000000 --bgr --spi-device=1 --spi-port=0 --gpio-reset=33 --gpio-data-command=32 --gpio RPi.GPIO

Traceback (most recent call last):
(...)
RuntimeError: It is not NanoPi based board.


 

Link to comment
Share on other sites

Following my lack of knowledge of the subject I found out another GPIO implementation that seems to have mappings for the NanoPi M4 called OPi.GPIO.

 

Rewired the LCD, I was unsure about the GPIO pin I picked for the DC pin:

 

MOSI > GPIO1_A7 > SPI1_RXD > M4 Pin 21   > LCD DIN Pin (blue)
SCK > GPIO1_B1 > SPI1_CLK > M4 Pin 23     > LCD CLK Pin (yellow)
CS > GPIO1_B2  > SPI1_CSn0 > M4 Pin 24    > LCD CS Pin (orange)

RST > GPIO1_A1(3V) > M4 Pin 11    >   LCD RST Pin (white)
DC > GPIO1_A3(3V)  > M4 Pin 13        >   LCD DC Pin (green)

 

Installed and run the thing without much success:

 

pip3 install --upgrade OPi.GPIO

ls /dev/spi*
/dev/spidev1.0

python3 luma.examples/examples/3d_box.py  \
--display=ssd1351 \
--interface=spi \
--width=128 --height=128 \
--spi-bus-speed=16000000 \
--bgr \
--spi-device=1 --spi-port=0 \
--gpio-reset=35 \
--gpio-data-command=33 \
--gpio OPi.GPIO \
--gpio-mode nanopi.m4.BOARD

Traceback (most recent call last):
  File "luma.examples/examples/3d_box.py", line 129, in <module>
    device = get_device()
  File "/root/luma.examples/examples/demo_opts.py", line 61, in get_device
    device = cmdline.create_device(args)
  File "/usr/local/lib/python3.7/dist-packages/luma/core/cmdline.py", line 246, in create_device
    device = Device(serial_interface=interface(), **params)
  File "/usr/local/lib/python3.7/dist-packages/luma/core/cmdline.py", line 161, in spi
    gpio=self.gpio or GPIO)
  File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 299, in __init__
    bitbang.__init__(self, gpio, transfer_size, reset_hold_time, reset_release_time, DC=gpio_DC, RST=gpio_RST)
  File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 187, in __init__
    self._DC = self._configure(kwargs.get("DC"))
  File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 200, in _configure
    self._gpio.setup(pin, self._gpio.OUT)
  File "/usr/local/lib/python3.7/dist-packages/OPi/GPIO.py", line 470, in setup
    pin = get_gpio_pin(_mode, channel)
  File "/usr/local/lib/python3.7/dist-packages/OPi/pin_mappings.py", line 80, in get_gpio_pin
    return _pin_map[mode][channel]
KeyError: 33

 

From what I understand of https://github.com/rm-hull/OPi.GPIO/blob/master/nanopi/m4.py my physical pin 11 maps to GPIO 33 and physical pin 13 to GPIO 35. Is this even correct?

 

Either way it still fails.

Link to comment
Share on other sites

  • Solution

 I finally managed to get this work. Things I was doing wrong:

  1. Not using the OPi.GPIO replacement library - others aren't compatible with the NanoPi M4;
  2. DIN LCD pin was connected to the SBC RXD instead of TXD;
  3. Passed wrong pin numbers to the libraries (should be the real physical pins numers);
  4. Mistaking SPI port with device...

Here the full guide on how to it properly. Start by installing:

 

apt-get install python3 python3-pip python3-pil libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev libopenjp2-7 libtiff5 -y
pip3 install luma.oled
apt-get remove python3-rpi.gpio rpi.gpio-common
pip3 install --upgrade OPi.GPIO

 

Wire up your LCD as:

 

MISO > GPIO1_B0 > SPI1_TXD > 19    > LCD DIN | Blue 
SCK > GPIO1_B1 > SPI1_CLK > 23     > LCD CLK | Yellow
CS > GPIO1_B2  > SPI1_CSn0 > 24    > LCD CS | Orange

RST > GPIO1_A1(3V) > M4 Pin 11     >  LCD RST Pin | White
DC > GPIO1_A3(3V)  > M4 Pin 13     >  LCD DC Pin | Green

 

Download an run an example:

 

git clone https://github.com/rm-hull/luma.examples.git

python3 luma.examples/examplebounce.py 
--display=ssd1351 \
--interface=spi \
--width=128 --height=128 \
--spi-bus-speed=50000000 \
--spi-device=0 \
--spi-port=1 \
--gpio-reset=11 \
--gpio-data-command=13 \
--gpio OPi.GPIO \
--gpio-mode nanopi.m4.BOARD

 

And you should get something like this:

 

nanopim4v2-ssd1351.jpg

 

It seems to be able to drive the display up to around 45fps without noises like I've experienced before in an Arduino.

 

Enjoy.

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines