Pages: [1] 2   Go Down
Author Topic: LDR with logic pro 9 (midi trigger)  (Read 1711 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Ive been trying to trigger drum sounds from logicpro9 via midi using LDR sensors for a few months now to no avail. I have all the supplies including 10k resistors, ldr's, wire, solder, jumpers, etc. . .
Does anyone here have an idea about this project?

Thanks for any help.
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 27
Posts: 1184
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What is your circuit and what is your code?
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have the arduino uno r3 and no code. I took up this project from an instructables website and the code it provided ended up not working  smiley-cry.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's what the hardware will look like http://www.instructables.com/files/deriv/FBA/Y5SV/GJQEIOFT/FBAY5SVGJQEIOFT.LARGE.jpg.

Here's a serial converter to get logic & arduino communicating http://www.spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html.

The part that takes a pro is getting logic to read the arduino and ldr's the same ways it reads a midi controller.
Can use help from coding to the arduinos setup to dealing with logic.

Thnx
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31452
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Here's what the hardware will look like
We need to know what your hardware looks like that is the one you can't get to work.

What we have to do is to look at your schematic, how you have implemented it and what code you are running.

You said:-
Quote
Hello Ive been trying to trigger drum sounds from logicpro9 via midi using LDR sensors for a few months now to no avail.
So you must have some code and hardware for us to work on.
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 27
Posts: 1184
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have been working for months and still have nothing to show then I would you may have been doing too much at once. IMHO think that your approach should be to
1. Try and get the LDR code working first - just read the LDR value and print it out. Lots of examples to follow on this.
2. Decide what you want the MIDI to do with the LDR value?
3. UNderstand how you can send a MIDI message out the Arduino serial port. Again many examples on this.
4. Build the message YOU want to send and put that through the serial output.


Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Heres what my hardware looks like.
1x Arduino board .
5x Small LDR Light Resistor (it costs $ cents and are very precise)
5x 10K Resistor
5x meters of thin and flexible solid core wire.
1x Protoboard and a bunch Jumper cables;
1x USB or Serial cable to connect Arduino -> MAC.
file:///Users/shawntperished/Downloads/IMG_20131212_143231_266.jpg
http://www.instructables.com/files/deriv/FBA/Y5SV/GJQEIOFT/FBAY5SVGJQEIOFT.LARGE.jpg (already posted)

https://gm2.ggpht.com/PPv7AVdGUn_r5BPfiDgl5eCnK7isucoWxIyfxDTZmJQ0_So4VbQE_44Rls6QtEHNiDX6x3KiMg5cM2E1mzUqn1FPdyG7btnpztiPHRxw8P5j1ptA0dpYgGimipgXrcmWSPV7zwYnyRpCw_UfomkZ8aZxEeemgxVD12D_fz-jj1DCkpCnOC7s1oA-aSE7_xDhASEYs7vl-PHpsvDe5cEagxT3byIYPLgNaTmirOabLXmO3tSh_ro_BiJMQGYEwWJF5Fh9-0HWuKfv3qlBVUCtAapPcBx8JZ8GgKvqTnVDy25hFnrQAcGb9bXzM7KaGLA78pcdL6HPdrF44Q5TP3oZnQnMReijsZdTynB9Yd6B075GPg5bMEcEHT6Zg7bv7n-w4kSP4CrDmebZU9huOqkLrK00Eqeq_plVyjp-urBB7STdwLP6TtrsQt-gwN-dg37g3-bAjHq16Y_CCLYGcwNBxGwj9Db21zCXtf0oqxyVHDkl4Gp6Rfecx1WDGGzRQEoTuRvkqvu2PFleS7pLYM-w-sOpJeNPfYgh9A=w912-h479-l75

So the board would look like:
Wire #1 -  connects 5v port and 4 LDR leads in a common and shared line.
Wire #2 - White: Connects LDR from Finger 1 to Analog IN Port 0
Wire #3 - White: Connects LDR from Finger 2 to Analog IN Port 1
Wire #4 - White: Connects LDR from Finger 3 to Analog IN Port 2
Wire #5 - White: Connects LDR from Finger 4 to Analog IN Port 3
All wires share 5v port.

(on another note). I am also confused on how the the sound generator app will communicate with the serial port(I've read things along the lines of midi port drivers.... If you have any thoughts on that.


And the code I'm using is.
Code:
unsigned char PadNote[4] = {45,55,60,67};         // MIDI notes from 0 to 127 (Mid C = 60)
                                                  // Imagine a piano roll. 45 55 are keys located on the middle for example.
                                                  // Tweak it to what sounds better to you.
 
int CutOff = 40;   // This is the minimal amount of analog reading before triggering the note!
 
int MaxPlayTime[6] = {6500,6500,6500,6500};               // Cycles before a 2nd hit is allowed
                                                          // Best value after lots of trial and error.
 
#define  midichannel 0;                              // MIDI channel from 0 to 15 (+1 in "real world")
 
 
//*******************************************************************************************************************
// Internal Use Variables
//
// You should tweak here if it's not optimal yet.
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Those values work perfectly when using the small LDR and 1K Resistor. So used it!
//
//*******************************************************************************************************************
 
boolean activePad[6] = {0,0,0,0};                   // Array of flags of pad currently playing
int PinPlayTime[6] = {0,0,0,0};                     // Counter since pad started to play
 
int ActivePadMinTime = 100;
int PinPauseTimeDelay = 200;
int PinPauseTime[4] = {0,0,0,0};
int PinAvailable[4] = {1,1,1,1};
 
unsigned char status;
 
int pin = 0;    
int hitavg = 0;
int maxread = 0;
int debug = false;
int noteOffset = 0;
 
//*******************************************************************************************************************
// Setup
//*******************************************************************************************************************
 
void setup()
{
  Serial.begin(57600);                                  // connect to the serial port 57600
}
 
//*******************************************************************************************************************
// Main Program
//*******************************************************************************************************************
 
void loop()
{
  for(int pin=0; pin <= 3; pin++)
  {
      hitavg = analogRead(pin);    // read the input pin
 
      if(debug)
      Serial.println(hitavg);
 
      if(hitavg < CutOff)   {
        if(debug)Serial.println("hitavg < CutOff");
        if(activePad[pin] == false) {
             if(debug)     Serial.println("activePad[pin] == false");
          if(PinAvailable[pin] == true)
          {
           if(debug) Serial.println("PinAvailable[pin] == true");
            // Toca a nota full
            activePad[pin] = true;
            PinPauseTime[pin] = 0;
 
            MIDI_TX((0x90 | pin), PadNote[pin]+noteOffset, 127);
 
         if(debug)   Serial.println("NoteON");
          }
        }
      }
 
     if(activePad[pin] == true) {
       if(debug)Serial.println("activePad[pin] == true");
       PinPlayTime[pin] += 1;
 
       if(analogRead(pin) > CutOff && PinPlayTime[pin] > ActivePadMinTime)
       {      
               if(debug) Serial.println("analogRead(pin) > PadCut == TRUE");
         activePad[pin] = false;
         PinAvailable[pin] = 2;
         if(debug)
         Serial.println("NoteOFF, available is now false. active is false;");
 
 
         MIDI_TX((0x80 | pin), PadNote[pin]+noteOffset, 50);
         PinPlayTime[pin] = 0;
 
        }
     }
 
     if(PinAvailable[pin] == 2 && PinPauseTime[pin] > PinPauseTimeDelay) {
       if(debug)Serial.println("PinAvailable[pin] == false && PinPauseTime[pin] > 10");
      PinAvailable[pin] = true;
     } else if(PinAvailable[pin] == 2) {
       if(debug)Serial.println("PinPauseTime[pin] += 1;");
       PinPauseTime[pin] += 1;
     }
 
     if(debug)delay(1000);
   }  
}
 
 
//*******************************************************************************************************************
// Transmit MIDI Message
//*******************************************************************************************************************
void MIDI_TX(byte MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
  //status = MESSAGE + midichannel;
  //status = MESSAGE + pin;
  digitalWrite(13,HIGH);
  Serial.print(MESSAGE, BYTE);
  Serial.print(PITCH);
  Serial.print(VELOCITY);
  delay(30);
  digitalWrite(13,LOW);
 
}/code]
 
Heres the response I get from the arduino software
[code]sketch_dec12a:1: error: expected constructor, destructor, or type conversion before 'char'
sketch_dec12a.ino: In function 'void loop()':
sketch_dec12a:71: error: 'PadNote' was not declared in this scope
sketch_dec12a:71: error: 'MIDI_TX' was not declared in this scope
sketch_dec12a:91: error: 'PadNote' was not declared in this scope
sketch_dec12a:91: error: 'MIDI_TX' was not declared in this scope
sketch_dec12a.ino: At global scope:
sketch_dec12a:113: error: variable or field 'MIDI_TX' declared void
sketch_dec12a:113: error: no matching function for call to 'HardwareSerial::write()'
/Users/shawntperished/Desktop/untitled folder/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:62: note: candidates are: virtual size_t HardwareSerial::write(uint8_t)
/Users/shawntperished/Desktop/untitled folder/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:63: note:                 size_t HardwareSerial::write(long unsigned int)
/Users/shawntperished/Desktop/untitled folder/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:64: note:                 size_t HardwareSerial::write(long int)
/Users/shawntperished/Desktop/untitled folder/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:65: note:                 size_t HardwareSerial::write(unsigned int)
/Users/shawntperished/Desktop/untitled folder/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:66: note:                 size_t HardwareSerial::write(int)
/Users/shawntperished/Desktop/untitled folder/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:53: note:                 virtual size_t Print::write(const uint8_t*, size_t)
/Users/shawntperished/Desktop/untitled folder/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note:                 size_t Print::write(const char*)
sketch_dec12a:113: error: expected primary-expression before 'unsigned'
sketch_dec12a:113: error: expected primary-expression before 'unsigned'/code]

[/code]
« Last Edit: December 12, 2013, 06:16:10 pm by Mnkyvsalien » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This link works for the hardware info.
https://mail.google.com/mail/u/0/?ui=2&ik=71d61a0d6a&view=fimg&th=142e911f155587d8&attid=0.1&disp=inline&realattid=1454258981627232256-local0&safe=1&attbid=ANGjdJ9t-ZhSE0_4j2utwlrXnqiaXDW0_Lf21Na_NJF25vuDESZimTUDdUov7RsqtUSRDlKxY8wrL_FrbSCu7Jk7xn4ckkPF8msGiKamFnljEKDxyay8AX5JffZDJrY&ats=1386890668370&rm=142e911f155587d8&zw&sz=w912-h479
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 27
Posts: 1184
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure what version of Arduino IDE you are using on the Mac, but it appears different from mine on Windows.

Your code does not compile with the Windows 1.0.5 version. You need to change MIDI_TX as follows:

Code:
//*******************************************************************************************************************
// Transmit MIDI Message
//*******************************************************************************************************************
void MIDI_TX(uint8_t MESSAGE, uint8_t PITCH, uint8_t VELOCITY)
{
  //status = MESSAGE + midichannel;
  //status = MESSAGE + pin;
  digitalWrite(13,HIGH);
  Serial.write(MESSAGE);
  Serial.write(PITCH);
  Serial.write(VELOCITY);
  delay(30);
  digitalWrite(13,LOW);
}
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Woah that actually worked Marco! . . . As far as getting logic to communicate with the arduino. ( when i touch the bottom of the analog in's on the arduino, as in the back-side of the board, it does trigger sound from the synth im running on logic).

However the ldr does NOT trigger the same sound, so i have to figure out how to send that same effect over to the protoboard and threw the ldr (cause its obviously not geting there) . It could be because the person who designed the first one and wrote the code was using 1k resistors and I am using 10k.
Also when I hold my finger over the back-side of the analog ins the sound it produces is seqeunced as in it continously triggers the sound on and off versus "holds".

The code also reads "avrdude: stk500_recv(): programmer is not responding" after uploading.


Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 27
Posts: 1184
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would really suggest that you experiment with the LDR to see what values you get back under certain conditions. Then you can make decisions about when and how the MIDI will be triggered.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, do you know which part of the code corresponds to the ldr's so I can test it?  Will there be a visible change in the arduino software when I touch it(i dont have any leds)?
Logic is getting all the way to the inputs on the arduino so I suppose it would be the same to get the signal over to the ldr as it would be to test it. . .
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 27
Posts: 1184
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Reading the LDR is just reading the analog input and printing the value you get back. It's a standard example that comes with the IDE.

You will get a change just by exposing it to light shading it with your hand/finger.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you mean in the IDE examples? There is no example for ldr sensors.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31452
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do you mean in the IDE examples?
Yes.
Quote
There is no example for ldr sensors.
Wrong. There are examples for reading the analogue inputs it matters not if they come from an LDR or a pot.
Logged

Pages: [1] 2   Go Up
Jump to: