Pages: [1]   Go Down
Author Topic: interfacing arduino+waveshield+standalone dmx box  (Read 1046 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody, since i'm not allowed to add links to my post until i firstly post a message without links, here's a message without links, the next and substantial one will follow shortly. Sorry for that interruption...

Sébastien
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody,
first of all, i want to thank the community for sharing all of this precious knowledge.
Then, for as obvious as it may seem, i have a question.
But first, let me describe the context a bit, as it seems important in order to understand the nature of my problem.
My buddy and I (I forgot mentioning we're french —sorry for that—,  he's a scenograph and i'm a light designer) have designed and built, a few years back, an artistic-poetic installation called "LuxBox" which is basically a 1 square meter box, transparent on 4 of its sides and equiped with 40 tiny LED projectors inside, in order to light up an abstract landscape essentially made of rusty metal and dead wood scraps. You can see a small video of it in action by clicking on this link (for info purpose only, i don't wanna be suspected of spamming) : http://www.sceneact.fr/scenographie.html#haut
The LuxBox is entirely autonomous, equiped with a computer, a driving/controling unit and a sound system, and plays on a 20 mn. cycle repeatedly, through a simple push of a button (a click of the mouse, actually).
As for today, we'd like to get rid of both the "pushbutton" and the computer, to make it truly autonomous, working without any intervention from a human operator.
I happened to find a replacement for the computer, which initial and essential role was to play both a pre-recorded lightshow and a musical score.
The lightshow would now be taken care of by a standalone DMX playback unit, while an Arduino+Waveshield (the latter being made by SeedStudio) combination would take care of the musical score.
The whole system would be orchestrated by an Arduino, which would simultaneously send start signals to both the waveshield and the standalone DMX Playback unit.
One can find a quick and dirty (not too dirty, i hope...) png diagram of the device here :
http://rapidshare.com/files/361063178/DiagLB2en2.png
As you can see, the Waveshield would host and send the musical score to the 5.1 amp, while the DMXPlayback unit would control the sending of the DMX frames to the driving/controling unit which, in return, would control and drive the projectors the way it usually does.
Last, but not least, i'd like to interface 4 distance IR analog sensors (one for each side of the LuxBox) in order to detect the proximity of a potential spectator and lauch the show.
Now, for my questions...
From what I have recently read (in "Practical Arduino", "Programming interactivity", "Physical Computing" and of course "Getting started with Arduino"), the whole thing appears pretty much feasible.
The major difficulty i can spot, as a total newbie, stands in synchronizing the start/stop of light and sound. But again, as a newbie, i'm pretty conscious it may not be the sole one and that i'm probably underestimating a few factors i'm not yet familiar with.
And that is precisely where i need your guys's help.
Does this general architecture look any viable to you ? Would there be a simpler or more rational way to proceed ?
Please tell me what you think about this project and its whereabouts, i will be eternally grateful since it'll both allow me to realize my project and progress into the Arduino universe.
Thanks again for taking the time to consider my plea and,
best regards to you all.

Sébastien


Logged

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That architecture looks feasible to me on first inspection, but I'm not sure what problem you're envisaging with synchronisation. I assume that once a sequence is started it will run through to completion every time, and not stop part way through if it stops detecting a presence. I also assume that the audio and video sub-systems can operate autonomously once they kick into action: all you need to do is send a "start" signal to the Enttec unit, and it takes care of the rest.

On that basis if you know that both the audio and video systems run for the same duration, and there's no particular "skew" that occurs while they are running that could cause them to drift out of synchronisation, then I don't see a particular problem. The role of the Arduino then becomes rather trivial: detect presence, store the timestamp (using millis), send "start" signals to the audio and video systems, and either go to sleep for a period equal to the duration of the display or go back to the start but only send start signals again if the current timestamp minus the last stored timestamp is greater than the show duration.

Short answer: what you're trying to do looks very feasible to me, unless I've overlooked something important.
--
Practical Arduino: www.practicalarduino.com
Freetronics: www.freetronics.com
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear Jon,

First, thank you soooo much for your answer, which helps a lot actually, as it radically narrows down the problematic i was concerned with.

Then, i'd like to mention i'm very honored to see my noob question answered by the very author of "Practical Arduino" 8-) : it really does strengthen my faith into the intrinsical capacity of the web to abolish borders, may they be a question of geography, expertise or whatever.

Anyway, and as you mentioned, i obviously got misled into thinking synchronicity could be a problem : the Enttec device is indeed fully autonomous as soon as it gets the serial command telling it to start the sequence. This is just as true of the Wave Shield, from what i've read.

So, and if i understand well, the sole issue which could be of any concern would stand into each autonomous device's intrinsical latency, right ? Then, and since i can precisely adjust the timing of the light sequence actual start, i'd just have to have it match the potential Wave Shield latency, which is pretty easy.

Before getting deeper into the timestamp question, i'd need to clear out one more possible issue : does the arduino require any kind of a time keeping device —like an RTC, typically—  to manage the timestamps, or is this taken care of by the arduino on a native basis ?

Thanks again for your help, Jon, and best regards,

Seb

Logged

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Sébastien,

It's not any particular honor: my knowledge level is vastly outstripped by many, many people on this forum!

Yes, my concern would be just maintaining timing between the devices. The Wave shield should maintain time very well - playing a (say) 17 minute, 12 second audio file should take exactly 17:12 from the moment it starts. I don't know anything about the video system you're using, but I assume that once it starts it also keeps to a quite well-defined schedule. Having the two systems out of sync by anything in the order of a few tens of milliseconds is not going to be noticeable to an observer, so with some testing of the latency of the two systems you should be able to get them starting close enough that nobody will ever be able to tell.

In terms of time-keeping for something like this you won't need an RTC. The Arduino itself maintains an internal counter that increments automatically once every millisecond, and you can retrieve the current value using the "millis()" function. The return value is simply the number of milliseconds the Arduino has been running since boot. There is some minor inaccuracy in millis() that I won't get into here: it causes problems for some real-time applications, but since you're dealing in time intervals related to human perception (which is very coarse compared to a microcontroller) you really won't care about it.

The value reported by millis() wraps back to 0 about every 49 days (IIRC) but even that shouldn't be a problem in your case, and it's easy enough to write the sketch in such a way that it doesn't glitch at the wrap-around.

Cheers      :-)

Jon
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear Jon,

Thx for your last message, it got me progressing quite a bit on my project's general architecture.

As for right now, i have a question you might be able to answer, concerning interfacing my 4 Sharp IR analog range sensors (the 2YOA21 flavor).

I would like the sensors, when they detect someone approaching less than a meter away,  to send the Arduino a start signal for both the Waveshield and the Enttec dmx interface. So, i materialized the on/off state with two leds, the red one being lit when irVal is above 80cm, the green one when it gets under 80cm.

I first tried with one sensor.

I found different pieces of code i managed, God knows how, to assemble in a functional way. I was pretty proud, actually, especially since the —small— parts of code i modded generated no syntax error at all and compiled just fine from the start. Small victory but, ya know... ;D

Here's the first piece of code.

[edit]/*
 read_gp2d12_range
 Function that reads a value from GP2D12 infrared distance sensor and returns a value in centimeters.

 Javier Valencia 2008 (mod by seb)

/* This is a simple code that reads an input from an analog pin on the Arduino and relays it back to the computer */

int irReader = 1;    // the analog input pin for the ir reader
int irVal = 0;       // stores value from Ir reader
int ledb = 8;
int ledr = 9;
void setup() {
Serial.begin(9600);  // begins serial communication with the computer
}

void loop() {
  int result;
  irVal = analogRead(irReader);    // read the value from the ir sensor
  delay(100);
  result = (6787 / (irVal - 3)) - 4;
  Serial.println(result);       // sends ir val to computer
  if (irVal > 80)
  {
    digitalWrite(ledb, HIGH);
    digitalWrite(ledr, LOW);
  }  
  else
  {
    digitalWrite(ledb, LOW);
    digitalWrite(ledr, HIGH);
  }
}

      [/edit]

As you can see, it successively( every 100 ms) reads the analog value returned by the sensor,  and serially prints the result , before lighting up a red or green led depending on the actual measured distance (over or under 80 cm).

Then, given the fact that my first success made me confident, i tried to leverage on it and, not really knowing the best way to extend the code to 4 sensors, simply decided to multiply it by 4, declaring as many sensors and variables as needed.

Here's what i wrote :

[edit]/*
 read_gp2d12_range
 Function that reads a value from four GP2D12
 infrared distance sensors and returns a value in centimeters, before
 lighting up a red or green led depending on the range

 Javier Valencia 2008 (modded by seb)*/

int ir1Reader = 0;    // the analog input pin for the ir reader
int ir2Reader = 1;
int ir3Reader = 2;
int ir4Reader = 3;
int ir1Val = 0;       // stores value from Ir reader
int ir2Val = 1;
int ir3Val = 2;
int ir4Val = 3;
int ledv = 8;
int ledr = 9;
int result1;
int result2;
int result3;
int result4;

void setup() {
Serial.begin(9600);  // begins serial communication with the computer
}

void loop()
{
  ir1Val = analogRead(ir1Reader);    // read the value from the ir1 sensor
  delay(500);
  result1 = (6787 / (ir1Val - 3)) - 4;
  Serial.println(result1);       // sends ir1 val to computer
  if (ir1Val > 80)
  {
    digitalWrite(ledv, HIGH);
    digitalWrite(ledr, LOW);
  }  
  else
  {
    digitalWrite(ledv, LOW);
    digitalWrite(ledr, HIGH);
  }
  ir2Val = analogRead(ir2Reader);    // read the value from the ir2 sensor
  delay(500);
  result2 = (6787 / (ir2Val - 3)) - 4;
  Serial.println(result2);       // sends ir2 val to computer
  if (ir2Val > 80)
  {
    digitalWrite(ledv, HIGH);
    digitalWrite(ledr, LOW);
  }  
  else
  {
    digitalWrite(ledv, LOW);
    digitalWrite(ledr, HIGH);
  }
  ir3Val = analogRead(ir3Reader);    // read the value from the ir3 sensor
  delay(500);
  result3 = (6787 / (ir3Val - 3)) - 4;
  Serial.println(result3);       // sends ir3 val to computer
  if (ir3Val > 80)
  {
    digitalWrite(ledv, HIGH);
    digitalWrite(ledr, LOW);
  }  
  else
  {
    digitalWrite(ledv, LOW);
    digitalWrite(ledr, HIGH);
  }
  ir4Val = analogRead(ir4Reader);    // read the value from the ir4 sensor
  delay(500);
  result4 = (6787 / (ir4Val - 3)) - 4;
  Serial.println(result4);       // sends ir4 val to computer
  if (ir4Val > 80)
  {
    digitalWrite(ledv, HIGH);
    digitalWrite(ledr, LOW);
  }  
  else
  {
    digitalWrite(ledv, LOW);
    digitalWrite(ledr, HIGH);
  }
}

      
[/edit]

The code, as far as measuring the 4 sensors' values sequentially, seems to work fine. It actually does measure each sensor one after the other, every half a sec, and sends the corresponding value on the serial monitor.

Unfortunately, the led part isn't working. Or, as i suspect, it gets confused since it sequentially gets too many infos. The leds do light on and off, but erratically, in a uninterpretable way. smiley-sad

What i would really like would be for the led to turn on or off, function of whichever sensor gets activated. I planned on 4 sensors just because our LuxBox will stand in the middle of a wide room, with spectators coming from different directions.

So, if i would to trivially express this intent in somekind of a basic algorithm, i could say "Light up the green LED as soon as 1 of the 4 sensors, whichever, has sent back a measurement below 80 cm. Otherwise, stay idle (light up the red led)".

I strongly suspect there exists a smart Wiring function that would take care of this. I mean, measuring sequential values from multiples sensors and issuing an identical result if one of the values matches the conditions.
I even suspect it could be a "while", but i cruelly miss the essential Arduino idiomatic vocabulary and grammar to guess it out. :-[

Would you please have a hint you could suggest me, that could be of any help ?

Thanks for your precious help,

Seb
Logged

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You're doing well so far but I think you need to change the structure of your expanded version of the program a bit. Unless I'm mistaken, what you want is for the green LED to illuminate if *any* of the range sensors detect <80cm, yes?

Instead, what you're doing is cycling through each sensor and displaying the appropriate LED for that sensor in isolation, then moving on to the next one. But you need to display the appropriate LED based on analysing all the sensors.

If that's the case what you need is a logical "OR" operation. You have 4 sensors, and you want your code to do something like this (pseudocode, not actual code):

Turn green LED on IF ((ir1val < 80) OR (ir2val < 80) OR (ir3val < 80) OR (ir4val < 80))

There are two obvious approaches to implementing that. The first is to just structure your code like I've done above, reading each of the sensors quickly in turn and then doing a series of OR comparisons against the results. Basically, take your current code and just move all the LED stuff to the bottom of the loop. That would be neatest for you.

Another way which I don't recommend in this case but mention just as a learning exercise because it may be helpful in other circumstances is to use a flag, which is a variable that you reset to a default state at the start of the loop and then any one of the comparisons during the loop can set it to a non-default state. Then at the end you check it and illuminate the correct LED based on its value.

That's a waste of time for this, but it may be useful in situations where (for example) you need to check a series of things like sensors and then report a number at the end showing how many sensors are tripped. You could set a variable to 0 at the start of the loop, then add 1 to it for each sensor that's tripped. at the end of the loop it will have a value of anything from 0 to 4, in your case. Then you could do things like have it get louder if there are more people around it!

Cheers     :-)

Jon
--
Practical Arduino: www.practicalarduino.com
Freetronics: www.freetronics.com
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your help on this, Jon,

[edit]You're doing well so far but I think you need to change the structure of your expanded version of the program a bit. Unless I'm mistaken, what you want is for the green LED to illuminate if *any* of the range sensors detect <80cm, yes?[/edit]

Absolutely !

[edit]Instead, what you're doing is cycling through each sensor and displaying the appropriate LED for that sensor in isolation, then moving on to the next one. But you need to display the appropriate LED based on analysing all the sensors.
[/edit]

Exactly so !

[edit]If that's the case what you need is a logical "OR" operation. You have 4 sensors, and you want your code to do something like this (pseudocode, not actual code):

Turn green LED on IF ((ir1val < 80) OR (ir2val < 80) OR (ir3val < 80) OR (ir4val < 80))
[/edit]

hehe, i got two answers in one :"pseudocode" was exactly what i was trying to express, and i kinda suspected the need for a comparison somewhere, but didn't know which operator could actually do. So, yes, it perfectly adresses my very issue !

[edit]There are two obvious approaches to implementing that. The first is to just structure your code like I've done above, reading each of the sensors quickly in turn and then doing a series of OR comparisons against the results. Basically, take your current code and just move all the LED stuff to the bottom of the loop. That would be neatest for you.
[/edit]

Yep, i'll choose this one approach, it appears faster and more elegant here.

[edit]Another way which I don't recommend in this case but mention just as a learning exercise because it may be helpful in other circumstances is to use a flag, which is a variable that you reset to a default state at the start of the loop and then any one of the comparisons during the loop can set it to a non-default state. Then at the end you check it and illuminate the correct LED based on its value.

That's a waste of time for this, but it may be useful in situations where (for example) you need to check a series of things like sensors and then report a number at the end showing how many sensors are tripped. You could set a variable to 0 at the start of the loop, then add 1 to it for each sensor that's tripped. at the end of the loop it will have a value of anything from 0 to 4, in your case. Then you could do things like have it get louder if there are more people around it!
[/edit]

Got it ! I'm gonna give it a try just for fun. This is very exciting, i bought Arduino stuff for like six months now, tons of it since i really believed —and still do !— it could answer a lot of our "arty" problematics, but never really found a way to dive deep into it. And the funniest, for a 44 y.o. geek wannabe like me, is that the easiest, more rational a
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...Sorry, sent a "send" shortcut by mistake !!

Anyway, i was just ending to say that the funniest was that code is indeed the most rational, elegant, but also the funniest and easiest angle of attack to do so. Learning C++ bases, for instance, didn't seem very sexy. But pushed by necessity while waiting for an hint from you, i happened to open and dive a bit deeper into "programming interactivity", by joshua Noble. In a couple hours, i had pretty much 85 % of my questions answered, and as soon as i got to his description of what classes were made of and intended to, 90 % of my initial fear had simply evaporated. And now i definitely wanna learn Processing, too, not even speaking about oF which very obviously is a must. But as Nobles writes, arduino's (and wiring) main quality is that you stay close to the metal, and this seems awfully attractive, hehe... smiley-wink

Well, thanks a lot for your help Jon, chances are i'll be back soon !

Cheers

Seb

Logged

Pages: [1]   Go Up
Jump to: