Raspberry PIxel dri...
 
Notifications
Clear all

Raspberry PIxel driver.

128 Posts
25 Users
0 Reactions
46.5 K Views
Barnabybear
Posts: 1583
Topic starter
(@barnabybear)
Noble Member
Joined: 15 years ago

Hi Zeph.
Yep that will do it nicely, and as you say we could use the other GPIO pins and an 'and gate' to multplex (or a shift register on CE1 and send data on CE0. Processor time and every thing else permitting). The reason I like the SPI output and am trying to stay away from the other GPIO, is that I beleve that you can prevent the processor from becomming distracted and doing other things during an SPI write.

I am still hoping that, if we do a 6 bit SPI write @ 16MHz for the 2811s the timing will be correct (i.e write to 6 strings - 3 sections per bit) Effectively meaning that we could control 6 strings. It would mean that the same output board (about $10 photos in next post) could in theory control:
2801 - 4 strings
3001 - 8 strings
2811 - 6 strings
(All dependant on a million and one other things that I haven't come across yet).

The nicest bit of this project (for me) is that, normaly I'm given a end result with a fixed spec that must be achieved. With this I have something to start with, and a chalange to see what I can get out of it.
I have set myself some rules; must be cheap, anyone who can solder can make parts and the finished item must be easy to continue to expand upon (both hard and software).


Reply
Posts: 35
(@snunn)
Eminent Member
Joined: 17 years ago

Can anyone point me to the appropriate connector to use on a pcb for connecting the lights to. Not sure what to pick on mouser.


Reply
Barnabybear
Posts: 1583
Topic starter
(@barnabybear)
Noble Member
Joined: 15 years ago

Finaly got the bits soldered up (will post photos tomorrow -need to find my digital camera as the phone takes photos that are to high a resalution to upload to the site).

It mostly works - it only lights the first pixel (and sometimes the second pixel) but I'm sure this is due to the way I'm calling the SPI write from python and the default SPI speed (which I can't change doing it this way).
Anyway, here is the code I've used to test the board and find out which bits appear on which output etc. It is written in Python.

This one has lots of notes.

import sys

# single test string of 2801s on outputs 7 and 8 - 7 is data 8 is clock

# defines 6 sets of data - 1=R 2=G 3=B L=clock low H=clock high
# LSB -> MSB used below - that makes bit 8 the 8th form the left
# b\40 = 00000010 outputs data high on 7 and clock low on 8
# b\c0 = 00000011 outputs data high on 7 and clock high on 8
# this data results in = 255 red - 255 green - 255 blue - so white
pix_1_L = bytearray(b'\40')
pix_1_H = bytearray(b'\c0')
pix_2_L = bytearray(b'\40')
pix_2_H = bytearray(b'\c0')
pix_3_L = bytearray(b'\40')
pix_3_H = bytearray(b'\c0')

# pix_qty = the number of pixels in the string
# pix_num = sets the counter for the pixel currently being writen to in the loop - starts at 1 and runs to pix_qty
pix_qty = 3
pix_num = 1

# so I know somthing is happening
print "writing to pixels"

# main loop - loops the number of times = to pix_qty - so once for each pixel in the string
while pix_num <= pix_qty:

  # sets / resets the counters for the loops that deal with each colour starts at 1 and runs to 8
  bit1 = 1
  bit2 = 1
  bit3 = 1

  # loop that writes the red data bit - the way it's currently setup it sends the same bit '1' 8 times
  # the first write is data 1 and clock 0 (low)
  # the second write is data 1 and clock 1 (high)
  # adds 1 to the counter
  while bit1 <=8:
    file('dev/spidev0.0', "wb").write(pix_1_L)
    file('dev/spidev0.0', "wb").write(pix_1_H)
    bit1 += 1

  # loop that writes the green data bit - same as red fromat
  while bit2 <=8:
    file('dev/spidev0.0', "wb").write(pix_2_L)
    file('dev/spidev0.0', "wb").write(pix_2_H)
    bit2 += 1

  # loop that writes the blue data bit - same as red fromat
  while bit3 <=8:
    file('dev/spidev0.0', "wb").write(pix_3_L)
    file('dev/spidev0.0', "wb").write(pix_3_H)
    bit3 += 1

  # adds 1 to the pixel currently being writen to counter - returns to start of loop untill all pixels have been writen to
  pix_num +=1

#clears data from the spidev file as we have sent all we need to atm
file('dev/spidev0.0', "wb").flush()

# job done - program ends - lights should have displayed data

This one is the same but without the notes.

import sys
pix_1_L = bytearray(b'\40')
pix_1_H = bytearray(b'\c0')
pix_2_L = bytearray(b'\40')
pix_2_H = bytearray(b'\c0')
pix_3_L = bytearray(b'\40')
pix_3_H = bytearray(b'\c0')
pix_qty = 3
pix_num = 1
print "writing to pixels"
while pix_num <= pix_qty:
  bit1 = 1
  bit2 = 1
  bit3 = 1
  while bit1 <=8:
    file('dev/spidev0.0', "wb").write(pix_1_L)
    file('dev/spidev0.0', "wb").write(pix_1_H)
    bit1 += 1
  while bit2 <=8:
    file('dev/spidev0.0', "wb").write(pix_2_L)
    file('dev/spidev0.0', "wb").write(pix_2_H)
    bit2 += 1
  while bit3 <=8:
    file('dev/spidev0.0', "wb").write(pix_3_L)
    file('dev/spidev0.0', "wb").write(pix_3_H)
    bit3 += 1
  pix_num +=1
file('dev/spidev0.0', "wb").flush()

I can shorten this even more but I can't see the point at the moment as it becomes really hard to follow.


Reply
Posts: 135
(@ptone)
Estimable Member
Joined: 16 years ago
Barnabybear wrote:It is written in Python.

There are quite a few optimizations that could be made here. The most important is to probably only get your SPI file handle once

I know very little format about the specific pixel chip protocols, or the kind of bitbanging you are trying to do, but for starters:

import sys
low = b'\40'
high = b'\c0'
pix_qty = 3
print "writing to pixels"
spi = file('dev/spidev0.0', "wb")
for pix in range(pix_qty)
    msg = bytearray()
    for bit in range(8):
        msg.append(low)
        msg.append(high)
    spi.write(msg)
    spi.flush()
spi.close()

Reply
Posts: 238
(@ronp5683)
Reputable Member
Joined: 14 years ago

I like where you are going with this simple example of how to convert the SPI to the serial outputs. However, when an operating system is involved often it is difficult keeping the output running at speed. This is why there is often fairly large memory buffers. You could do a similar translation with a fifo memory. You can input parallel data to the FIFO using the GPIO, and then use a slow oscillator to clock the data back out. With the extra memory as a buffer, maybe it would run smoother. Just a thought.

http://www.nxp.com/documents/data_sheet/74HC_HCT7403.pdf


Reply
Page 24 / 26
Share: