Introduction: Use 8x8x8 RGB LED Cube on PcDuino

Picture of Use 8x8x8 RGB LED Cube on PcDuino

8x8x8 RGB LED cube is one of the stunning RGB LED Cube designed  by LinkSprite. It has Arduino compatible interface and uses the SPI interface to communicate with Arduino/pcDuino.

Step 1: Wiring Diagram

Picture of Wiring Diagram

The 8x8x8 LED Cube can be directly installed on pcDuino. However, we do recommend to use a T Board to translate the voltage.

Step 2: Test Code

#include <SPI.h>

#define STATUS_PIN 9
#define CS_PIN 10
#define MOSI_PIN 12
#define MISO_PIN 11
#define SCK_PIN 13

#define SPI_MODE SPI_MODE1

#ifdef PCDUINO_IDE
   #define SpiExchangeByte(x) SPI.transfer(x,SPI_CONTINUE)
#else
  #define SpiExchangeByte(x) SPI.transfer(x)
#endif

void SetDefaultTask(char task,long repeatTime)
{
  bool DeviceStatus;
  unsigned short count;

  DeviceStatus = digitalRead(STATUS_PIN);
  digitalWrite(CS_PIN,LOW);

   SpiExchangeByte(2);
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(task);//X
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//Y
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//Z
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(repeatTime & 0xff);//R
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((repeatTime>>8) & 0xff);//G
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((repeatTime>>16) & 0xff);//B
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((repeatTime>>24) & 0xff);//RSV
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   digitalWrite(CS_PIN,HIGH);
}

void SetLedCubeColor(long color)
{
  bool DeviceStatus;
  unsigned short count;

  DeviceStatus = digitalRead(STATUS_PIN);
  digitalWrite(CS_PIN,LOW);

   SpiExchangeByte(1);
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//X
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//Y
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//Z
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(color & 0xff);//R
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((color>>8) & 0xff);//G
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((color>>16) & 0xff);//B
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((color>>24) & 0xff);//RSV
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   digitalWrite(CS_PIN,HIGH);
}

void SetPonitColor(char x,char y,char z,long color)
{
  bool DeviceStatus;
  unsigned short count;

  DeviceStatus = digitalRead(STATUS_PIN);
  digitalWrite(CS_PIN,LOW);

   SpiExchangeByte(3);
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(x);//X
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(y);//Y
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(z);//Z
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(color & 0xff);//R
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((color>>8) & 0xff);//G
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((color>>16) & 0xff);//B
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte((color>>24) & 0xff);//RSV
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   digitalWrite(CS_PIN,HIGH);
}

void SendImageData(void)
{
  unsigned short tmpShort;

  bool DeviceStatus;
  unsigned short count;

  DeviceStatus = digitalRead(STATUS_PIN);
  digitalWrite(CS_PIN,LOW);

   SpiExchangeByte(4);
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//X
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//Y
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//Z
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//R
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//G
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//B
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
   SpiExchangeByte(0);//RSV
   while(digitalRead(STATUS_PIN) == DeviceStatus);
   DeviceStatus = !DeviceStatus;
  for(tmpShort =0;tmpShort < 512*3;tmpShort ++)
  {
    SpiExchangeByte((char)tmpShort);
    while(digitalRead(STATUS_PIN) == DeviceStatus);
    DeviceStatus = !DeviceStatus;
  }
  digitalWrite(CS_PIN,HIGH);
}

void setup() {
  // put your setup code here, to run once:
  pinMode(STATUS_PIN, INPUT);
  pinMode(CS_PIN, OUTPUT);
  pinMode(MOSI_PIN, OUTPUT);
  pinMode(MISO_PIN, INPUT);
  pinMode(SCK_PIN, OUTPUT);
  digitalWrite(CS_PIN,HIGH);
  digitalWrite(STATUS_PIN,HIGH);
  digitalWrite(SCK_PIN,LOW);

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE);
  SPI.setClockDivider(SPI_CLOCK_DIV4);
  SetDefaultTask(0,15);
  SetLedCubeColor(0x00000000);
  SendImageData();
  delay(5000);
}

void loop() {
  // put your main code here, to run repeatedly:
  printf("SetLedCubeColor(R);\n");
  SetLedCubeColor(0x00ff0000);
  delay(1000);
  printf("SetLedCubeColor(G);\n");
  SetLedCubeColor(0x0000ff00);
  delay(1000);
  printf("SetLedCubeColor(B);\n");
  SetLedCubeColor(0x000000ff);
  delay(1000);
  printf("SetDefaultTask(1);\n");
  SetDefaultTask(1,20);
  delay(5000);
  printf("SetDefaultTask(2);\n");
  SetDefaultTask(2,15);
  delay(5000);
  printf("SetDefaultTask(3);\n");
   SetDefaultTask(3,15);
  delay(5000);

}

Step 3: Description Command

Picture of Description Command

8x8x8 RGB LED cube supports  four kinds of commands. The format of the commands is below: [cmd] [x] [y] [z] [r] [g] [b] [rsv]

In the command sequence:

cmd is the command byte.

x, y, z, represents the three axis coordinate values.

r, g, b represents the three color of red, blue, green value of  corresponding coordinate , rsv is a reserved char.

Command 0×01: Set the whole LED cube into a certain color. X/Y/Z is invalid.

Command 0×02: Set a demo mode, X means demo mode X. Y and Z are invalid. t/h/b/rsv means the repeat number. There are currently three demo mode.

Command 0×03:  Set the color of a certain LED.  x, y, z is the coordinate. r, g, b is the color.

Command 0×04:  Send the data starting from (0,0,0).  x, y, z, r, g, b, rsv are invalid.  The data after the command is the data of color.

Step 4: Test Result

Picture of Test Result

8x8x8 RGB LED Cube on pcDuino is very beautiful!

Comments

Yonatan24 (author)2015-11-20

Hi, I've added your project to the "A Collection of WAAAY To Many 8X8X8 RGB LED Cubes!" Collection

This is the link If you are interested:

https://www.instructables.com/id/A-Collection-of-WA...

SuperTech-IT made it! (author)2014-08-18

If you'd like something larger with more options, visit here:

https://www.instructables.com/id/8X8X8-RGB-LED-Cube/

About This Instructable

7,346views

31favorites

License:

More by Yanny Guo:Use pcDuino as Photo Booth ControllerUse Si4703 FM Breakout Board on Arduino UnoUse SIM900 GPRS/GSM Shield on pcDuino
Add instructable to: