MIDI Sprout

Discussion (*ask your questions here!) => Questions => Topic started by: Julio on January 10, 2018, 06:50:48 AM

Title: MidiSprout controlling 8channel Switch Relay
Post by: Julio on January 10, 2018, 06:50:48 AM
Hi Sam,

I'm preparing an art installation with the MidiSprout builded with your tutorials,
 
My idea is to now change the MIDI output jack of my midi sprout (I do not need midi notes), what I need is something simpler, I want to control in some way an 8-channel relays switch module (the ones that often used with arduino).

at the moment I am controlling the relays with a simple random generator written in an Arduino Uno. the connection and circuit of the relays work very well.

My question is: how could I make the plant define those parameters on and off in the 8 channel relays module? that is: (1) which relay channel it selects and (2) how long that channel remains on, before it is disconnected again.

thanks a lot in advance!
Title: Re: MidiSprout controlling 8channel Switch Relay
Post by: sam on January 10, 2018, 12:14:12 PM
Hello Julio, yes that is a great idea to control a set of relays with the sprout.  How much programming experience do you have, and is this your first electronics project?  Your modifications are very doable, but it will take a bit of solder and code!

1.) what type of relay board are you using?  Many relay boards for arduino have 8 individual digital input pins, some use SPI/I2C, and others can use Serial to trigger the relays.   I think we have 8 digital pins available on the sprout, so even the most basic or diy relay setup should be able to be 'wired' to the sprout.

2.) You can easily modify the code to turn a relay on when a note is triggered and off when an note is updated. 
   a. First you should increase the note polyphony from 5 to 8 (to match your relays). 
   b. Second, In setNote() add  some code to turn on the relay digitalWrite(relayPin[ i ],HIGH);  where relayPin[] is an array containing the pin number for each of the relay inputs and "i" is the currently available 'note' of the 8 available from polyphony
   c. Third, in checkNote() add some code to turn off the relay when the note is expired digitalWrite(relayPin[ i ],LOW);

This method will have the relays mirror the notes and durations as they turn on and off.

Good luck!  please post some more info of your build!

-sam
Title: Re: MidiSprout controlling 8channel Switch Relay
Post by: Julio on January 17, 2018, 10:44:34 AM
Hi Sam,
sorry for the late reply, I did not get a notification of your response:)
thanks for your reply

well, programming experience very little, but tomorrow I ll have some help from an expert.
I have more experience with soldering DIY oscillators dub sirens, and simple synths, this is my first one involving code.

1. this is my relay board:
(https://78.media.tumblr.com/0de487f012e0845f0c386163bb725476/tumblr_p2ph6fNAqk1wwmmh8o1_r1_1280.jpg)
(https://78.media.tumblr.com/d5bc435d730e6c54fdd422c7ed4bcb96/tumblr_p2ph6fNAqk1wwmmh8o3_r1_1280.png)
(8 Channel 5V Relay Module Modul for Arduino)
Now it is working with a simple code with a random generator / it is working just fine / but I would like to have a real change of this random generator with the input signal of the Midi Sprout.
This is the code I am using:
#define RELAY1  2
#define RELAY2  3
#define RELAY3  4
#define RELAY4  5
#define RELAY5  6
#define RELAY6  7
#define RELAY7  8
#define RELAY8  9
byte relays[8] = { RELAY1, RELAY2, RELAY3, RELAY4, RELAY5, RELAY6, RELAY7, RELAY8};
void setup() {
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
  pinMode(RELAY5, OUTPUT);
  pinMode(RELAY6, OUTPUT);
  pinMode(RELAY7, OUTPUT);
  pinMode(RELAY8, OUTPUT);
}
void loop() {
  digitalWrite(relays[random(0, 8)], random(0, 4));
  delay(random(500, 5000));
}

and about my DIY sprout build, here is a picture of it:
(https://78.media.tumblr.com/0e41730e0b4ec65bf53d083919080d0b/tumblr_p2ph6fNAqk1wwmmh8o2_540.png)
(please note I could not find a .0042uF capacitor so instead I use a .0047
also I got so much trouble trying to bootload the ATMEGA328-PU so I use instead the ATMEGA328P-PU from an Arduino UNO, do you think this 2 changes from the original kit would be problematic?, seems to work fine till now)

so, in short, I have this two "devices" working separately.., now I need to somehow make them communicate to each other.. :)

Thanks a lot for the coding suggestions and very creative input!, tomorrow I ll test them with the build, hopefully everything works 0k.

best!
Julio
Title: Re: MidiSprout controlling 8channel Switch Relay
Post by: Julio on January 20, 2018, 07:14:49 PM
(Update)
I have the soldering part done (not using Midi Out + leds)
and using 8 digital out from ATMEGA connected to 8channel relay board:
(https://78.media.tumblr.com/d847a543974d7ff65dcaaa8bcb167a30/tumblr_p2vpjmau271wwmmh8o2_1280.jpg)
(https://78.media.tumblr.com/059b78a03c78112357bcf4409de3ae5b/tumblr_p2vpjmau271wwmmh8o3_1280.jpg)
(https://78.media.tumblr.com/d7e19e5e21cd4b6a4b055140f711af90/tumblr_p2vpjmau271wwmmh8o1_1280.jpg)
so we tried to work on editing the original code to switch the relays on/off, with still no luck:(
Title: Re: MidiSprout controlling 8channel Switch Relay
Post by: sam on January 20, 2018, 09:19:15 PM
Send me a link to your code and I'd be happy to help.  This should be a fairly easy modification with the right digital pins.