install.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. Installation
  2. ------------
  3. .. note:: The library has been tested against Python 3.6 and newer.
  4. Pre-requisites
  5. ^^^^^^^^^^^^^^
  6. MAX7219 Devices
  7. """""""""""""""
  8. By default, the SPI kernel driver is **NOT** enabled on a Raspberry Pi Raspbian image.
  9. You can confirm whether it is enabled using the shell command below::
  10. $ lsmod | grep -i spi
  11. spi_bcm2835 7424 0
  12. Depending on the hardware/kernel version, this may report **spi_bcm2807** rather
  13. than **spi_bcm2835** - either should be adequate.
  14. And to verify that the devices are successfully installed in ``/dev``::
  15. $ ls -l /dev/spi*
  16. crw------- 1 root root 153, 0 Jan 1 1970 /dev/spidev0.0
  17. crw------- 1 root root 153, 1 Jan 1 1970 /dev/spidev0.1
  18. If you have no ``/dev/spi`` files and nothing is showing using ``lsmod`` then this
  19. implies the kernel SPI driver is not loaded. Enable the SPI as follows (steps
  20. taken from https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial#spi-on-pi):
  21. #. Run ``sudo raspi-config``
  22. #. Use the down arrow to select ``5 Interfacing Options``
  23. #. Arrow down to ``P4 SPI``
  24. #. Select **yes** when it asks you to enable SPI
  25. #. Also select **yes** when it asks about automatically loading the kernel module
  26. #. Use the right arrow to select the **<Finish>** button
  27. #. Reboot.
  28. .. image:: images/raspi-spi.png
  29. After rebooting re-check that the ``lsmod | grep -i spi`` command shows whether
  30. SPI driver is loaded before proceeding. If you are stil experiencing problems, refer to the official
  31. Raspberry Pi `SPI troubleshooting guide <https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md#troubleshooting>`_
  32. for further details, or ask a `new question <https://github.com/rm-hull/luma.led_matrix/issues/new>`_ - but
  33. please remember to add as much detail as possible.
  34. GPIO pin-outs
  35. ^^^^^^^^^^^^^
  36. MAX7219 Devices (SPI)
  37. """""""""""""""""""""
  38. The breakout board has two headers to allow daisy-chaining:
  39. ============ ====== ============= ========= ====================
  40. Board Pin Name Remarks RPi Pin RPi Function
  41. ------------ ------ ------------- --------- --------------------
  42. 1 VCC +5V Power 2 5V0
  43. 2 GND Ground 6 GND
  44. 3 DIN Data In 19 GPIO 10 (MOSI)
  45. 4 CS Chip Select 24 GPIO 8 (SPI CE0)
  46. 5 CLK Clock 23 GPIO 11 (SPI CLK)
  47. ============ ====== ============= ========= ====================
  48. .. seealso:: Also see the section for :doc:`cascading/daisy-chaining <python-usage>`, power supply and
  49. level-shifting.
  50. WS2812 NeoPixels (DMA)
  51. """"""""""""""""""""""
  52. Typically, WS2812 NeoPixels reqire VCC, VSS (GND) and DI pins connecting to the
  53. Raspberry Pi, where the DI pin is usually connected to a PWM control pin such
  54. as GPIO 18.
  55. ============ ====== ============= ========= ====================
  56. Board Pin Name Remarks RPi Pin RPi Function
  57. ------------ ------ ------------- --------- --------------------
  58. 1 DO Data Out - -
  59. 2 DI Data In 12 GPIO 18 (PWM0)
  60. 3 VCC +5V Power 2 5V0
  61. 4 NC Not connected - -
  62. 5 VDD Not connected - -
  63. 6 VSS Ground 6 GND
  64. ============ ====== ============= ========= ====================
  65. The DO pin should be connected to the DI pin on the next (daisy-chained)
  66. neopixel, while the VCC and VSS are supplied in-parallel to all LED's.
  67. WS2812b devices now are becoming more prevalent, and only have 4 pins.
  68. NeoSegments
  69. """""""""""
  70. @msurguy's NeoSegments should be connected as follows:
  71. ============ ====== ============= ========= ====================
  72. Board Pin Name Remarks RPi Pin RPi Function
  73. ------------ ------ ------------- --------- --------------------
  74. 1 GND Ground 6 GND
  75. 2 DI Data In 12 GPIO 18 (PWM0)
  76. 3 VCC +5V Power 2 5V0
  77. ============ ====== ============= ========= ====================
  78. Installing from PyPi
  79. ^^^^^^^^^^^^^^^^^^^^
  80. Install the dependencies for library first with::
  81. $ sudo usermod -a -G spi,gpio pi
  82. $ sudo apt install build-essential python3-dev python3-pip libfreetype6-dev libjpeg-dev libopenjp2-7 libtiff5
  83. .. warning:: The default ``pip`` and ``setuptools`` bundled with apt on Raspbian are really old,
  84. and can cause components to not be installed properly. Make sure they are up to date by upgrading
  85. them first::
  86. $ sudo -H pip install --upgrade --ignore-installed pip setuptools
  87. Proceed to install latest version of the luma.led_matrix library directly from
  88. `PyPI <https://pypi.python.org/pypi?:action=display&name=luma.led_matrix>`_::
  89. $ sudo python3 -m pip install --upgrade luma.led_matrix
  90. Examples
  91. ^^^^^^^^
  92. Ensure you have followed the installation instructions above.
  93. Clone the `repo <https://github.com/rm-hull/luma.led_matrix>`__ from github,
  94. and run the example code as follows::
  95. $ python examples/matrix_demo.py
  96. The matrix demo accepts optional flags to configure the number of cascaded
  97. devices and correct the block orientation phase shift when using 4x8x8
  98. matrices::
  99. $ python examples/matrix_demo.py -h
  100. usage: matrix_demo.py [-h] [--cascaded CASCADED]
  101. [--block-orientation {0,90,-90}] [--rotate {0,1,2,3}]
  102. [--reverse-order REVERSE_ORDER]
  103. matrix_demo arguments
  104. optional arguments:
  105. -h, --help show this help message and exit
  106. --cascaded CASCADED, -n CASCADED
  107. Number of cascaded MAX7219 LED matrices (default: 1)
  108. --block-orientation {0,90,-90}
  109. Corrects block orientation when wired vertically
  110. (default: 0)
  111. --rotate {0,1,2,3} Rotate display 0=0_, 1=90_, 2=180_, 3=270_
  112. (default: 0)
  113. --reverse-order REVERSE_ORDER
  114. Set to true if blocks are in reverse order (default:
  115. False)
  116. Similarly, there is a basic demo of the capabilities of the
  117. :py:class:`luma.led_matrix.virtual.sevensegment` wrapper::
  118. $ python examples/sevensegment_demo.py
  119. and for the :py:class:`luma.led_matrix.device.neopixel` device::
  120. $ sudo python examples/neopixel_demo.py
  121. Further examples are available in the `luma.examples
  122. <https://github.com/rm-hull/luma.examples>`_. git repository. Follow the
  123. instructions in the README for more details.
  124. A small example application using `ZeroSeg
  125. <https://thepihut.com/products/zeroseg>`_ to display TOTP secrets can be
  126. found in https://github.com/rm-hull/zaup.