Good afternoon everyone,
I'm currently working on a project for school and trying to build and program a 5v5v5 LED Cube.
I already soldered the Cube itself together and designed a circuit board for my shiftregistern and stuff...
I believe I could run my with shiftOut() too but I wanted to learn and understand as much as possible because I'm probably wanna make similar projects later again.
After some research I found out that there is the SPI library which should be exspecially good for my project due to its speed. Unfortunatly I have trouble fitting the SPI in my test projects. (I built up an LED line controlled with an 74hc595 and ULN2803 which I also wanna use in my final project)
I'm using an Arduino Micro to control everything.
Howewer I only used 3 Pins with shiftOut() and it worked fine for me - and left out Output Enable (SCK)
I also tried it with all 4 pins but didn't get the results i was looking for...
To give you an idea here is the simplest version of my testing code:
Hi, don't try to use port manipulation, use digitalWrite(). When you can make it work with digitalWrite() then if it still too slow you can try to use port manipulation. But I believe you will find that it is very fast with digitalWrite().
I find digitalWrite() too slow.
When I want fast I do this:
PORTB = PORTB & 0b11111011; // clear D10 on Uno
SPI.transfer(bits0to7);
SPI.transfer(bits8to15);
SPI.transfer(bits16to23);
SPI.transfer(bits24to31); // only need 1 here for 25 total
PORTB = PORTB | 0b00000100; // set D10 on Uno
No loops, just the 4 SPI transfers to send out the column info for example, then turn on a layer driver.
Also, your code is little messed up, see the notes I added below
[color=#222222]#include <SPI.h>[/color][color=#222222][/color]
[color=#222222][/color]
[color=#222222]#define speicherPin 5 [/color]// library also sets up D10 as an output so device can be SPI master - might as well use for data latch (RCLK on '595)[color=#222222][/color]
[color=#222222]// #define datenPin 11 // not needed SPI library sets this up - this is MOSI, goes to Serial In[/color][color=#222222][/color]
[color=#222222]// #define taktPin 13 [/color][color=#222222] // not needed SPI library sets this up - this is SCK, goes to SRCLK[/color][color=#222222][/color]
[color=#222222]// #define blank_pin 12 [/color][color=#222222]// not needed SPI library sets this up - this is MISO, not used for xfer to '595[/color]
[color=#222222][/color]
[color=#222222]byte shiftZahl=0;[/color][color=#222222][/color]
[color=#222222]long data;[/color][color=#222222][/color]
[color=#222222][/color]
[color=#222222]void setup()[/color][color=#222222][/color]
[color=#222222]{[/color][color=#222222][/color]
[color=#222222] SPI.setBitOrder(MSBFIRST); // move this after SPI.begin(), also this is a default, so not needed[/color][color=#222222][/color]
[color=#222222] SPI.setDataMode(SPI_MODE0);[/color][color=#222222]// move this after SPI.begin()[/color][color=#222222], also this is a default, so not needed[/color][color=#222222][/color]
[color=#222222] SPI.setClockDivider(SPI_CLOCK_DIV2);[/color][color=#222222]// move this after SPI.begin()[/color][color=#222222][/color]
[color=#222222] [/color][color=#222222][/color]
[color=#222222] // pinMode(taktPin,OUTPUT); [/color][color=#222222]// not needed SPI library sets this up[/color][color=#222222][/color]
[color=#222222] pinMode(speicherPin,OUTPUT); [/color][color=#222222][/color]
[color=#222222] // pinMode(datenPin,OUTPUT); [/color][color=#222222]// not needed SPI library sets this up[/color][color=#222222][/color]
[color=#222222] // pinMode(blank_pin, OUTPUT); [/color][color=#222222]// not needed SPI library sets this up[/color][color=#222222][/color]
[color=#222222] SPI.begin();[/color][color=#222222][/color]
[color=#222222]}[/color][color=#222222][/color]
[color=#222222][/color]
[color=#222222]void loop()[/color][color=#222222][/color]
[color=#222222]{[/color][color=#222222][/color]
[color=#222222] shiftZahl = B11111111;[/color][color=#222222][/color]
[color=#222222]// shiftOut(datenPin,taktPin,LSBFIRST,shiftZahl);[/color][color=#222222][/color]
[color=#222222]// digitalWrite(speicherPin,HIGH);[/color][color=#222222][/color]
[color=#222222]// digitalWrite(speicherPin,LOW);[/color][color=#222222][/color]
[color=#222222] [/color][color=#222222][/color]
[color=#222222] PORTD |= 1 << blank_pin; // change to RCLK going low[/color][color=#222222][/color]
[color=#222222] SPI.transfer(shiftZahl); // SPI transfer does 8 bits at a time - need 4 of them here[/color][color=#222222][/color]
[color=#222222] PORTD |= 1 << speicherPin;[/color][color=#222222]// change to RCLK going high[/color][color=#222222][/color]
[color=#222222] PORTD &= ~(1 << speicherPin);[/color][color=#222222]// not needed[/color][color=#222222][/color]
[color=#222222] PORTD &= ~(1 << blank_pin);[/color][color=#222222]// not needed[/color][color=#222222][/color]
[color=#222222]}
thank you very much for your support...
After taking a look on the Arduino pin mapping and shiftregister datasheet again I decided to reconnect the pins the following way:
... and left out the SS pin
However my LEDs stay turned off even after randomly trying some other connections
Did I fail connecting them the right way?
Greetings...
Fix these:
Arduino -----> shiftregister
SCK (13) -----> shift register clock inputs
MOSI (11) -----> serial data input
MISO (12) -----> not used
SS (10) -----> storage register clock input - or pin 5 I think you had?
Then:
digitalWrite (ssPin, LOW);
SPI.transfer(dataByte0); // leave it you to break up your long data type as needed
SPI.transfer(dataByte1);
SPI.transfer(dataByte2);
SPI.transfer(dataByte3);
SPI.transfer(dataByte4);
digitalWrite (ssPin, HIGH);
SRCLR pin to +5
OE (G/) pin to Gnd, or a PWM output for brightness control.
This definitely works. Here are 12 shift registers on a board I offer (only 6 populated here), data is written out the same way, with a '328P providing the Arduino functionality: http://www.crossroadsfencing.com/BobuinoRev17/
Thank you very much, that pin connection worked nicely!
Unfortunatly I totally failed in choosing the right pins first ... obviously on Arduino Micro the pins have the following pin numbers (just for correctness):