Show Posts
Pages: 1 2 3 [4] 5 6 ... 8
46  Forum 2005-2010 (read only) / Interfacing / Re: ping ))) code help on: June 04, 2009, 03:51:51 pm
mem: the map function seems like the perfect solution but I have been trying to implement it with little success:

Code:
/* New Variables */
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 = 31250;

/* Ultrasound Sensor
 *------------------
 *
 * Reads values (00014-01199) from an ultrasound sensor (3m sensor)
 * and writes the values to the serialport.
 *
 * http://www.xlab.se | http://www.0j0.org
 * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
 *
 */

 // CODE EDITED BY SEBASTIAN TOMCZAK 23 APRIL 2008

int ultraSoundSignal = 11; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0;
int brightness = 0;// Echo counter
int ledPin = 13;
int redPin = 2;
int bluePin = 3;
int yellowPin = 4;
int whitePin = 10;// LED connected to digital pin 13

void setup() {
  Serial.begin(baud_rate);
  pinMode(ledPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(whitePin, OUTPUT);            // Sets the digital pin as output
  MIDI_channel = MIDI_channel - 1;
}

void loop() {
  timecount = 0;
  val = 0;
  pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

  /* Send low-high-low pulse to activate the trigger pulse of the sensor
   * -------------------------------------------------------------------
   */

  digitalWrite(ultraSoundSignal, LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignal, LOW); // Holdoff

  /* Listening for echo pulse
   * -------------------------------------------------------------------
   */

  pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
  val = digitalRead(ultraSoundSignal); // Append signal value to val
  while(val == LOW) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
  }

  while(val == HIGH) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
    timecount = timecount +1;            // Count echo pulse time
  }

  /* Writing out values to the serial port
   * -------------------------------------------------------------------
   */

  ultrasoundValue = timecount;
ultrasoundValue = map(ultrasoundValue, 0, 127, 127, 0);

 // Append echo pulse time to ultrasoundValue
  if((ultrasoundValue >= 110) && (ultrasoundValue < 127)){
    digitalWrite(redPin, HIGH);
    delay(100);
    digitalWrite(redPin, LOW);
    digitalWrite(bluePin, HIGH);
    delay(100);
    digitalWrite(bluePin, LOW);
    digitalWrite(redPin, HIGH);
    delay(100);
    digitalWrite(redPin, LOW);
    digitalWrite(bluePin, HIGH);
    delay(100);
    digitalWrite(bluePin, LOW);
  
  }
 
 else{
  digitalWrite(redPin, LOW);
  digitalWrite(bluePin, LOW);  
 }



  /* BEGIN EDITED CODE */

  ultrasoundValue = ultrasoundValue - 14;
  ultrasoundValue = ultrasoundValue / 5;
  brightness = ultrasoundValue;
  analogWrite(whitePin, brightness);
  if(ultrasoundValue > 127) {
    printing_byte = 127;
    
  
  }
  
  else {
  
  printing_byte = ultrasoundValue ;
  }
  
  Serial.print(B10110000 + MIDI_channel,BYTE);
  Serial.print(cc_number,BYTE);
  Serial.print(printing_byte,BYTE);
  

  /* END EDITED CODE */

  /* Lite up LED if any value is passed by the echo pulse
   * -------------------------------------------------------------------
   */

  if(timecount > 0){
    digitalWrite(ledPin, HIGH);
  }

  /* Delay of program
   * -------------------------------------------------------------------
   */

  delay(delay_time);
}

All I want is for the MIDI data to be inversed, so instead of going from 0 to 127 it went the opposite way.

On a slightly side note - I have now attached a length of LED's that get brighter when the person comes closer to the sensor, however the fade is a bit jerky (i.e. not like a smooth fade) - is that because the midi data is 0 - 127 and the LED wants to have the brightness controlled from 0 to 255? or is it just bound to be a bit jerky.
47  Forum 2005-2010 (read only) / Interfacing / Re: ping ))) code help on: June 03, 2009, 04:42:35 am
hey - yeah, I am using a programme called MidiPipe http://www.macupdate.com/info.php/id/10541, although this is only necessary if there is some form of midi filtering needed. If its coming out of the ping sensor correctly then it should come up on vdmx. To make sure your computer is receiving MIDI data (correctly) I use a little app called MidiMonitorhttp://www.snoize.com/MIDIMonitor/ which shows what data is coming in on what channel etc. once you establish that there is something coming in correctly the next place to check is the IAC midi driver (applications/utility/audio midi setup) is turned on and online.  
48  Forum 2005-2010 (read only) / Interfacing / Re: ping ))) code help on: June 01, 2009, 06:40:42 am
thanks for that - it works perfectly now. The ping))) sensor is very responsive! really looking forward to working with it. Is there a way to reverse the output from it? What I mean is currently the sensor with the above code outputs a constant midi cc value, which goes from 127 - 0, so the closer i bring my hand to the sensor the lower the number - what I want to do is make it work in reverse so the closer I bring my hand to the sensor the higher the number. I have found a software solution (MidiPipe OS X) which allows you to run all sorts of midi filters including an inverse one, but was hoping to do it internally on the arduino board itself.

So at the moment the Ping ))) sensor outputs continuous midi data which I can now use to control ableton / modul8 etc. and that is the sound and video side of the project resolved. However - I want a series of lights to be triggered when the sensor reads that the hand is close to it, i.e. when it reads that the hand is 10cm away (midi value around smiley-cool that it can trigger a sequence of on/off on pins 2-10 and then reset itself. The idea is that if the viewer brings his hand too close to the crystal ball a whole host of lights and fans will turn on and off in a fairly manic sequence to give the impression that the viewer has gone too far.
49  Forum 2005-2010 (read only) / Interfacing / ping ))) code help on: May 29, 2009, 12:00:46 pm
hi

I have recently aquired a Ping ))) ultrasonic sensor for an upcoming project for which I need the data being recieved by the sensor to be output as a midi cc value to control a vj software (it is to build a crystal ball which a magician will use to tell the future - by bringing his hand towards it and hence increasing the opacity / volume of the video clip). The sensor works great and when I tested it with the code provided in the playground i get very stable results. I have been trying to implement the code found on the brilliant little_scale blog:
http://little-scale.blogspot.com/2008/04/ping-sans-max.html

however when i input the code into arduino:

Code:
/* New Variables */
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 = 31250;

/* Ultrasound Sensor
 *------------------
 *
 * Reads values (00014-01199) from an ultrasound sensor (3m sensor)
 * and writes the values to the serialport.
 *
 * http://www.xlab.se | http://www.0j0.org
 * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
 *
 */
 
 // CODE EDITED BY SEBASTIAN TOMCZAK 23 APRIL 2008

int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13

void setup() {
  beginSerial(baud_rate);
  pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
  MIDI_channel = MIDI_channel - 1;
}

void loop() {
  timecount = 0;
  val = 0;
  pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

  /* Send low-high-low pulse to activate the trigger pulse of the sensor
   * -------------------------------------------------------------------
   */

  digitalWrite(ultraSoundSignal, LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignal, LOW); // Holdoff

  /* Listening for echo pulse
   * -------------------------------------------------------------------
   */

  pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
  val = digitalRead(ultraSoundSignal); // Append signal value to val
  while(val == LOW) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
  }

  while(val == HIGH) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
    timecount = timecount +1;            // Count echo pulse time
  }

  /* Writing out values to the serial port
   * -------------------------------------------------------------------
   */

  ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

  /* BEGIN EDITED CODE */

  ultrasoundValue = ultrasoundValue - 14;
  ultrasoundValue = ultrasoundValue / 5;

  if(ultrasoundValue > 127) {
    printing_byte = 127;
  }
  
  else {
  
  printing_byte = ultrasoundValue;
  }
  
  printByte(B10110000 + MIDI_channel);
  printByte(cc_number);
  printByte(printing_byte);
  
  
  
  
  
  /* END EDITED CODE */



  /* Lite up LED if any value is passed by the echo pulse
   * -------------------------------------------------------------------
   */

  if(timecount > 0){
    digitalWrite(ledPin, HIGH);
  }

  /* Delay of program
   * -------------------------------------------------------------------
   */

  delay(delay_time);
}


I get the following error message:

In function 'void loop()':
error: 'printByte' was not declared in this scope


I am not too sure as to how to address this issue?
has anyone had any success outputting data being received by the ping sensor as midi cc values to a software?
any help would be greatly appreciated

50  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);
  
 
  

  }



51  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
52  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
53  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.
54  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.
55  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
56  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

57  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.
58  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.
59  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.


60  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?

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