Pd OSC ints > Processing > Arduino > shif


hi peeps,

as first ever forum post find myself begging help. i'm not of coder , somehow have talked myself creating project takes sound data pd , passes on tcp ip processing sketch , arduino. idea influence led colours through sound , pass led's through old school video feedback loop in immersion dome.

i'm using osc external pd , getting data processing fine following code:

import oscp5.*;
import netp5.*;
import processing.serial.*;

oscp5 oscp5;
netaddress myremotelocation;
int pitchint;
serial myport;

void setup() {
oscp5 = new oscp5(this,9997);
println(serial.list());
myport = new serial(this, serial.list()[0], 115200);
myremotelocation = new netaddress("127.0.0.1",9997);
}

void draw(){
 try {
 myport.write(pitchint);
 int ardcallback = myport.read();
 println(ardcallback);
} catch (exception e) {
 //do want handle exception
 println("unable parse int");
}
}


/* incoming osc message forwarded oscevent method. */
void oscevent(oscmessage theoscmessage) {
 pitchint = theoscmessage.get(0).intvalue();
}



i'm trying write values on serial arduino using premade shiftbrite sketch i've found online:

/* ports , pins

direct port access faster digitalwrite.
must match correct port , pin shown in table below.

arduino pin        port        pin
13 (sck)           portb       5
12 (miso)          portb       4
11 (mosi)          portb       3
10 (ss)            portb       2
9                  portb       1
8                  portb       0
7                  portd       7
6                  portd       6
5                  portd       5
4                  portd       4
3                  portd       3
2                  portd       2
1 (tx)             portd       1
0 (rx)             portd       0
a5 (analog)        portc       5
a4 (analog)        portc       4
a3 (analog)        portc       3
a2 (analog)        portc       2
a1 (analog)        portc       1
a0 (analog)        portc       0

*/

// defines use arduino functions
#define clockpin   13 // cl
#define enablepin  10 // bl
#define latchpin    9 // xl
#define datapin    11 // si

// defines direct port access
#define clkport portb
#define enaport portb
#define latport portb
#define datport portb
#define clkpin  5
#define enapin  2
#define latpin  1
#define datpin  3

// variables communication
unsigned long sb_commandpacket;
int sb_commandmode;
int sb_bluecommand;
int sb_redcommand;
int sb_greencommand;

// define number of shiftbrite modules
#define numleds 1

// create led value storage array
int ledchannels[numleds][3] = {0};

// set pins outputs , initial states
void setup() {
 serial.begin(115200);
 pinmode(datapin, output);
 pinmode(latchpin, output);
 pinmode(enablepin, output);
 pinmode(clockpin, output);
 digitalwrite(latchpin, low);
 digitalwrite(enablepin, low);
 spcr = (1<<spe)|(1<<mstr)|(0<<spr1)|(0<<spr0);
}

// load values spi register
void sb_sendpacket() {

   if (sb_commandmode == b01) {
    sb_redcommand = 127;
    sb_greencommand = 110;
    sb_bluecommand = 110;
   }

   spdr = sb_commandmode << 6 | sb_bluecommand>>4;
   while(!(spsr & (1<<spif)));
   spdr = sb_bluecommand<<4 | sb_redcommand>>6;
   while(!(spsr & (1<<spif)));
   spdr = sb_redcommand << 2 | sb_greencommand>>8;
   while(!(spsr & (1<<spif)));
   spdr = sb_greencommand;
   while(!(spsr & (1<<spif)));

}

// latch values pwm registers
void sb_latch() {

 delaymicroseconds(1);
 latport += (1 << latpin);
 //enaport += (1 << enapin);
 delaymicroseconds(1);
 //enaport &= ~(1 << enapin);
 latport &= ~(1 << latpin);

}

// send array values chain
void writeledarray() {

 sb_commandmode = b00; // write pwm control registers

 for (int = 0; i<numleds; i++) {
   sb_redcommand = ledchannels
  • & 1023;
       sb_greencommand = ledchannels[1] & 1023;
       sb_bluecommand = ledchannels[2] & 1023;
       sb_sendpacket();
     }

     sb_latch();

     sb_commandmode = b01; // write current control registers

     for (int z = 0; z < numleds; z++) sb_sendpacket();  

     sb_latch();

    }

    // fade between 2 colors @ specified interval
    void fadeall(int rate, int fromred, int fromgreen, int fromblue, int tored, int togreen, int toblue) {

    (int = 0; < 33; i++) {

        (int j1 = 0; j1 < numleds; j1++) {
          ledchannels[j1][0] = (fromred * (32 - i) + tored * i)/32;
          ledchannels[j1][1] = (fromgreen * (32 - i) + togreen * i)/32;
          ledchannels[j1][2] = (fromblue * (32 - i) + toblue * i)/32;
        }

       writeledarray();
       delay(rate);

      }  
    }

    void loop() {
    while (serial.available() > 0) {
     int inbyte = serial.read();
     serial.write(inbyte);
     inbyte = inbyte *5;
     if (inbyte > 0){
       fadeall(60,0,500,0,0,0,1023);
       delay(inbyte);
       fadeall(60,0,0,1023,0,0,0);  
       delay(inbyte);
     }
     else {
       
     }
    }
    }




    due nature of setup i'm finding hard debug serial port being used constantly. processing sketch printing port having process on arduino , re-write port , print processing :s

    can identify silly mistakes making?

    any appreciated :)


    nick


quote
can identify silly mistakes making?

besides not telling problem(s) having, if any?

quote
due nature of setup i'm finding hard debug serial port being used constantly. processing sketch printing port having process on arduino , re-write port , print processing :s

but, works.

you lcd attach arduino, , write debug data there...

you avoid issues debugging breaking programming smaller pieces. processing , arduino send data , forth reliably. then, extend arduino sketch data. then, extend processing sketch send meaningful data.

extend 1 sketch @ time. then, issues new code...


Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > Pd OSC ints > Processing > Arduino > shif


arduino

Comments