樹莓派系列三(max7219 led點陣)

在網上看到一篇樹莓派diy智能家居服務器的文章,對裏面的led點陣的鐘比較感興趣(原諒我家也沒有鍾...囧),所以某寶搜了一個4*8*8的led點陣回來弄的時間在家裏顯示(做爲服務器閒着也是閒着...)

實現方法和文章中的有所不同,這裏通過spi控制,所用管腳如下,需要5根杜邦線母對母的.



樹莓派需要開啓spi功能,在終端輸入
sudo raspi-config

找一下spi功能的enable,這裏不做介紹了,網上很多,菜單選擇可能有所不同,多翻翻就看到了.開啓好之後,


$ lsmod | grep -i spi
spi_bcm2835             7424  0

$ ls -l /dev/spi*
crw------- 1 root root 153, 0 Jan  1  1970 /dev/spidev0.0
crw------- 1 root root 153, 1 Jan  1  1970 /dev/spidev0.1


安裝依賴

$ sudo usermod -a -G spi,gpio pi
$ sudo apt-get install python-dev python-pip libfreetype6-dev libjpeg-dev
$ sudo -i pip install --upgrade pip setuptools
$ sudo apt-get purge python-pip

$ sudo -H pip install --upgrade luma.led_matrix


這裏使用github上的項目 ,感情這些無私的大神~~~~~

 

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

$ python examples/matrix_demo.py -h
usage: matrix_demo.py [-h] [--cascaded CASCADED]
                      [--block-orientation {0, 90, -90}]

matrix_demo arguments

optional arguments:
-h, --help            show this help message and exit
--cascaded CASCADED, -n CASCADED
                      Number of cascaded MAX7219 LED matrices (default: 1)
--block-orientation {0, 90, -90}
                      Corrects block orientation when wired vertically
                      (default: 0)

這裏用的4塊8*8的點陣,可以執行python matrix_demo.py -n 4 --block-orientation -90


執行過程中如果報錯

ImportError: No module named led_matrix.device

說明依賴安裝的有問題,執行如下命令解決.

$ sudo rm -rf /usr/local/lib/python2.7/dist-packages/luma*
$ sudo -H pip install -U luma.led_matrix

顯示時間就參考matrix_demo.py中的代碼,每隔60秒輸出一次,從0,0位置顯示時 分即可.

參考:

https://luma-led-matrix.readthedocs.io/en/latest/install.html

https://github.com/rm-hull/luma.led_matrix

https://github.com/rm-hull/luma.led_matrix/issues/104


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章