Loading...
  Show Posts
Pages: 1 2 3 [4] 5 6 ... 8
46  Forum 2005-2010 (read only) / Interfacing / Re: optical tachometer to MIDI help on: July 30, 2009, 11:55:29 am
hey

thanks for your reply - the map function is next on my list.
For now, I have managed to get the MIDI working pretty well - just need to tidy up the maths regarding the rpm readout as it jumps around a bit.
here is the code I have used:

Code:
/*
 * Optical Tachometer
 *
 * Uses an IR LED and IR phototransistor to implement an optical tachometer.
 * The IR LED is connected to pin 13 and ran continually. A status LED is connected
 * to pin 12. Pin 2 (interrupt 0) is connected across the IR detector.
 *
 *
 */
//#define DEBUG      
 
int ledPin = 13;                // IR LED connected to digital pin 13
int statusPin = 12;
int lightPin = 11;// LED connected to digital pin 12
int brightness = 0;
int delay_time = 40; // delay for this amount each write cycle.
byte MIDI_channel = 0;
byte cc_number = 0;
byte printing_byte = 0;
int Value = 0;
int midi_pitch = 0;
#ifdef DEBUG
const int DEBUG_RATE = 9600;        // Serial debugging communicates at 9600 baud
const int SERIAL_PORT_RATE = DEBUG_RATE;
#else
const int MIDI_BAUD_RATE = 31250;   // MIDI communicates at 31250 baud
const int SERIAL_PORT_RATE = MIDI_BAUD_RATE;
#endif



volatile byte rpmcount;
volatile int status;

unsigned int rpm;

unsigned long timeold;

 void rpm_fun()
 {
   //Each rotation, this interrupt function is run twice, so take that into consideration for
   //calculating RPM
   //Update count
      rpmcount++;
      
   //Toggle status LED  
   if (status == LOW) {
     status = HIGH;
   } else {
     status = LOW;
   }
   digitalWrite(statusPin, status);
 }

void setup()
 {
   Serial.begin(SERIAL_PORT_RATE);
   //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
   //Triggers on FALLING (change from HIGH to LOW)
   attachInterrupt(0, rpm_fun, FALLING);
  
   //Turn on IR LED
   pinMode(ledPin, OUTPUT);
   digitalWrite(ledPin, HIGH);
  
   //Use statusPin to flash along with interrupts
   pinMode(statusPin, OUTPUT);

   rpmcount = 0;
   rpm = 0;
   timeold = 0;
   status = LOW;

 }

 void loop()
 {
   //Update RPM every second
   delay(500);
   //Don't process interrupts during calculations
   detachInterrupt(0);
   //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
   //happened once per revolution instead of twice. Other multiples could be used
   //for multi-bladed propellers or fans
   rpm = 3*1000/(millis() - timeold)*rpmcount;
   timeold = millis();
   rpmcount = 0;
  brightness = (4 * rpm);
  analogWrite(lightPin, brightness);
 
   if(rpm > 127) {
    printing_byte = 127;
  
   }
  

else {
  
  printing_byte = rpm ;
  }
  #ifdef DEBUG
    Serial.println(rpm, DEC);
  #else
  Serial.print(B10110000 + MIDI_channel,BYTE);
  Serial.print(cc_number,BYTE);
  Serial.print(printing_byte,BYTE);
  #endif

  
    
   //Write it out to serial port
 
  
   //Restart the interrupt processing
   attachInterrupt(0, rpm_fun, FALLING);
  
 
  

  }



47  Forum 2005-2010 (read only) / Interfacing / optical tachometer to MIDI help on: July 30, 2009, 07:35:51 am
hi

I am working on a device that will be able to measure the speed of a rotating object (in this case a bicycle wheel) and control the pitch of an audio file (in ableton) I have go the optical tachometer working accuratly enough (although the incrementations by which it goes up and down need a bit of tweaking), I have managed to also get it to control the brightness of an LED according to the RPM. The next hurdle is to get the arduino to output the RPM as a midi cc message.
I have wired into the arduino a MIDI out port and have attempted to hack together some code I had from previous projects but so far with so success.
The arduino is outputting midi values but its jibbirish. I just want the RPM to be a cc value so that when it is at its fastest speed it is reading the highest midi value of 127 and when it is still it reads a midi value of 0.
below is the code I have so far - does anyone have any suggestions how to improve it?

Code:
/*
 * Optical Tachometer
 *
 * Uses an IR LED and IR phototransistor to implement an optical tachometer.
 * The IR LED is connected to pin 13 and ran continually. A status LED is connected
 * to pin 12. Pin 2 (interrupt 0) is connected across the IR detector.
 *
 *
 */
 
int ledPin = 13;                // IR LED connected to digital pin 13
int statusPin = 12;
int lightPin = 11;// LED connected to digital pin 12
int brightness = 0;
int delay_time = 40; // delay for this amount each write cycle.
byte MIDI_channel = 1;
byte cc_number = 127;
byte printing_byte = 0;
int baud_rate = 32500;
int Value = 0;

volatile byte rpmcount;
volatile int status;

unsigned int rpm;

unsigned long timeold;

 void rpm_fun()
 {
   //Each rotation, this interrupt function is run twice, so take that into consideration for
   //calculating RPM
   //Update count
      rpmcount++;
      
   //Toggle status LED  
   if (status == LOW) {
     status = HIGH;
   } else {
     status = LOW;
   }
   digitalWrite(statusPin, status);
 }

void setup()
 {
   Serial.begin(baud_rate);
   //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
   //Triggers on FALLING (change from HIGH to LOW)
   attachInterrupt(0, rpm_fun, FALLING);
  
   //Turn on IR LED
   pinMode(ledPin, OUTPUT);
   digitalWrite(ledPin, HIGH);
  
   //Use statusPin to flash along with interrupts
   pinMode(statusPin, OUTPUT);
   pinMode(lightPin, OUTPUT);
   rpmcount = 0;
   rpm = 0;
   timeold = 0;
   status = LOW;
   MIDI_channel = MIDI_channel - 1;
 }

 void loop()
 {
   //Update RPM every second
   delay(500);
   //Don't process interrupts during calculations
   detachInterrupt(0);
   //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
   //happened once per revolution instead of twice. Other multiples could be used
   //for multi-bladed propellers or fans
   rpm = 3*1000/(millis() - timeold)*rpmcount;
   timeold = millis();
   rpmcount = 0;
  
  brightness = (4 * rpm);
  analogWrite(lightPin, brightness);
  printing_byte = rpmcount;

  
  Serial.print(B10110000 + MIDI_channel,BYTE);
  Serial.print(cc_number,BYTE);
  Serial.print(127-printing_byte,BYTE);
   //Write it out to serial port
   Serial.println(rpm,DEC);
  
   //Restart the interrupt processing
   attachInterrupt(0, rpm_fun, FALLING);

  }




any help would be greatly appreciated
48  Forum 2005-2010 (read only) / Interfacing / Re: correct resistor / transistors advice sought on: June 01, 2009, 06:28:52 am
Tried the Mosfet this morning - and perfect results, very fast and fully compatible with my existing circuit. thanks again for all the advice
49  Forum 2005-2010 (read only) / Interfacing / Re: correct resistor / transistors advice sought on: May 29, 2009, 11:54:32 am
thanks for all the responses - I have tried a TIP31C and it was even less responsive than the TIP120, I tried them both with a lower base resistor and have ordered a MOSFET transistor instead - hopefully will get it working tomorrow.
50  Forum 2005-2010 (read only) / Interfacing / Re: correct resistor / transistors advice sought on: May 28, 2009, 11:22:34 am
just a quick update - the TIP120 did not really do the job, I think the control voltage it requires from arduino is higher than the board can output, it seemed to be really sluggish in comparison to the 2N222, will try a TIP31C instead.
51  Forum 2005-2010 (read only) / Interfacing / Re: correct resistor / transistors advice sought on: May 27, 2009, 01:18:16 pm
thanks for the advice - i thought that about the resistor also when I was setting everything up but since it worked i didn't probe it further. However the 1K resistor from the board to the transistor is an easy one to implement, I have ordered a TIP120 so will give that a go tomorrow.
Thanks again
52  Forum 2005-2010 (read only) / Interfacing / correct resistor / transistors advice sought on: May 27, 2009, 10:34:43 am
hi
as mentioned in the title I need some advice regarding a setup I have built but need to modify.
It is a system for controlling 17 x 1W LED's, they currently run from an external power supply running around 8v through the following circuit.
However I need to make this setup work from a car battery now (it is being installed into a mobile barrel organ) which is 12v. I am using 2N222 transistors and 3W resistors in my current setup, so am I right in thinking I need some transistors with a higher resistance rating?
any advice would be greatly appreciated



would something like this do:

http://uk.farnell.com/avago-technologies/at-41511-tr1g/rf-transistor-npn-sot-143/dp/1056822

53  Forum 2005-2010 (read only) / Interfacing / Re: Ping Sensor->Max/MSP -> Ableton on: May 29, 2009, 12:43:45 pm
hey - out of interest did you manage to get any successful results?
I have hit a similar problem to what you have described and was wondering if there was a workable solution.
54  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: May 15, 2009, 05:29:17 am
appologies for not being very clear - I want to build a device which would allow me to control a number of LED's connected to the arduino board through a MIDI controller, so essentially MIDI going into the board and then outputting serial data to control the individual I/O.

I will give it a go today without pin 6 connected, I guess the tricky thing I am finding and I am sure this is the same for many of us here, is troubleshooting, i.e. finding ways to troubleshoot the problem and narrow down the possible causes of it when nothing stands out.
55  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: May 14, 2009, 07:07:57 am
been trying to get this schematic alongside a few other MIDI IN ones to work but so far no results. Apologies if this is a stupid question but am I right in thinking that with this schematic pins 6 and 4 go to GND? and pin 5 goes first to PIN 0 and then to +5v (via 3.3k resistor)?

I have been trying to find a suitable solution and have also come across this in the process:

http://www.spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html

which is a Serial to Midi converter - haven't fully tested yet but could be a solution also - however this requires the MIDI data to be sent over USB and that also means a computer, I am interested in that to an extent but I would also like to be able to build standalone units that can be controlled by simple (and cheap) midi keyboards.


56  Forum 2005-2010 (read only) / Interfacing / Re: constant current driver advice sought on: May 05, 2010, 11:10:04 am
thanks for that advice mike -
i was thinking about the possibility of using something like this:

http://picprojects.org/projects/bigmosfetrgb/index.htm
as an led driver for the led's whilst doing the actual switching through the max7219 chips. the rgb led drivers can handle up to 5amp per channel - which is equal to 16 of the LED's I want to use. I realised that since i am using a max7219 chip there is not any point at which more than 8 are turned on - even to turn all of them on, the wiring library just cycles really fast through all the pins creating the illusion that they are all on. this should mean that one of those rgb drivers should be enough for the entire matrix.
if i just wire up the + of the led's to the mosfet driver and then control them through the GND - will this work? the pic board comes pre programmed with a load of different preset sequences but they should not matter as the driver does the switching through the GND which i hope to plug into the multiplexing chip instead, providing the driver is constantly outputting the required current for the led's.
could this work?

57  Forum 2005-2010 (read only) / Interfacing / Re: constant current driver advice sought on: May 05, 2010, 05:59:22 am
thanks for that - am i correct in thinking i will need one of these per LED?
58  Forum 2005-2010 (read only) / Interfacing / constant current driver advice sought on: May 05, 2010, 05:44:56 am
hello

i am in the process of building a 5 x 5 x 5 led matrix using some high power LED's - the ones i am keen on using have a fairly high forward current of 300mA and 3.0v DC forward voltage. I have been told on this forum that i will not be able to use a series resistor and instead need a constant current drive. I was hoping to get some advice regarding this:
could I get just one fairly powerful constant current driver for all of the LED's? if so - has anyone had much luck with this? I need something that can power 125 of these high power LED's. or do i have to get a number of them and then wire up the LED's in groups. I have found that using a 3w (33ohm) resistor gets good results but the resistor gets so hot that this is clearly not the solution especially if i want to build all of the circuit board into a fairly compact board.

thanks for your time
59  Forum 2005-2010 (read only) / Interfacing / Re: quick question re. correct resistor on: March 31, 2010, 04:17:16 pm
just had a look at the spec sheet - and it has a maximum continuous collector current rating of 600mA, so should be ok.
60  Forum 2005-2010 (read only) / Interfacing / Re: quick question re. correct resistor on: March 31, 2010, 12:51:51 pm
hi mike

thanks for your reply.
I did not know that 300mA LEDs needed a constant current drive - what is the maximum forward current that you can use a series resistor for? i am keen to use the LEDs i have mentioned as they are really bright and will be just right for the job + they are fairly cheap (I found 150 of them for $70).
With regards to the MAX7219 chip - i have used it in the past to control 64  LEDs with an external power supply, the chip itself got power through the arduino but the LEDs were powered externally. I have attached a schematic of how I did it before (with great results), however I was using not as powerful LEDs.
with regards to the DC forward Voltage - the minimum is 3.0v, typical 3.4v and max 3.6v.

How would I go about providing the LEDs with a constant current drive?

thanks

Pages: 1 2 3 [4] 5 6 ... 8