Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: cross voltages from neighbor analog input? on: August 19, 2013, 04:25:09 pm
Thanks to both of you,
I have done some other tests keeping the resistor and the zener plugged, without the piezo, and they are sufficient to correct this. What surprised me is that I had a threshold at 600 for the analog value and was still getting some "false positive".
Also reading two times
Code:
hitavg = muxShield.analogReadMS(1,pin);
didn't change anything. This tiny voltages seems to stay too long.

2  Using Arduino / Sensors / cross voltages from neighbor analog input? on: August 17, 2013, 08:16:45 am
Hello all,
I am using 4 piezos (and more comings) connected on a muxshield on analog inputs 0 to 3.
My code was working but I now encounter a problem.
If one of my sensor is unplugged e.g. pin 3 and I push the one on pin 2 a voltage is detected also on pin3. If I replug everything goes back to normal.

I have tried to remove the mux shield and changed the code to read arduino analog inputs and I have the same issue.
The piezo are connected in parrallel with a 5,1 zener and a 1Mohm resistor.
I have now tried to input 5volt on pin 2 with pin 3 unplugged and get the same issue (the consequence here is two midi notes playing at the same time.

I think I have burnt something on my UNO board...maybe one of you have another idea?
here is my code.

Thanks a lot,
Rok

Code:
//*******************************************************************************************************************

// User settable variables   

//exemple avec millis

//http://forum.arduino.cc/index.php/topic,76140.msg574940.html#msg574940

//*******************************************************************************************************************



#include <MuxShield.h> // for the muxshield library (optional?)



unsigned char PadNote[6] = {52,53,54,55,56,57};         // MIDI notes from 0 to 127 (Mid C = 60)

unsigned char CurrentPadNote[6] = {0,0,0,0,0,0};         // MIDI notes from 0 to 127 (Mid C = 60)

int PadCutOff[6] = {600,600,600,600,600,600};           // Minimum Analog value to cause a drum hit

int MaxPlayTime[6] = {90,90,90,90,90,90};               // Cycles before a 2nd hit is allowed

#define  midichannel    0;                              // MIDI channel from 0 to 15 (+1 in "real world")



//*******************************************************************************************************************

// Internal Use Variables   

//*******************************************************************************************************************

boolean activePad[6] = {0,0,0,0,0,0};                   // Array of flags of pad currently playing

int PinPlayTime[6] = {0,0,0,0,0,0};                     // Counter since pad started to play

unsigned char status;

int pin = 0;   

int hitavg = 0;



//*******************************************************************************************************************

// Multitasking 

//*******************************************************************************************************************

// Time periods of blinks in milliseconds (1000 milliseconds to a second).

// Time variable and constants are always unsigned long

const unsigned long MidiOutSendInterval = 1UL ;

const unsigned long MidiInReadInterval = 50UL ;



// Variable holding the timer value so far. One for each "Timer"

unsigned long MidiOutSendTimer = 0 ;

unsigned long MidiInReadTimer = 0 ;



//*******************************************************************************************************************

// Midi In Variables   

//*******************************************************************************************************************

byte statusIN;

byte PitchIN;

byte VelocityIN;



//*******************************************************************************************************************

//Initialize the Mux Shield

//*******************************************************************************************************************

MuxShield muxShield;





//*******************************************************************************************************************

// Setup   

//*******************************************************************************************************************

void setup()

{

 //Set I/O 1,  as analog inputs

muxShield.setMode(1,ANALOG_IN);



 

 MidiOutSendTimer = millis () ;

MidiInReadTimer = millis () ;

// connect to the serial port 31250 for MIDI communication

 Serial.begin(31250); 
//Serial.begin(9600); 

}

//*******************************************************************************************************************

// Main Program   

//*******************************************************************************************************************

void loop() {



// First, check if it is time to send Midi

  if ( (millis () - MidiOutSendTimer) >= MidiOutSendInterval ) {

  for(int pin=0; pin < 4; pin++)

  {

    //hitavg = analogRead(pin); 
    // read the input pin, classic input version
 
hitavg = muxShield.analogReadMS(1,pin); // read muxShield analog value on pin pin, row 1

    if((hitavg > PadCutOff[pin]))

    {

      if((activePad[pin] == false))

      {

        if((CurrentPadNote[pin] != PadNote[pin])){
        CurrentPadNote[pin] = PadNote[pin];
        }
       
        MIDI_TX(144,PadNote[pin],127);

        PinPlayTime[pin] = 0;

        activePad[pin] = true;

      }

      else

      {

        PinPlayTime[pin] = PinPlayTime[pin] + 1;

      }

    }

    else if((activePad[pin] == true))

    {

      PinPlayTime[pin] = PinPlayTime[pin] + 1;

     

      if(PinPlayTime[pin] > MaxPlayTime[pin])

      {

        activePad[pin] = false;

        MIDI_TX(128,CurrentPadNote[pin],127);

      }

    }

  }

  // end of the loop Reset timer with current time at end

    MidiOutSendTimer = millis () ;

  }

 

  //Check if is time to read midi in

  if ( (millis () - MidiInReadTimer) >= MidiInReadInterval ) {

  // ok it is time

checkMIDI();

// end of the loop Reset timer with current time at end

MidiInReadTimer = millis () ;

}



}

//*******************************************************************************************************************

// Transmit MIDI Message   

//*******************************************************************************************************************

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)

{

  status = MESSAGE + midichannel;

  Serial.write(status);

  Serial.write(PITCH);

  Serial.write(VELOCITY);

}



//*******************************************************************************************************************

// Receive MIDI Message   

//*******************************************************************************************************************

void checkMIDI(){

  do{

    if (Serial.available()){

      statusIN = Serial.read();//read first byte

      PitchIN = Serial.read();//read next byte

      VelocityIN = Serial.read();//read final byte

      if (statusIN == 145 && PitchIN != 0 && VelocityIN != 0){//if Chan 2 note on

  digitalWrite(13,HIGH);//turn on led

       

   //assign value to pad note

      PadNote[0] = PitchIN; 

      } else {
        digitalWrite(13,LOW);//turn of led
      }
    }

  }

  while (Serial.available() > 24);//when three bytes available

}

3  Using Arduino / Audio / Midi input and callback functions on: October 16, 2012, 04:12:55 am
So I have a midi In connected to my arduino on rx pin. The goal is to trigger LEDs with the function BlinkM_fadeToHSB(,,,) depending on midi event. For now, a midi note with velocity>1 trigger one LED board with the 0x09 I2C bus adress. The color of the RGB LED is changed using 3 midi control changes number 7,13 and 14 using the HandleControlChange callback.

I add trouble to handle interruption of the HandleControlChange callback by the MyHandleNoteOn so I've added two boolean "interruptors" (not sure how to call them) boolean oklight and boolean oksignal between them to be sure to end the wire transmission before call a new BlinkM_fadeToHSB.

Now I want to multiplex my code to use more than one address on the I2C bus, but I'm not sure this is really scallable.For example, one special midi note could trigger one LED. I feel I should use the BlinkM_fadeToHSB function in the loop only and change it's arguments in the callback but can't figure out how to write this.
Does anyone as an idea?

Here is my code:
Code:
#include "Wire.h"
#include "BlinkM_funcs.h"

#include <MIDI.h>  // Add Midi Library

#define LED 13    // Arduino Board LED is on Pin 13

byte blinkm_addr = 0x09; // addresse du master controle
int color = 0;
int intensite = 255;
int saturation = 255;
boolean oklight = true;
boolean oksignal = true;

// Below is my function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
  if (velocity == 1) {//A NOTE ON message with a velocity = Zero is actualy a NOTE OFF
    digitalWrite(LED,LOW);//Turn LED off

    if (oksignal==true) {
      oklight = false;
      BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
    }
  }
  if (velocity > 1) {
  BlinkM_fadeToHSB(blinkm_addr, color, saturation , intensite);
  oklight = true;
   }
}

void HandleControlChange (byte channel, byte number, byte value){   
    if (number == 7 ){
      intensite = map(value, 0, 127,0, 255);
      }
      if (number == 14 ){
      saturation = map(value, 0, 127,0, 255);
      //BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
      }
      if (number == 13 ){
      color = map(value, 0, 127, 0, 255);
      //BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
      }
      if (oklight== true){
      oksignal = false;
      BlinkM_fadeToHSB(blinkm_addr, color, saturation , intensite);
      oksignal = true;
      }
  }
 

void setup() {
  BlinkM_begin();
  BlinkM_stopScript(blinkm_addr);
  BlinkM_fadeToHSB(blinkm_addr, 43, 0, 255); // instant fade
  BlinkM_setFadeSpeed(blinkm_addr,255);
 
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to channel 2 notes only.
 
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function I want called when a Note ON command
  // is received. in this case it's "MyHandleNoteOn".
  MIDI.setHandleControlChange (HandleControlChange);
 
}

void loop() { // Main loop
  MIDI.read(); // Continually check what Midi Commands have been received
}

Thanks!
4  Using Arduino / LEDs and Multiplexing / Re: blinkm maxm and midi, programming advices needed! on: October 13, 2012, 07:12:18 pm
So I've added two boolean “tokens“ between the midiNoteOn and midiControlChange callbacks and it works! It thus wait the return of the function before being able to lauch a new transmission. Not sure it's the most elegant wait to do it but as for now it's a good start.
Code:
#include "Wire.h"
#include "BlinkM_funcs.h"

#include <MIDI.h>  // Add Midi Library

#define LED 13    // Arduino Board LED is on Pin 13

byte blinkm_addr = 0x09; // addresse du master controle
int color = 0;
int intensite = 255;
int saturation = 255;
boolean oklight = true;
boolean oksignal = true;

// Below is my function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
  if (velocity == 1) {//A NOTE ON message with a velocity = Zero is actualy a NOTE OFF
    digitalWrite(LED,LOW);//Turn LED off

    if (oksignal==true) {
      oklight = false;
      BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
    }
  }
  if (velocity > 1) {
  BlinkM_fadeToHSB(blinkm_addr, color, saturation , intensite);
  oklight = true;
   }
}

void HandleControlChange (byte channel, byte number, byte value){   
    if (number == 7 ){
      intensite = map(value, 0, 127,0, 255);
      }
      if (number == 14 ){
      saturation = map(value, 0, 127,0, 255);
      //BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
      }
      if (number == 13 ){
      color = map(value, 0, 127, 0, 255);
      //BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
      }
      if (oklight== true){
      oksignal = false;
      BlinkM_fadeToHSB(blinkm_addr, color, saturation , intensite);
      oksignal = true;
      }
  }
 

void setup() {
  BlinkM_begin();
  BlinkM_stopScript(blinkm_addr);
  BlinkM_fadeToHSB(blinkm_addr, 43, 0, 255); // instant fade
  BlinkM_setFadeSpeed(blinkm_addr,255);
 
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to channel 2 notes only.
 
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function I want called when a Note ON command
  // is received. in this case it's "MyHandleNoteOn".
  MIDI.setHandleControlChange (HandleControlChange);
 
}

void loop() { // Main loop
  MIDI.read(); // Continually check what Midi Commands have been received
}
5  Using Arduino / LEDs and Multiplexing / Re: blinkm maxm and midi, programming advices needed! on: October 13, 2012, 06:04:21 am
well I though I could find a way to have one instance of the builtin function in the loop() and sending paramaters from the callbacks but that doesn't work or I'm doing it wrong. I've change the fade time to "instantaneous" so these functions returns quite fast, maybe a wait(1) could be the solution.

here is the code of the fadetohsb function
Code:
// Fades to an HSB color
static void BlinkM_fadeToHSB(byte addr, byte hue, byte saturation, byte brightness)
{
  Wire.beginTransmission(addr);
  Wire.write('h');
  Wire.write(hue);
  Wire.write(saturation);
  Wire.write(brightness);
  Wire.endTransmission();
}
.

I suppose the problem appears when I open two connection on the wire. But strangely this code where the led changes are only from midi control change callback works :

Code:
#include "Wire.h"
#include "BlinkM_funcs.h"
#include <MIDI.h>  // Add Midi Library
#define LED 13    // Arduino Board LED is on Pin 13

byte blinkm_addr = 0x09; // addresse du master controle
int color = 0;
int intensite = 255;
int saturation = 255;

// Below is my function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
  if (velocity == 1) {//A NOTE ON message with a velocity = Zero is actualy a NOTE OFF
    //BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
  }
  if (velocity > 1) {
  //color = map(velocity, 1, 127, 0, 255);
  }
}

void HandleControlChange (byte channel, byte number, byte value){   
    if (number == 7 ){
      intensite = map(value, 0, 127,0, 255);
      BlinkM_fadeToHSB(blinkm_addr, color, saturation , intensite);
      }
      if (number == 14 ){
      saturation = map(value, 0, 127,0, 255);
      BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
      }
      if (number == 13 ){
      color = map(value, 0, 127, 0, 255);
      BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
      }
  }
 

void setup() {
  BlinkM_begin();
  BlinkM_stopScript(blinkm_addr);
  BlinkM_fadeToHSB(blinkm_addr, 43, 0, 255);
  BlinkM_setFadeSpeed(blinkm_addr,255);
 
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to channel 2 notes only.
 
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function I want called when a Note ON command
  // is received. in this case it's "MyHandleNoteOn".
  MIDI.setHandleControlChange (HandleControlChange);
 
}

void loop() { // Main loop
  MIDI.read(); // Continually check what Midi Commands have been received
 
}
6  Using Arduino / LEDs and Multiplexing / Re: blinkm maxm and midi, programming advices needed! on: October 12, 2012, 12:31:24 pm
My code is a bit better now, the map function work perfectly, thanks!  I still can't figure out how to interrupt the leds when I receive a note at velocity>1. I've tried many different scheme but nothing works. Maybe it's more a midi than LED problem...Here is a version with a boolean between the two callbacks.

Code:
#include "Wire.h"
#include "BlinkM_funcs.h"

#include <MIDI.h>  // Add Midi Library

#define LED 13    // Arduino Board LED is on Pin 13

byte blinkm_addr = 0x09; // addresse du master controle
int color = 0;
int intensite = 255;
int saturation = 255;
boolean oklight = true;

// Below is my function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
  if (velocity == 1) {//A NOTE ON message with a velocity = Zero is actualy a NOTE OFF
    digitalWrite(LED,LOW);//Turn LED off
    oklight = false;
  }
  if (velocity > 1) {
   oklight = true;
  }
}

void HandleControlChange (byte channel, byte number, byte value){ 
while (oklight == true) {
    if (number == 7 ){
      intensite = map(value, 0, 127,0, 255);
      BlinkM_fadeToHSB(blinkm_addr, color, saturation , intensite);
      }
      if (number == 14 ){
      saturation = map(value, 0, 127,0, 255);
      BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
      }
      if (number == 13 ){
      color = map(value, 0, 127, 0, 255);
      BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensite);
      }
}
  }
 

void setup() {
  BlinkM_begin();
  BlinkM_stopScript(blinkm_addr);
  BlinkM_fadeToHSB(blinkm_addr, 43, 0, 255);
  BlinkM_setFadeSpeed(blinkm_addr,255);
 
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to channel 2 notes only.
 
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function I want called when a Note ON command
  // is received. in this case it's "MyHandleNoteOn".
  MIDI.setHandleControlChange (HandleControlChange);
 
}

void loop() { // Main loop
  MIDI.read(); // Continually check what Midi Commands have been received
 
}

Someone inspired?
7  Using Arduino / LEDs and Multiplexing / Re: blinkm maxm and midi, programming advices needed! on: October 04, 2012, 07:03:41 am
Ok thanks that's very clear.
I'll try the map function for the range conversion.

Do you think it'll be better to keep my functions :
Code:
BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensity);
in the loop part and just change the color, saturation, intensity variables value in the midi callbacks?
8  Using Arduino / LEDs and Multiplexing / Re: blinkm maxm and midi, programming advices needed! on: October 03, 2012, 03:56:17 pm
I m using pin 0, Rx for midi in. I have no idea how to specify another in for serial debugging.
Thanks!
9  Using Arduino / LEDs and Multiplexing / Re: blinkm maxm and midi, programming advices needed! on: October 03, 2012, 06:52:06 am
I've deleted them for now but they were here for eventual troubleshooting :
Code:
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
  if (velocity == 1) {//A NOTE ON message with a velocity = 1is actualy a NOTE OFF
    digitalWrite(LED,LOW);//Turn LED off
    BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
  }
  color = velocity*2+1;
  BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensity);

Serial.write(velocity);

}

and adding Serial.begin(38400) to the setup
10  Using Arduino / LEDs and Multiplexing / blinkm maxm and midi, programming advices needed! on: October 03, 2012, 06:18:33 am
Hello,

I need some basic programming advice on my project. I'm driving maxm rgb led modules with midi from ableton live. I want to be able to control the color (hue) with the note intensity value, the saturation with the channel volume control change and the value with the channel control n°14.
For now, when one of this message is received, the BlinkM_fadeToHSB() is called with the changed parameters. The problem is I can't get led's off with the intensity at 1 because the other functions are still called by the other functions fadeToHSB called. How can I manage this better?

Second short question, my midi data values are from 1 to 127 and I would like to transform them from 0 to 255 with artificial  +1 increments, is there an elegant way to do that?

Last one, due to the midi specific baud rate, I can't get the serial monitor working to have a look at my variables or midi in messages. Is there a workaround for that?

Thanks to all, here is my code. Maxm is externaly powered, midi in arrives on rx pin.

Code:
#include "Wire.h"
#include "BlinkM_funcs.h"
#include <MIDI.h>  

#define LED 13  

byte blinkm_addr = 0x09;
int color = 0;
int intensity = 255;
int saturation= 255;

// Below is my function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
  if (velocity == 1) {//A NOTE ON message with a velocity = 1is actualy a NOTE OFF
    digitalWrite(LED,LOW);//Turn LED off
    BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
  }
  color = velocity*2+1;
  BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensity);
}

void HandleControlChange (byte channel, byte number, byte value){
  if (number == 7){
    intensity = value*2+1;
    BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensity);
    }
    if (number == 14){
    saturation = value*2+1;
    BlinkM_fadeToHSB(blinkm_addr, color, saturation, intensity);
    
  }
 

void setup() {
  BlinkM_begin();
  BlinkM_stopScript(blinkm_addr);
  BlinkM_fadeToHSB(blinkm_addr, 0, 0, 0);
  BlinkM_setFadeSpeed(blinkm_addr,255);
 
  pinMode (LED, OUTPUT);
  MIDI.begin(MIDI_CHANNEL_OMNI);
 
  MIDI.setHandleNoteOn(MyHandleNoteOn);
  MIDI.setHandleControlChange (HandleControlChange);
 
}

void loop() { // Main loop
  MIDI.read(); // Continually check what Midi Commands have been received
 
}
Pages: [1]