Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix on SPI1 vs SPI0 #221

Open
jwilts opened this issue May 28, 2020 · 3 comments
Open

Matrix on SPI1 vs SPI0 #221

jwilts opened this issue May 28, 2020 · 3 comments
Labels

Comments

@jwilts
Copy link

jwilts commented May 28, 2020

Hi this is a bit of a Noob Question but I am hoping that you can give me some direction on how to configure the matrix to run on SPI1 instead of SPI0

I have the same problem on both a Raspberry Pi3 and and PiZero W.

Type of Raspberry Pi

Pi 3 and Pi zero

Linux Kernel version

I am running 4.18.97-v7+ #1294 as my kernel.

Expected behaviour

I am able to get the Max7219 8x8 matrix working properly, however I need to add another SPI device (RC422 RFID Reader) and the two do not seem to want to work sharing the CS pin (pin 24).
(Text on the Max7219 gets garbled and stilted and theRC422 does not work)
From my research (and limited knowledge) I understand that I should be able to move to CS1 (PIN 26) and this in theory should solve my issue.

I am using this as my initialization code for the Max7219:

from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT

import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522

#!/usr/bin/env python
import time 
import RPi.GPIO as GPIO

# Setup gpio
# GPIO.setwarnings(False)
GPIO.setmode (GPIO.BOARD)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(26,GPIO.OUT)

# Turn 8x8 matrix on
GPIO.output(24,GPIO.LOW)

# create matrix device
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=4, block_orientation=-90)
print("Created device")

show_message(device, "test", fill="white", font=proportional(CP437_FONT), scroll_delay=0.1)

# Turn 8x8 matrix Off
GPIO.output(24,GPIO.HIGH)

# turn RFID reader on
GPIO.output(26,GPIO.LOW)

reader = SimpleMFRC522()

try:
        print("Put RFID on Pad")
        id, text = reader.read()
        print(id)
        print(text)
finally:
        GPIO.cleanup()

Actual behaviour

I have tried changing port=1, and device=1 but neither results in anything appearing on the matrix.

port=1 ==> "SPI Device Not Found"
device=1 ==> No error raised, but matrix does not update.

Edit -- I have continued to try to get this working (without any success) I understand that I have to toggle the value on CS to LOW for any SPI device that I want to activate. I have tried manually forcing the GPIO to high and low between the RC522 and the Max7219 but that doesn't appear to do anything.

Anyone who can help with this problem I would be extremely grateful as I am stumped on my project until I can get past this blocking issue.

@J0eK1ng
Copy link

J0eK1ng commented Nov 16, 2021

Hi

I want to use my LED Matrix to display the temp of a MAX6675 Module with a Thermocouple. The MAX6675 will use SPI0 and I need to have the LED Matrix using SPI1. I've been trying to figure this out can you help?

Thanks

@Kyuchumimo
Copy link

luma.core.interface.serial has a peripheral method by bitbang as SPI. This is the only way I see that can solve this problem without the help of the maintainers or contributors who seem to be either no longer active or have abandoned the library.

Instead of defining a serial object as you would normally do:

from luma.core.interface.serial import spi
...
'serial = spi(port=0, device=0, gpio_DC=23, gpio_RST=24)', 

Now you do it like this:

from luma.core.interface.serial import bitbang
...
'serial = bitbang(SCLK=21, SDA=20, CE=16, DC=23, RST=24)',

Please note that the bitbanging method is slower, as the interface is via software, but the advantage is that you can use any of your unused GPIO pins.

If you need more information, check the docsting of the bitbang class:
https://github.com/rm-hull/luma.core/blob/master/luma/core/interface/serial.py#L148

@Kyuchumimo
Copy link

Kyuchumimo commented May 30, 2024

Ok, I found a way to use SPI1.

First check if you have SPI1 enabled. This is done in the terminal with the command ls -l /dev/spi*.

All SPI ports and devices should be displayed.
If SPI1 is enabled, you should see at least one that says /dev/spidev1.*.

If not, it is necessary to activate it. In the terminal type sudo nano /boot/config.txt. To the end of the text document add dtoverlay=spi1-1cs, then press ctrl+s to save and ctrl+x to exit. For the changes to take effect, it is necessary to reboot with sudo reboot.

The default SPI1 pins are as follows:

  • MOSI - pin 38
  • MISO - pin 35
  • CE0 - pin 12
  • CLK - pin 40

If you wish, you can also change the pin of CS0 by adding ,cs0_pin=<pin#> to the line

now check again if SPI1 is already there with ls -l /dev/spi*.
you should see at least one line ending in /dev/spi1.*.
see that the format is spiP.D.

in the spi object, in the port parameter you will put P (in this case 1 of SPI1) and in device you will put D (as in this example we only enable 1 CS, the value is 0).

from luma.core.interface.serial import spi
...
'serial = spi(port=1, device=0, gpio_DC=23, gpio_RST=24)', 

References:
rm-hull/luma.examples#78
https://raspberrypi.stackexchange.com/questions/73346/how-to-enable-spi1-and-spi0-at-the-same-time#73844
https://blog.stabel.family/raspberry-pi-4-multiple-spis-and-the-device-tree/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants