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: /* * 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? /* * 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
|
|
|
|
|
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.htmlwhich 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.htmas 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?
|
|
|
|
|
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
|
|
|
|
|
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 
|
|
|
|
|