Close

Processing on the Pi – RS485

A project log for Networked Low Resolution DMD Projectors

WiFi networked electro-mechanical 7x7 pixel flip-dot displays as giant DMDs (Digital Micromirror Devices) for low resolution projection

michael-shaubMichael Shaub 02/24/2016 at 03:270 Comments

Date: 2/19/2016

For the project to work I had to get the Raspberry Pi to do the same thing the Arduino. The LinkSprite shield does work with the Raspberry Pi V2 (and I'm assuming other models with 40 pin GPIO pins) even though it only has 26 pins. Just align the 1st pin of each and leave the other 14 unused.

(insert link to GPIO serial settings)

Once I'd opened up the serial connection to be available for Processing I just copied and pasted the code from the Arduino IDE to Processing. The Arduino Serial.begin(57600); becomes myPort = new Serial(this, Serial.list()[0], 57600); to select the first (only) serial port available. To send a command, instead of Serial.write( message ); Processing will need it to be myPort.write( message );

Below is my working Processing code, using the LinkSprite shield.

// Serial example by Tom Igoe
//
// Adapted for LinkSprite V3 and AlfaZeta flip-dot display
// by Michael Shaub 2016

import processing.serial.*;

// The serial port:
Serial myPort;       

int delay_tr = 1000;

byte test_allWhite[]= {byte(0x80), byte(0x87), byte(0xFF), byte(0x7F), byte(0x7F), byte(0x7F), byte(0x7F), byte(0x7F), byte(0x7F), byte(0x7F), byte(0x8F)};
byte test_allBlack[]= {byte(0x80), byte(0x87), byte(0xFF), byte(0x00), byte(0x00), byte(0x00), byte(0x00), byte(0x00), byte(0x00), byte(0x00), byte(0x8F)};
  
int frameDelay = 50; //pause 400 ms between frames being sent to the board
int counter = 0;
int rowCounter = 0;
int row1 = 0; //hold variable for row1
int row2 = 0; //hold variable for row2
int row3 = 0; //hold variable for row3
int row4 = 0; //hold variable for row4
int row5 = 0; //hold variable for row5
int row6 = 0; //hold variable for row6
int row7 = 0; //hold variable for row7
int rowArray[ ] = {0,0,0,0,0,0,0};

void setup(){
// List all the available serial ports:
printArray(Serial.list());

// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[0], 57600);
  
// Send a capital A out the serial port:
//myPort.write(65);
}

void draw(){
  //count rows and frames
  if(counter > 7){
    counter = 0;
    rowCounter++;
  }
  if(rowCounter > 7) rowCounter = 0;
  
  for(int j=0; j<7; j++){ //set values to match counter, should flip dots one by one across
    if(j == counter){
      rowArray[j] = 1; //set to 1
    }else{
      rowArray[j] = 0; //reset value to 0
    }
  }
  
  //bitshift values from array
  row1 = 0;
  row2 = 0;
  row3 = 0;
  row4 = 0;
  row5 = 0;
  row6 = 0;
  row7 = 0;
  for(int i=0; i<rowArray.length; i++){
    int a = rowArray[i];
    int b = a << i; //bitshift the value the number of positions equal to the digit
    switch(rowCounter){
    case 1:
      row1 = row1 | b; //bitwise OR addition of the "b" value to the existing "row3" value
      break;
    case 2:
      row2 = row2 | b; //bitwise OR addition of the "b" value to the existing "row3" value
      break;
    case 3:
      row3 = row3 | b; //bitwise OR addition of the "b" value to the existing "row3" value
      break;
    case 4:
      row4 = row4 | b; //bitwise OR addition of the "b" value to the existing "row3" value
      break;
    case 5:
      row5 = row5 | b; //bitwise OR addition of the "b" value to the existing "row3" value
      break;
    case 6:
      row6 = row6 | b; //bitwise OR addition of the "b" value to the existing "row3" value
      break;
    case 7:
      row7 = row7 | b; //bitwise OR addition of the "b" value to the existing "row3" value
      break;
    }
  }
  
  int test_2[]= {0x80, 0x87, 0xFF, row1, row2, row3, row4, row5, row6, row7, 0x8F};
  //int test_2[]= {0x80, 0x87, 0xFF, 0, counter, 0, 0, 0, 0, 0, 0x8F};
  
  for(int i=0; i<test_2.length; i++){
    myPort.write(test_2[i]); 
  }
  //myPort.write(60);
  //println("Dark");
  counter++;
  
  delay (frameDelay);

}

Discussions