Pages: [1]   Go Down
Author Topic: Multi Stepper OSC controlled Bird boxes  (Read 1211 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello
Just wanted to write about a little project I recently completed for a pop-up outdoor garden space we have set up here in liverpool. The devices comprise of 4 wooden birdboxes equipped with speakers, stepper motors and LEDs. The devices are controlled through an Arduino Mega running the AccelStepper library and an ethernet shield. The stepper positions and led brightness is sequnced live using OSC over an ethernet shield using the wonderful ArdOSC library, the advantage being that we were able to talk to the birdboxes directly out of Ableton Live and easily address all the different parameters as well as use touchOSC for realtime control. The whole system is synced live using Ableton.


a short video of them in action:









below is the code used for the motors:

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <ArdOSC.h>
#include <AccelStepper.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[]  = { 192, 168, 1, 100 };
int serverPort  = 10000;
int destPort=12000;
// int ledPin =  12;

int flag=0;

OSCServer server;
OSCClient client;
AccelStepper stepper1(4,2,3,56,5);
AccelStepper stepper2(4,6,7,8,9);
AccelStepper stepper3(4,12,13,54,55);
AccelStepper stepper4(4,14,15,16,17);
AccelStepper stepper5(4,18,19,20,21);
AccelStepper stepper6(4,22,23,24,25);
AccelStepper stepper7(4,26,27,28,29);
// initialize the stepper library on pins 8 through 11:


long val1 = 0;
long val2 = 0;
long val3 = 0;
long val4 = 0;
long val5 = 0;
long val6 = 0;
long val7 = 0;



void setup(){
  
 Serial.begin(9600);
 
 Ethernet.begin(myMac ,myIp);
 server.begin(serverPort);
 
 //set callback function & oscaddress
 server.addCallback("/1/fader1",&func1);
 server.addCallback("/1/fader2",&func2);
  server.addCallback("/1/fader3",&func3);
   server.addCallback("/1/fader4",&func4);
    server.addCallback("/1/fader5",&func5);
     server.addCallback("/1/fader6",&func6);
      server.addCallback("/1/fader7",&func7);
 
 // pinMode(ledPin, OUTPUT);  
 // stepper.setSpeed(50);
 stepper1.setMaxSpeed(100.0);
 stepper1.setAcceleration(50.0);
 stepper2.setMaxSpeed(150.0);
 stepper2.setAcceleration(100.0);
  stepper3.setMaxSpeed(200.0);
 stepper3.setAcceleration(150.0);
  stepper4.setMaxSpeed(250.0);
 stepper4.setAcceleration(200.0);
  stepper5.setMaxSpeed(300.0);
 stepper5.setAcceleration(250.0);
  stepper6.setMaxSpeed(350.0);
 stepper6.setAcceleration(300.0);
  stepper7.setMaxSpeed(400.0);
 stepper7.setAcceleration(350.0);
 
}
  
void loop(){
  
  if(server.aviableCheck()>0){
 //    Serial.println("alive! ");
  }
  stepper1.moveTo(val1);
  stepper1.run();
  stepper2.moveTo(val2);
  stepper2.run();
   stepper3.moveTo(val3);
  stepper3.run();
   stepper4.moveTo(val4);
  stepper4.run();
   stepper5.moveTo(val5);
  stepper5.run();
   stepper6.moveTo(val6);
  stepper6.run();
   stepper7.moveTo(val7);
  stepper7.run();
  
  pinMode(54, OUTPUT);
  pinMode(55, OUTPUT);
  pinMode(56, OUTPUT);
  pinMode(57, OUTPUT);
  
}


void func1(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val1 = (long)(value*200);
  Serial.println(val1);
}

void func2(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val2 = (long)(value*200);
  Serial.println(val2);
}

void func3(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val3 = (long)(value*200);
  Serial.println(val3);
}

void func4(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val4 = (long)(value*200);
  Serial.println(val4);
}

void func5(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val5 = (long)(value*200);
  Serial.println(val5);
}

void func6(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val6 = (long)(value*200);
  Serial.println(val6);
}

void func7(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val7 = (long)(value*200);
  Serial.println(val7);
}


code used for controlling LED's

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <ArdOSC.h>


byte myMac[] = { 0xDA, 0xFE, 0xBA, 0xEE, 0xEF, 0xDE };
byte myIp[]  = { 192, 168, 1, 200 };
int serverPort  = 9000;
int destPort=12000;
// int ledPin =  12;

//int flag=0;

OSCServer server;
OSCClient client;
int led1 = 3;
int led2 = 5;
int led3 = 6;
int led4 = 9;
int led5 = 10;
int led6 = 14;


// initialize the stepper library on pins 8 through 11:


long val1 = 0;
long val2 = 0;
long val3 = 0;
long val4 = 0;
long val5 = 0;
long val6 = 0;




void setup(){
  
 Serial.begin(9600);
 
 Ethernet.begin(myMac ,myIp);
 server.begin(serverPort);
 
 //set callback function & oscaddress
 server.addCallback("/1/light1",&func1);
 server.addCallback("/1/light2",&func2);
  server.addCallback("/1/light3",&func3);
   server.addCallback("/1/light4",&func4);
    server.addCallback("/1/light5",&func5);
     server.addCallback("/1/light6",&func6);
 
 pinMode(led6, OUTPUT);    
 
 // pinMode(ledPin, OUTPUT);  
 // stepper.setSpeed(50);

 
}
  
void loop(){
  
  if(server.aviableCheck()>0){
 //    Serial.println("alive! ");
  }
  analogWrite(led1, val1);
  analogWrite(led2, val2);
  analogWrite(led3, val3);
  analogWrite(led4, val4);
  analogWrite(led5, val5);
  analogWrite(led6, val6);

  
}


void func1(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val1 = (long)(value*255);
  //Serial.println(val1);
}

void func2(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val2 = (long)(value*255);
  //Serial.println(val2);
}

void func3(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val3 = (long)(value*255);
  //Serial.println(val3);
}

void func4(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val4 = (long)(value*255);
  //Serial.println(val4);
}

void func5(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val5 = (long)(value*255);
  //Serial.println(val5);
}

void func6(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val6 = (long)(value*255);
  //Serial.println(val6);
}




« Last Edit: August 15, 2012, 10:01:05 am by kazimier » Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Guess the birds wonder whats happening ?
Looks good
Logged

UK
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

we do actually have a lot of seagulls around here.. and yes they were a bit confused for a while especially when the birds of prey sounds come on...
Logged

Pages: [1]   Go Up
Jump to: