Raspberry Pi with 36mm Square RGB Pixels (WS2801)

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
MrStone
 
Posts: 2
Joined: Thu Nov 19, 2015 12:38 am

Raspberry Pi with 36mm Square RGB Pixels (WS2801)

Post by MrStone »

Hello,

I'm currently trying to get Raspberry Pi (Rev1 B) to control Adafruit 36mm Square RGB Pixels (WS2801). https://www.adafruit.com/products/683

I have the Adafruit WebIDE installed and running.

The Adafruit_LEDPixels.py example seams to work, however there a bit of random flickering doing on.


My question is how do you set all the pixels to a given colour?
The tutorial at https://learn.adafruit.com/36mm-led-pixels/code only gives code for the arduino.

Has anyone got an examples of how you can control them using python?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Raspberry Pi with 36mm Square RGB Pixels (WS2801)

Post by adafruit_support_rick »

MrStone wrote:My question is how do you set all the pixels to a given colour?

Code: Select all

	for i in range(len(pixels)):
		setpixelcolor(pixels, i, Color(r, g, b))
	writestrip(pixels)

User avatar
MrStone
 
Posts: 2
Joined: Thu Nov 19, 2015 12:38 am

Re: Raspberry Pi with 36mm Square RGB Pixels (WS2801)

Post by MrStone »

Hi Rick,

Thanks for your reply.

I'm not that good with python code, I put the code below together but nothing happens.

What am I doing wrong? Please help!

Code: Select all

#!/usr/bin/env python

# Test code for Adafruit LED Pixels, uses hardware SPI

import RPi.GPIO as GPIO, time

DEBUG = 1
GPIO.setmode(GPIO.BCM)

def slowspiwrite(clockpin, datapin, byteout):
	GPIO.setup(clockpin, GPIO.OUT)
	GPIO.setup(datapin, GPIO.OUT)
	for i in range(8):
		if (byteout & 0x80):
			GPIO.output(datapin, True)
		else:
			GPIO.output(clockpin, False)
		byteout <<= 1
		GPIO.output(clockpin, True)
		GPIO.output(clockpin, False)


SPICLK = 23
SPIDO = 19

ledpixels = [0] * 25

def writestrip(pixels):
	spidev = file("/dev/spidev0.0", "w")
	for i in range(len(pixels)):
		spidev.write(chr((pixels[i]>>16) & 0xFF))
		spidev.write(chr((pixels[i]>>8) & 0xFF))
		spidev.write(chr(pixels[i] & 0xFF))
	spidev.close()
	time.sleep(0.002)

def Color(r, g, b):
	return ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF)

def setpixelcolor(pixels, n, r, g, b):
	if (n >= len(pixels)):
		return
	pixels[n] = Color(r,g,b)

def setpixelcolor(pixels, n, c):
	if (n >= len(pixels)):
		return
	pixels[n] = c

def colorwipe(pixels, c, delay):
	for i in range(len(pixels)):
		setpixelcolor(pixels, i, c)
		writestrip(pixels)
		time.sleep(delay)			
        

        while True:        
                setpixelcolor(pixels, i, Color(50, 50, 0))

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Raspberry Pi with 36mm Square RGB Pixels (WS2801)

Post by adafruit_support_rick »

Code: Select all

        while True:        
		for i in range(len(ledpixels)):
			setpixelcolor(ledpixels, i, Color(50, 50, 0))
		writestrip(ledpixels)
		time.sleep(1)

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”