Uploading Code to Your Lightshow – Piper

LET'S UPLOAD YOUR CODE TO YOUR LIGHTSHOW

Okay, so let's get your bitmaps working on your lightshows! Now, this is where things might get gnarly, because the drivers (the thing that talks to the lightshow) for the Raspberry Pi and the Arduino Micro are different, meaning the codes are different!

Are you plugging your Lightshow pins into the Arduino Micro? If you're doing the ARDUINO + COMPUTER or ARDUINO + PI setup, click Arduino below.

Are you plugging your Lightshow pins into the Raspberry Pi? If you're doing the PI ALONE setup, click Raspberry Pi below.

ARDUINO



Click OPEN CODE and add to your own sketchbook. Select the Arduino Micro as your device, make sure your command center is plugged in via USB and hit UPLOAD.

Please follow these links to full tutorials on using Arduino Create as well as downloading Arduino IDE.

Remember those sections of code in the earlier page? Copy each of those into the code after byte myImage[] to show each image.

For easy reference here they are again:

Uploading Code to Your Lightshow

Minecraft Zombie

000100,B000100,B000100,B000100,B000100,B000100,B000100,B000100,
B000100,B000100,B000100,B000100,B001000,B001000,B000100,B000100,
B000100,B001000,B001000,B001000,B001000,B001000,B001000,B000100,
B001000,B001000,B001000,B001000,B001000,B001000,B001000,B000100,
B001000,B000000,B000000,B001000,B001000,B000000,B000000,B001000,
B000100,B001000,B001000,B000000,B000000,B001000,B001000,B000100,
B000100,B001000,B000000,B001000,B001000,B000000,B001000,B000100,
B000100,B000100,B000100,B000100,B000100,B000100,B000100,B000100,

Uploading Code to Your Lightshow

Piperbot

B000001,B000001,B000001,B000001,B000001,B000001,B000001,B000001,
B000001,B011101,B011101,B011101,B011101,B011101,B011101,B000001,
B000001,B011101,B111111,B011101,B011101,B111111,B011101,B000001,
B000001,B011101,B000000,B011101,B011101,B000000,B011101,B000001,
B000001,B011101,B111111,B011101,B011101,B111111,B011101,B000001,
B000001,B011101,B011101,B011101,B011101,B011101,B011101,B000001,
B000001,B011101,B011101,B000000,B000000,B011101,B011101,B000001,
B000001,B000001,B000001,B000001,B000001,B000001,B000001,B000001,

Uploading Code to Your Lightshow

Pip the Mouse

B110100,B110100,B110100,B000000,B000000,B110100,B110100,B110100,
B110100,B010000,B110100,B000000,B000000,B110100,B010000,B110100,
B110100,B110100,B110100,B110100,B110100,B110100,B110100,B110100,
B000000,B110100,B111111,B110100,B110100,B111111,B110100,B000000,
B000000,B110100,B000000,B110100,B110100,B000000,B110100,B000000,
B110100,B110100,B110100,B010000,B010000,B110100,B110100,B110100,
B000000,B110100,B110100,B110100,B110100,B110100,B110100,B000000,
B110100,B110100,B110100,B110100,B110100,B110100,B110100,B110100,

RASPBERRY PI

To get started after wiring up your Raspberry Pi, first exit Piper and get to the desktop. After this you'll use CHROMIIUM to download your code and TERMINAL to run it.

Click the POWER icon in the top left

Uploading Code to Your Lightshow

Click EXIT TO DESKTOP

Click the CHROMIUM icon to open your browser

Click the TERMINAL icon to open your command line

THE EASIEST WAY TO UPLOAD YOUR CODE

Click on these icons to download different code files (written in C) to your Pi:

Code a Simple Heart

Uploading Code to Your Lightshow

Code a Beating Heart

Uploading Code to Your Lightshow

Code a Zombie Face

Uploading Code to Your Lightshow

Code Piperbot's Face

Uploading Code to Your Lightshow

Let's walk through how to clone the folder from your terminal. Open terminal (that black coding icon in the top bar) and type the following:

git clone git://github.com/buildwithpiper/LightShow-raspberry-pi.git

cd lightshow-raspberry-pi

make

Note: Make sure you have the URL and a working internet connection.

./matrix

Note: Make sure you replace "matrix" with whichever file you're running -- i.e. "piperbot"

Press Ctrl+C to stop running a program, so you can start another

COPY IN YOUR OWN CODE

Open terminal and create a new file (name it according it to which file you would like to copy in.  

nano matrix.c

matrix.c

#include <stdio.h>         
#include <stdio.h>
#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdint.h>

#define RED_DATA 0          //define the red data source 
#define BLUE_DATA 1         //define the blue data source
#define GREEN_DATA 2    // define the green data source 

int main(void)
{
static uint8_t data[4] = {0x0,0x0,0x0,0x0}; // initialize RGB data source static uint8_t i = 0; wiringPiSetup(); // initialize wiringPi wiringPiSPISetup(0,500000); // initialize SPI information, 0 is channel 0, 500000 is clock rate. while(1){ int j; int x = 2; static uint8_t heart[8] =
{
0b00000000,
0b01100110,
0b11111111,
0b11111111,
0b11111111,
0b01111110,
0b00111100,
0b00011000
}; // this is a array of heart
for ( j=0;j<8;j++) { data[0] = ~heart[j]; data[2] = 0xFF; data[1] = 0xFF; data[3] = 0x01 << j ; wiringPiSPIDataRW(0,data,sizeof(data)); // send data to SPI channel 0, and the length of the data delay(x); } } }

heart.c

#How_to_use_it
#include <stdio.h>
#include <stdio.h>
#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdint.h>

#define RED_DATA 0 //define the red data source
#define BLUE_DATA 1 //define the blue data source
#define GREEN_DATA 2 // define the green data source

int main(void)
{
static uint8_t data[4] = {0x0, 0x0, 0x0, 0x0}; // initialize RGB data source

wiringPiSetup(); // initialize wiringPi
wiringPiSPISetup(0, 500000); // initialize SPI information, 0 is channel 0, 500000 is clock rate.
while (1)
{
int j;
int x = 2;
static uint8_t heart[8] =
{
0b00000000,
0b01100110,
0b11111111,
0b11111111,
0b11111111,
0b01111110,
0b00111100,
0b00011000}; // this is a array of heart
for (j = 0; j < 8; j++)
{
data[0] = ~heart[j];
data[2] = 0xFF;
data[1] = 0xFF;
data[3] = 0x01 << j;
wiringPiSPIDataRW(0, data, sizeof(data)); // send data to SPI channel 0, and the length of the data
delay(x);
}
}
}

heartbeat.c

#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdint.h>

#define RED_DATA 0
#define BLUE_DATA 1
#define GREEN_DATA 2

int j;
int x = 2;

static uint8_t data[4] = {0x0, 0x0, 0x0, 0x0};

void heartbig()
{
static uint8_t heart[8] = {0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18};
for (j = 0; j < 8; j++)
{
data[0] = ~heart[j];
data[2] = 0xFF;
data[1] = 0xFF;
data[3] = 0x01 << j;
wiringPiSPIDataRW(0, data, sizeof(data));
delay(x);
}
}

void heartsmall()
{
static uint8_t heart[8] = {0x00, 0x00, 0x24, 0x7E, 0x7E, 0x3C, 0x18, 0x00};
for (j = 0; j < 8; j++)
{
data[0] = ~heart[j];
data[2] = 0xFF;
data[1] = 0xFF;
data[3] = 0x01 << j;
wiringPiSPIDataRW(0, data, sizeof(data));
delay(x);
}
}

void matrixoff()
{
static uint8_t heart[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
for (j = 0; j < 8; j++)
{
data[0] = ~heart[j];
data[2] = 0xFF;
data[1] = 0xFF;
data[3] = 0x01 << j;
wiringPiSPIDataRW(0, data, sizeof(data));
delay(x);
}
}

int main(void)
{
wiringPiSetup();
wiringPiSPISetup(0, 500000);

while (1)
{
int m = 10;
for (m = 10; m > 0; m--)
{
heartbig();
};
matrixoff();
delay(100);
for (m = 10; m > 0; m--)
{
heartsmall();
};
matrixoff();
delay(100);
}
}

zombie.c

#include <stdio.h>         
#include <stdio.h>
#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdint.h>

#define RED_DATA 0          //define the red data source 
#define BLUE_DATA 1         //define the blue data source
#define GREEN_DATA 2    // define the green data source 

int main(void)
{
static uint8_t data[4] = {0x0,0x0,0x0,0x0};                  // initialize RGB data source 
static uint8_t i = 0;                                                       

wiringPiSetup();                                // initialize wiringPi 
wiringPiSPISetup(0,500000);           // initialize SPI  information, 0 is channel 0, 500000 is clock rate.
while(1){                         
int j;
int x = 2;
static uint8_t zombie[8] = 
{
0b11111111,
0b11111111,
0b11111111,
0b11111111,
0b10011001,
0b11100111,
0b11011011,
0b11111111
}; // this is a array of zombie face for ( j=0;j<8;j++) { data[0] = 0xFF;
data[2] = ~zombie[j];
data[1] = 0xFF;
data[3] = 0x01 << j ; wiringPiSPIDataRW(0,data,sizeof(data)); // send data to SPI channel 0, and the length of the data delay(x);
} } }

piperbot.c

#include <stdio.h>         
#include <stdio.h>
#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdint.h>

#define RED_DATA 0          //define the red data source 
#define BLUE_DATA 1         //define the blue data source
#define GREEN_DATA 2    // define the green data source 

int main(void)
{
static uint8_t data[4] = {0x0,0x0,0x0,0x0};                  // initialize RGB data source 
static uint8_t i = 0;                                                       

wiringPiSetup();                                // initialize wiringPi 
wiringPiSPISetup(0,500000);           // initialize SPI  information, 0 is channel 0, 500000 is clock rate.
while(1){                         
    int j;
    int x = 2;
static uint8_t piperbot[8] = 
{
0b11111111,
0b10000001,
0b10100101,
0b10000001,
0b10100101,
0b10000001,
0b10011101,
0b11111111
}; // this is a array of piperbots face for ( j=0;j<8;j++) { data[0] = 0xFF; data[2] = 0x00; data[1] = ~piperbot[j]; data[3] = 0x01 << j ; wiringPiSPIDataRW(0,data,sizeof(data)); // send data to SPI channel 0, and the length of the data delay(x); } } }
for (j=0;j<8;j++)
{
data[0] = 0xFF;
data[2] = 0x00;
data[1] = ~piperbot[j];
data[3] = 0x01 << j ;
wiringPiSPIDataRW(0,data,sizeof(data)); // send data to SPI channel 0, and the length of the data
delay(x);
}
}
}

After you've copied in your text (right-click and hit paste text), then click CTRL + X and then Y to save. Then hit ENTER.

After that, type this into command line:

sudo gcc -o matrix matrix.c -lwiringPi

Note: Make sure you replace "matrix" with whichever file you're running -- i.e. "piperbot"

sudo ./matrix

Note: Make sure you replace "matrix" with whichever file you're running -- i.e. "piperbot"

Note: Here's precise guidance on coding the LED board you have: https://wiki.52pi.com/index.php/RPI-RGB-LED-Matrix_SKU:EP-0043#How_to_use_it

Light it up and play around to see what you can create! When you make something cool, be sure to share it with us using the handle @startwithpiper.com