LDR with logic pro 9 (midi trigger)

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 =(.

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 Serial_MIDI.

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

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:-

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.

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.

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.

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]

This link works for the hardware info.

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:

//*******************************************************************************************************************
// 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);
}

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.

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.

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. . .

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.

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

Do you mean in the IDE examples?

Yes.

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.

Okay I got this to work and the sound from logic is getting to analog pin 0. But Idk how to get them to work together or which par the original code I was using (not the arduino example) works with the ldr.

There is no analogRead() anywhere in the code? That seems like a good place to start looking to me.

I uploaded the example's code to what I already had.
[codeMidi_touch_2.ino: In function 'void setup()':
Midi_touch_2:129: error: redefinition of 'void setup()'
Midi_touch_2:42: error: 'void setup()' previously defined here
Midi_touch_2.ino: In function 'void loop()':
Midi_touch_2:134: error: redefinition of 'void loop()'
Midi_touch_2:51: error: 'void loop()' previously defined here

If it reads "previously defined here: doesn't it mean it was already there.

If it reads "previously defined here: doesn't it mean it was already there.

Yes.

You should get a grip of at least the very basics of programming, it is hard to help you when you don't know what the help means.
It is like helping some one to do a hurdles race and finding out they can't stand up yet.

To join two pieces of code you need to do what it tells you here:-
http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

Okay, I hear ya grumpy mike. I shall read your article and learn the basics.
But just for the record this thing is actually working!
The ldr is triggering sounds from logic. The only problem is it's only working in the dark?!(any thoughts?)
It says also that I need to share the 5v line for the other ldrs. Does that mean I put multiple jumpercables in the same input on arduino?

A recap.
I'm running this 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(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);
}/code]

And I've wired the breadboard  just like in this picture. -http://cdn.instructables.com/FBA/Y5SV/GJQEIOFT/FBAY5SVGJQEIOFT.MEDIUM.jpg
 
Download this and fallowed instructions. 
http://www.spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html

And thats it!

It says also that I need to share the 5v line for the other ldrs. Does that mean I put multiple jumpercables in the same input on arduino

Yes.
I am not sure what you mean by work in the dark.
If you want to reverse the sense in which the light triggers chang all the

  ....... = analogRead( 
To 
...... = 1023 - analogRead(

Yes, I don't understand it either. The hole breadboard has to be covered or only "dimly lit" for the arduino to be triggered.
For example, I have to have my hand over the breadboard(to shield from light) then totally cover the ldr with me finger for it to trigger the midi.