RPG game + LED pixel game system hardware

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Tue Dec 11, 2012 9:00 pm

Sorry for not getting back to you yesterday. I received my color PICnDuino boards and needed to get one ready ASAP to send to one of the guys at hackaday. He's going to do a write up for me on hackaday so it should get plenty of publicity!

These screens are very interesting in the way they work, and it took me a while to get buy my head around them, but once you have your code to draw graphics, it's really simple to use after that - you just fill your graphic data with a whole heap of 1's and 0's and the draw graphics routine will take care of the rest.

I have the code for swordfish, but not for Arduino (should be very simple to port over though.)

Here's my Port Pins Setup: This is to drive two screens I.E. 32x32 pixels)

Code: Select all

// Port Setup
Dim RedData0 As PORTB.7
Dim RedData1 As PORTB.1
Dim GreenData0 As PORTB.2
Dim GreenData1 As PORTB.3
Dim BlueData0 As PORTB.4
Dim BlueData1 As PORTB.5
Dim RowA As PORTC.0
Dim RowB As PORTC.1 
Dim RowC As PORTC.2
Dim Latch As PORTC.3
Dim CLK2 As PORTA.0
Dim CLK As PORTB.6
Dim OutputEnable As PORTB.0
Then, here's the code to actually send your data to the display:

Code: Select all

Sub DrawGraphics()
    For y = 0 To 7
        TempData0 = OutputDataRed(y)
        TempData1 = OutputDataRed(y + 8)
        TempData2 = OutputDataRed(y + 16)
        TempData3 = OutputDataRed(y + 24)        
        TempData4 = OutputDataGreen(y)
        TempData5 = OutputDataGreen(y + 8)
        TempData6 = OutputDataGreen(y + 16)
        TempData7 = OutputDataGreen(y + 24) 
        TempData8 = OutputDataBlue(y)
        TempData9 = OutputDataBlue(y + 8)
        TempData10 = OutputDataBlue(y + 16)
        TempData11 = OutputDataBlue(y + 24)
        For x = 0 To 31
            RedData0 = TempData0.bits(x)
            RedData1 = TempData1.bits(x) 
            GreenData0 = TempData4.bits(x)
            GreenData1 = TempData5.bits(x) 
            BlueData0 = TempData8.bits(x)
            BlueData1 = TempData9.bits(x)
            CLK2 = 1
            CLK2 = 0
            RedData0 = TempData2.bits(x)
            RedData1 = TempData3.bits(x)
            GreenData0 = TempData6.bits(x)
            GreenData1 = TempData7.bits(x)
            BlueData0 = TempData10.bits(x)
            BlueData1 = TempData11.bits(x)
            CLK = 1
            CLK = 0
        Next
        RowA = y.bits(0)
        RowB = y.bits(1)
        RowC = y.bits(2)
        Latch = 1
        Latch = 0  
        OutputEnable = 0
        DelayUS(250)
        OutputEnable = 1
    Next           
End Sub
These displays draw two rows simultaneously (so if you have two displays together, you are drawing four rows every time you enable the output tri-state buffers) this is why when we load the temp data - we are loading the first one as is, then we load the next one with the data eight rows up from that, then we do the next one eight rows up from the previous one etc...

So when we want to draw a full 32 x 32 pixel picture, we are drawing four rows at once, so we only need to enable then disable the outputs eight times and then once full frame will have been drawn. The data is loaded in serially so we need to shift all the bits in before we display the rows.

Have a look at the code and let me know what you think. It might be kinda hard to get your head around at this stage but we'll get there!

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Tue Dec 11, 2012 10:59 pm

From what I understand, the code works like this:

*load 2 lines or 2 sets of 32 bit variables to display per screen
*clock in the data a bit at a time
*latch and output enable the data to display it


I do not understand what this is or does, or why you set them to y.bits because from what I can see, y.bits is a constant, and you could substitute 0s or 1s instead of them.
RowA = y.bits(0)
RowB = y.bits(1)
RowC = y.bits(2)
I am also having trouble with seeing what the pins are on the screen (there is an inconvenient screw blocking two of the pin identifications) and I am not sure what all of them are.

Reading the pins like an integrated circuit (from top left to bottom left then from bottom right to top right):

R0 = first red line data
U0 = no idea
R1 = second red line data
I cant see it clearly, U1 maybe?
I cant see it
C = no idea
clk = clock for the data
OE = output enable

GND = ground
STB = i don't know
GND = I don't know why they need a second ground
B = I don't know
GND = or a third
G1 = second green line data
GND = and why would you ever need a fourth? Especially since there seems to be a plugin for ground and V+ in the middle of the board also
G0 = first green line data


So if you could help with the pins also, that would be great (hopefully we have the same boards.)

Thanks for the help so far Brad!
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Wed Dec 12, 2012 8:51 am

No worries, I have written it down but it is at home.

Will do a better write up and explanation when I get home.

The U0 and U1 are supposed to be B0 and B1 (B means Blue) and also remember how I was saying it only needs to draw the rows eight times because it draws multiple rows at a time? Well that's why we have:

Code: Select all

RowA = y.bits(0)
RowB = y.bits(1)
RowC = y.bits(2)
Because with three row bits you have eight combinations so 000 would be to draw the very first row and the ninth row. 001 would be to draw the second row and the tenth row, 111 would be to draw the eighth row and sixteenth row.

Will get back to you though!

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Wed Dec 12, 2012 8:57 am

That's pretty cool, it has a 3 to 8 line decoder in it so you don't have to set every line every time you want to change what it displays.
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Thu Dec 13, 2012 8:34 am

Okay apologies again for being late!

We had our church band Christmas party last night - sorry for not getting back to you.

Anywho, Here is the Pinout:

RED0 GREEN0
BLUE0 GROUND
RED1 GREEN1
BLUE1 GROUND
A B
C GROUND
CLOCK LATCH
O/E GND

Normally you have multiple grounds in order to prevent having to use thick wire. I.E. you could use four thin wires instead of one that is for times as thick. They do this quite often in computer power supplies so that you get more flexibility in the cable going to the motherboard. In our case, I only use one ground (doesn't matter which one) because you also have the thick ground wire going to the power supply.


So, some more thoughts on the code and drawing to the display:

There are two serial data lines for each color and each time you send a clock pulse in, you are clocking through what ever data is present on R0, R1, B0, B1, G0 and G1 (so each clock pulse sends in 6 bits)

R0, B0 and G0 will be displayed on the same line (you choose which line by the A, B and C connections) and then R1, B1 and G1 will be displayed on the same line as each other. These two lines will be separated by eight rows. here's the combinations:

ABC
000 - R0, B0 and G0 will displayed on the first row and R1, B1 and G1 will be displayed on the ninth row
001 - R0, B0 and G0 will displayed on the second row and R1, B1 and G1 will be displayed on the tenth row
010 - R0, B0 and G0 will displayed on the third row and R1, B1 and G1 will be displayed on the eleventh row
011 - R0, B0 and G0 will displayed on the fourth row and R1, B1 and G1 will be displayed on the twelfth row
100 - R0, B0 and G0 will displayed on the fifth row and R1, B1 and G1 will be displayed on the thirteenth row
101 - R0, B0 and G0 will displayed on the sixth row and R1, B1 and G1 will be displayed on the fourteenth row
110 - R0, B0 and G0 will displayed on the seventh row and R1, B1 and G1 will be displayed on the fifteenth row
111 - R0, B0 and G0 will displayed on the eighth row and R1, B1 and G1 will be displayed on the sixteenth row

if you are using two of the 32x16 Matrix displays, then you just have all the identical data lines connected together (I.E. R0 to R0, B0 to B0 etc...) the only difference is that they have a different clock - there's a clock for the first display and a separate clock for the second, that way you can control when they grab the data.

Hope that helps!

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Thu Dec 13, 2012 8:34 am

Okay apologies again for being late!

We had our church band Christmas party last night - sorry for not getting back to you.

Anywho, Here is the Pinout:

RED0 GREEN0
BLUE0 GROUND
RED1 GREEN1
BLUE1 GROUND
A B
C GROUND
CLOCK LATCH
O/E GND

Normally you have multiple grounds in order to prevent having to use thick wire. I.E. you could use four thin wires instead of one that is for times as thick. They do this quite often in computer power supplies so that you get more flexibility in the cable going to the motherboard. In our case, I only use one ground (doesn't matter which one) because you also have the thick ground wire going to the power supply.


So, some more thoughts on the code and drawing to the display:

There are two serial data lines for each color and each time you send a clock pulse in, you are clocking through what ever data is present on R0, R1, B0, B1, G0 and G1 (so each clock pulse sends in 6 bits)

R0, B0 and G0 will be displayed on the same line (you choose which line by the A, B and C connections) and then R1, B1 and G1 will be displayed on the same line as each other. These two lines will be separated by eight rows. here's the combinations:

ABC
000 - R0, B0 and G0 will displayed on the first row and R1, B1 and G1 will be displayed on the ninth row
001 - R0, B0 and G0 will displayed on the second row and R1, B1 and G1 will be displayed on the tenth row
010 - R0, B0 and G0 will displayed on the third row and R1, B1 and G1 will be displayed on the eleventh row
011 - R0, B0 and G0 will displayed on the fourth row and R1, B1 and G1 will be displayed on the twelfth row
100 - R0, B0 and G0 will displayed on the fifth row and R1, B1 and G1 will be displayed on the thirteenth row
101 - R0, B0 and G0 will displayed on the sixth row and R1, B1 and G1 will be displayed on the fourteenth row
110 - R0, B0 and G0 will displayed on the seventh row and R1, B1 and G1 will be displayed on the fifteenth row
111 - R0, B0 and G0 will displayed on the eighth row and R1, B1 and G1 will be displayed on the sixteenth row

if you are using two of the 32x16 Matrix displays, then you just have all the identical data lines connected together (I.E. R0 to R0, B0 to B0 etc...) the only difference is that they have a different clock - there's a clock for the first display and a separate clock for the second, that way you can control when they grab the data.

Hope that helps!

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Thu Dec 13, 2012 10:18 am

Sounds great, I'll have to hook it up soon to test it out (some projects are taking priority over this, mostly those needing to be finished before Christmas.)
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Thu Dec 13, 2012 1:35 pm

Hmm, you could probably PWM the different colors if you hook each color data to a shift register (ideally in parallel, and 2 data outs would be hooked up to each shift register) and then PWM pins to the enable output of each shift registers. It would be kind of hardware wasteful since it would be using 2 of the 8 pins on each shift register, but it would work and if using 2 displays it would be using half the potential of the shift registers and may even reduce the microcontroller pin count.

Would there be a better way to mix the colors?


Example:

B0 and B1 to shift register 1
PWM pin 1 to shift register 1 output enable

R0 and R1 to shift register 2
PWM pin 2 to shift register 2 output enable

G0 and G1 to shift register 3
PWM pin 3 to shift register 3 output enable


Set the PWM rate on each register to determine how bright each color is.
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Thu Dec 13, 2012 4:28 pm

Unfortunately that won't work since you need to shift all your data in (for one row) which means you shift in 32 bits of Red, 32 bits of Green and 32 bits of blue. It's not until all these bits are in there that you then enable the outputs so the data can be shown on the LED's. If you wanted to use PWM to vary the brightness of individual pixels. You would have to send in your 32 bits of red, green and blue. Then enable the outputs to show them, quickly turn them off again, send in the new data and do it all again many many times a second.I.E. if you wanted a red pixel to be at half brightness, you would first let that pixel have a logic 1, then the next time you send the data in, you would make that a logic 0, then the next time it would be a 1 etc...

Otherwise you could pulse the O/E line, but this would just vary the brightness of all pixels.

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Tue Dec 18, 2012 5:36 pm

I finally got around to trying to get the display running but did not have any luck...

If anyone wants to look at the code and tell me what I did wrong, that would be great (note: I have made so all 3 colors and both the color0 and color1 display the same data just to test to see if the matrix works)

if this written code helps:

Code: Select all

sets all matrix pins as outputs

for each of the 8 lines
  for each of the 32 bits:
    set the color data pins to the desired data (note: for testing, all of these are set to the same)
    set clock high then low to change
  end the 32 bits for loop
  set the A B and C pins to the line determined by the  8 lines for loop
end the 8 lines for loop

pulse the Latch pin
pulse the O/E pin HIGH then LOW (with a 1 millisecond delay in between)
the actual arduino code used:

Code: Select all

byte matrixPins[13] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; //r0, r1, g0, g1, b0, b1, A, B, C, clock, latch, O/E

unsigned long matrixData[17] = { 
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
};
void setup(){
  for(byte p = 0; p < 12; p++){ //for each pin
    pinMode(p, OUTPUT); //set as an output so we can control the matrix
  }
}

void loop(){
  for(byte L = 0; L < 8; L++){ //for each Line of data 
    
    for(byte d = 0; d < 32; d++){ //for each data bit
      for(byte c = 0; c < 6; c++){ //for each color (I am setting them all to the same data) (sets both color0 and color1 to the same data)
        digitalWrite(matrixPins[c], bitRead(matrixData[L], d)); //sets the red green and blue data (all the same)      set all the pins to the data of the correct line, L, and the corect bit, d
      }
      digitalWrite(matrixPins[9], 1); //pulse the clock pin to go to the next bit
      digitalWrite(matrixPins[9], 0);
    }//after all 32 bits of data are set
    digitalWrite(matrixPins[6], bitRead(L, 0));
    digitalWrite(matrixPins[7], bitRead(L, 1));   //set the row selector pins to the right row (A, B, and C)
    digitalWrite(matrixPins[8], bitRead(L, 2));
  }
    digitalWrite(matrixPins[10], 1); //pulse the latch pin to display the data
    digitalWrite(matrixPins[10], 0);
    digitalWrite(matrixPins[11], 1); //pulse the O/E pin to display the data
    delay(1);
    digitalWrite(matrixPins[11], 0);
  
}
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Wed Dec 19, 2012 11:57 am

I'll run it up on my PICnDuino and see how I go with getting it working for you.

It might take me a couple of days though as we are going south for some water sports fun!

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Wed Dec 19, 2012 2:43 pm

I'm in no rush, thanks Brad.
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Thu Dec 20, 2012 9:18 am

Okay, no worries :)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Thu Dec 27, 2012 9:04 pm

I was looking into this for you and have found exactly what you need - all pin configurations and even source code so you can draw graphics text and even cool plasma effects on your matrix.

I have yet to get it going myself simply because I always seem to have problems with the arduino software whenever I need to include header files. I do everything I am supposed to and I always get compilation errors.

Anyway, check it out and get back to me about how it goes for you:
http://www.ladyada.net/products/rgbledmatrix/

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Thu Jan 17, 2013 10:56 pm

Thanks a lot for the post Brad! Just got time to look at it, and apparently I put all the pins on the wrong side (no wonder it didn't work!) Anyway, I'll continue to look into it in my spare time, although I have some other projects I need to get finished soon.
Joshua

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 3 guests