I am trying to figure out if there is a way to use the beam sensor in the link below as a trigger directly to one of the Servo channels the Mini Maestro 12-Channel set as an input.
I had it laying around from another prop setup and I wanted to utilize it with the new build I’m working on. I have a limited understanding of electronics and am slowly picking up on it.
I am not very familiar with that beam sensor, but it looks like it’s output is just a relay, so you should be able to use that like a switch as an input to the Maestro (i.e. connect the COM wire to GND and the NC wire to the Maestro signal channel along with a pull-up resistor).
The image below is the wiring diagram that came with it. Does the N.O (normally open) line connect to anything? And are there any concerns about the separate input voltage on the device being 12v?
The normally-open wire will just be the inverted result of the normally-closed wire, so you only need to use one of them.
As far as the 12V operating voltage, I suspect that is for powering the sensor and the relay, but the relay outputs are separate. If that is the case, then it should be fine.
Now the issue I’m having is trying to write the script so that it triggers track one on the Robertsonics MP3 trigger board when the beam is broken.
But I also need to make sure if the beam is broken while the track is playing that it doesn’t reset. I need it to wait until that track is done before the beam can trigger it again.
Using other posts and the How To guide I’ve started the script below. The problem is that the track only plays when the beam is broken, and it turns off when the beam is restored.
begin
begin
0 get_position 500 greater_than while
#while button is not pushed code inside of this while loop will run
repeat
0x31 0x54 serial_send_byte serial_send_byte
repeat
As a simple test to check that the MP3 trigger is behaving as expected, could you try replacing your script with the following code?
begin
0x31 0x54 serial_send_byte serial_send_byte
quit
repeat
Using that code, you should be able to start the track by clicking the “Run Script” button, and the track should play through. If that does not work, could you post a copy of your Meastro settings file along with some pictures of your setup showing all of your connections? You can save a copy of your Maestro settings file from the “File” drop-down menu of the Maestro Control Center while the controller is connected.
Thank you for the update. It sounds like the communication and everything is working properly. So, you should be able to use a simple script that just sends the appropriate byes when the button is pressed. The easiest way to prevent the button from working again until the audio is done playing is probably to just add a delay after sending the bytes.
For example, if your audio track is 10 seconds long, you can do something like this to have the program wait 10 seconds before continuing:
begin
0 get_position 500 less_than if #if the button is pressed
0x31 0x54 serial_send_byte serial_send_byte #send serial data to start track
10000 delay #wait for 10 seconds
endif
repeat
Could you post some pictures of your setup that show all of your connections, as well as a copy of your Maestro settings file? You can save a copy of your Maestro settings file from the" File" drop-down menu of the Maestro Control Center.
Also, could you check the “Status” tab of the Maestro Control Center to see how the slider behaves for the channel you have the beam sensor connected to? It should be high (to the right) normally, and go low (to the left) when the beam sensor is blocked.
Once I read your reply I instantly knew I had the Normally Closed and Normally Open lines swapped. I fixed that so, as you said, the slider for the channel behaves correctly with it being normally high and then it drops to the left with blocked.
With that, the code you sent does work fine in starting the track. My only issue now is that there is a value limit on the delay function of 32767. The track is longer than two minutes. Is there another way of delaying the beam sensor longer, so it doesn’t restart the track when blocked in that time limit?
I am glad you found the problem and were able to get it working.
To have the script delay longer, you could call several delay functions in a row. Alternatively, you can use the method shown in our “Long delays” example from the “Example Scripts” section of the Maestro user’s guide, which is a more elegant solution.
1.) When messing with the long delays code I’m opting to use the example below. But when I put it in the script it seems like the code wants the delay_seconds to be delay_minutes to match the sub routine title.
# delay by a specified number of minutes, up to 65535 min
sub delay_minutes
begin dup while
1 minus 60 delay_seconds # subtract one and delay 1min
repeat
drop return # remove the 0 from the stack and return
2.) Also, I’ve been going through the examples, and command reference pages in the users guide and I just can’t figure out where to input the delay code into the code below without getting a stack overflow error.
begin
0 get_position 500 less_than if #if the button is pressed
0x31 0x54 serial_send_byte serial_send_byte #send serial data to start track
endif
repeat
The subroutines in the “Long delays” example are essentially custom functions for delaying a specified number of seconds (i.e. delay_seconds) or minutes (delay_minutes). In order to call these subroutines from your main loop, they should be copied below your current script (after repeat).
Then, you can call them before endif to delay for your desired amount of time, like this:
begin
0 get_position 500 less_than if #if the button is pressed
0x31 0x54 serial_send_byte serial_send_byte #send serial data to start track
#delay 3 minutes and 40 seconds:
3 delay_minutes
40 delay_seconds
endif
repeat
# delay by a specified number of seconds, up to 65535 s
sub delay_seconds
begin dup while # check if the count has reached zero
1 minus 1000 delay # subtract one and delay 1s
repeat
drop return # remove the 0 from the stack and return
# delay by a specified number of minutes, up to 65535 min
sub delay_minutes
begin dup while
1 minus 60 delay_seconds # subtract one and delay 1min
repeat
drop return # remove the 0 from the stack and return