Go Down

Topic: LDR with logic pro 9 (midi trigger) (Read 4054 times) previous topic - next topic

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.


What is your circuit and what is your code?
Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

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



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.

Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

Dec 13, 2013, 12:07 am Last Edit: Dec 13, 2013, 12:16 am by Mnkyvsalien Reason: 1
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.
http://www.instructables.com/files/deriv/FBA/Y5SV/GJQEIOFT/FBAY5SVGJQEIOFT.LARGE.jpg (already posted)


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: [Select]
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(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;
        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;


// Transmit MIDI Message
void MIDI_TX(byte MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
 //status = MESSAGE + midichannel;
 //status = MESSAGE + pin;
 Serial.print(MESSAGE, BYTE);


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]


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:

Code: [Select]

// Transmit MIDI Message
void MIDI_TX(uint8_t MESSAGE, uint8_t PITCH, uint8_t VELOCITY)
  //status = MESSAGE + midichannel;
  //status = MESSAGE + pin;
Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

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.
Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

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.
Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

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


Do you mean in the IDE examples?

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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131