djmcg Posted December 31, 2019 Share Posted December 31, 2019 Hello Ones again I need Your advice for steering RGB LED APA106. I try to search for any program to control this Led but most of them is for RPI and it`s not work for My OPI. Is this connection for DIN should by for any SPI1?: Do You have idea how to for example set change color of led ? Regards Link to comment Share on other sites More sharing options...
martinayotte Posted December 31, 2019 Share Posted December 31, 2019 1 hour ago, djmcg said: Do You have idea how to for example set change color of led ? You need some NeoPixel library ... Here are some info extracted from https://gist.github.com/probonopd/97f6826cc5aa3c0c0950682b0bc266bc WS2812B Neopixels driven by Python Connect the data line of the WS2812B Neopixels to pin SPI1_MOSI/PA15. In /boot/armbianEnv.txt we need: overlays=spi-spidev param_spidev_spi_bus=1 param_spidev_max_freq=100000000 We can successfully compile the needed Python libraries on the device itself: git clone https://github.com/doceme/py-spidev.git cd py-spidev make -j4 make install cd .. git clone https://github.com/joosteto/ws2812-spi.git find ws2812-spi/ -type f -name '*.py' -exec sed -i -e 's|spi.open(0,0)|spi.open(1,0)|g' {} \; find ws2812-spi/ -type f -name '*.py' -exec sed -i -e 's|tx=\[\]|tx=\[0x00\]|g' {} \; Make sure to use spi.open(1,0); we need to use SPI bus 1 since the internal SPI Flash is connected to SPI bus 0. # Make 16 LEDs red ./ws2812-spi/ws2812.py -c "[[0,255,0]]" -n 16 # Make 16 LEDs white ./ws2812-spi/ws2812.py -c "[[255,255,255]]" -n 16 # Switch 16 LEDs off ./ws2812-spi/ws2812.py -c "[[0,0,0]]" -n 16 1 Link to comment Share on other sites More sharing options...
djmcg Posted January 1, 2020 Author Share Posted January 1, 2020 Hello thank for reply: 16 hours ago, martinayotte said: Connect the data line of the WS2812B Neopixels to pin SPI1_MOSI/PA15 I Have the OPI WIN not Zero so I connect to SPI1_MOSI/PD2 hope it`s good. Next I edit the /boot/armbianEnv.txt file like below : and saved. Next steps like You wrote please check: Unfortunately I have error: Could You advice what I`m doing wrong? Link to comment Share on other sites More sharing options...
martinayotte Posted January 1, 2020 Share Posted January 1, 2020 4 hours ago, djmcg said: Could You advice what I`m doing wrong? It seems not finding the /dev/spi1.0 ... Did you rebooted after having edited the /boot/armbianEnv.txt to add the overlay ? Link to comment Share on other sites More sharing options...
djmcg Posted January 1, 2020 Author Share Posted January 1, 2020 Yes I`m reboot after save What You mean "overlay" Link to comment Share on other sites More sharing options...
martinayotte Posted January 1, 2020 Share Posted January 1, 2020 Just now, djmcg said: What You mean "overlay" This is loading an overlay : overlays=spi-spidev param_spidev_spi_bus=1 It should make /dev/spi1.0 appearing ... Which Armbian image are you using ? Link to comment Share on other sites More sharing options...
djmcg Posted January 1, 2020 Author Share Posted January 1, 2020 The system image: https://dl.armbian.com/_old/orangepiwin/archive/Armbian_19.11.4_Orangepiwin_bionic_current_5.3.13_desktop.img.gz Now I have problem with connection to internet Link to comment Share on other sites More sharing options...
martinayotte Posted January 1, 2020 Share Posted January 1, 2020 Dou you see the /dev/spi1.0 ? Link to comment Share on other sites More sharing options...
djmcg Posted January 2, 2020 Author Share Posted January 2, 2020 I have "spidev1.0" Link to comment Share on other sites More sharing options...
djmcg Posted January 3, 2020 Author Share Posted January 3, 2020 Hello I just reinstall Armbian and RGB led start work However after update sudo apt install python-numpy My LED colors is change now off is red and other colors is diffrent Could You advice why? ? Link to comment Share on other sites More sharing options...
djmcg Posted January 5, 2020 Author Share Posted January 5, 2020 I just uninstall python-numpy an color back to normal. I would like to wrote some short code for change colors in python Could You advice how to implement this commands for code On 12/31/2019 at 6:13 PM, martinayotte said: # Make 16 LEDs red ./ws2812-spi/ws2812.py -c "[[0,255,0]]" -n 16 # Make 16 LEDs white ./ws2812-spi/ws2812.py -c "[[255,255,255]]" -n 16 # Switch 16 LEDs off ./ws2812-spi/ws2812.py -c "[[0,0,0]]" -n 16 Link to comment Share on other sites More sharing options...
martinayotte Posted January 5, 2020 Share Posted January 5, 2020 1 hour ago, djmcg said: Could You advice how to implement this commands for code What do you mean ? Do you mean alternating colors within the same script ? Simply add sleep command between each calls to ws2812.py ... Link to comment Share on other sites More sharing options...
djmcg Posted January 6, 2020 Author Share Posted January 6, 2020 13 hours ago, martinayotte said: What do you mean ? Do you mean alternating colors within the same script ? Simply add sleep command between each calls to ws2812.py ... Yes I know how to generate colors But won`t work I don`t know where to paste this script of different colors. Link to comment Share on other sites More sharing options...
martinayotte Posted January 6, 2020 Share Posted January 6, 2020 4 hours ago, djmcg said: But won`t work You seems to add calls within the script itself, which is bad technique, resulting to such python error ... Leave the script unmodified and use a bash script as the master script such as : #!/bin/bash while true; do ./ws2812-spi/ws2812.py -c "[[255,0,0]]" -n 16 sleep 0.5 ./ws2812-spi/ws2812.py -c "[[0,255,0]]" -n 16 sleep 0.5 ./ws2812-spi/ws2812.py -c "[[0,0,255]]" -n 16 sleep 0.5 done Link to comment Share on other sites More sharing options...
djmcg Posted January 6, 2020 Author Share Posted January 6, 2020 I`m really need update script in Python Do You have idea how to update this script for example to kept the same effect what You wrote ? Link to comment Share on other sites More sharing options...
martinayotte Posted January 6, 2020 Share Posted January 6, 2020 1 hour ago, djmcg said: I`m really need update script in Python Do You have idea how to update this script for example to kept the same effect what You wrote ? Then delete all those lines : if color!=None: write2812(spi, eval(color)*nLED) elif doTest: test_fixed(spi, nLED) else: usage() and add those ones : while 1: write2812(spi, [[255,0,0]) time.sleep(0.5) write2812(spi, [[0,255,0]) time.sleep(0.5) write2812(spi, [[0,0,255]) time.sleep(0.5) Be careful about indentation, python is strict about line alignements ... Link to comment Share on other sites More sharing options...
djmcg Posted January 6, 2020 Author Share Posted January 6, 2020 I paste the code what You wrote and perform some updates Unfortunately it`s not work However I make some short script like You mentioned before and it`s work but it`s something wrong the RGB LED sometime when should be "off" [(black) (0,0,0)] sometimes shines as RED. Link to comment Share on other sites More sharing options...
martinayotte Posted January 6, 2020 Share Posted January 6, 2020 5 minutes ago, djmcg said: Unfortunately it`s not work You use parenthesis instead of brackets !!! It should be "write2812(spi, [[0,0,255]])" instead of "write2812(spi, (0,0,255))" Link to comment Share on other sites More sharing options...
djmcg Posted January 6, 2020 Author Share Posted January 6, 2020 Update, something work but colors is different that should be back to you first script please check the video the colors is diifren than code (RED is note in Code) VID_20200106_171151.mp4 Link to comment Share on other sites More sharing options...
martinayotte Posted January 6, 2020 Share Posted January 6, 2020 Maybe due to the fact that you didn't provide color inside quotes ... Try something like : Green = "/root/Downloads/ws2812-spi/ws2812.py -c \"[[0,255,0]]\" -n 1" Link to comment Share on other sites More sharing options...
djmcg Posted January 6, 2020 Author Share Posted January 6, 2020 Update code But nothing chnage (however i just lern how to use "" twice Thanks (\" did`t know\" ) import os import time White = "/root/Downloads/ws2812-spi/ws2812.py -c \"[[255,255,255]]\" -n 1" Green = "/root/Downloads/ws2812-spi/ws2812.py -c \"[[0,255,0]]\" -n 1" Blue = "/root/Downloads/ws2812-spi/ws2812.py -c \"[[0,0,255]]\" -n 1" Red = "/root/Downloads/ws2812-spi/ws2812.py -c \"[[255,0,0]]\" -n 1" Off = "/root/Downloads/ws2812-spi/ws2812.py -c \"[[0,0,0]]\" -n 1" y = 0.5 while True: os.system(White) print("white") time.sleep(y) os.system(Off) print("sleep") time.sleep(y) os.system(Blue) time.sleep(y) os.system(Off) time.sleep(y) os.system(Green) time.sleep(y) os.system(Off) time.sleep(y) Link to comment Share on other sites More sharing options...
martinayotte Posted January 6, 2020 Share Posted January 6, 2020 38 minutes ago, djmcg said: But nothing chnage But what are the color discripancies ? White is white, right ? Maybe bytes are swapped, for example, is red become blue ? Link to comment Share on other sites More sharing options...
djmcg Posted January 7, 2020 Author Share Posted January 7, 2020 I`m observe that often [0,0,0] (turnoff) is RED. Link to comment Share on other sites More sharing options...
martinayotte Posted January 7, 2020 Share Posted January 7, 2020 3 hours ago, djmcg said: I`m observe that often [0,0,0] (turnoff) is RED. If you only send [0,0,0] frequently, does it becomes RED sometimes ? If Yes, maybe it is SPI speed issue ... Link to comment Share on other sites More sharing options...
djmcg Posted January 8, 2020 Author Share Posted January 8, 2020 20 hours ago, martinayotte said: If you only send [0,0,0] frequently, does it becomes RED sometimes ? Yes. It`s any possible to rework that? any resistor help? Link to comment Share on other sites More sharing options...
martinayotte Posted January 8, 2020 Share Posted January 8, 2020 1 hour ago, djmcg said: It`s any possible to rework that? I don't know, maybe by lowering the SPI speed ... Try to change those lines, replacing the 1.05 by 5.05 : #print [hex(v) for v in tx] spi.xfer(tx, int(4/1.05e-6)) 1 hour ago, djmcg said: any resistor help? Issue has nothing to do with resistor ... Link to comment Share on other sites More sharing options...
Recommended Posts