Show Posts
Pages: 1 [2] 3 4 ... 12
16  Forum 2005-2010 (read only) / Syntax & Programs / Re: Timing Problem on: June 16, 2008, 08:46:53 pm
Good idea. Tried it; it doesn't work. Thanks, though. I've given up this project because even though it LOOKS cool, it's completely impractical and the code is extremely delicate (easily flawed). It's just not practical for use as an alarm, and it simply doesn't work.  :'(
17  Forum 2005-2010 (read only) / Syntax & Programs / Re: Timing Problem on: June 02, 2008, 02:39:15 pm
Mmmkk... But I'm not sure it's moving exactly 10 degrees at a time; the '10' increments in the program are definitely not 10 degrees, now that I think about it; the pulse width extremes that the Arduino sends to this servo are 1100 and 2100, and this servo obviously does not rotate up to 2100 degrees (or even 360 for that matter). So maybe that's not the problem.....?
18  Forum 2005-2010 (read only) / Syntax & Programs / Re: Timing Problem on: June 02, 2008, 08:28:50 am
Ok.
I AM stepping 10 degrees (or so I guess)
The servo IS following the 'if at an extreme, toggle direction' rule
BUT--

-The range is being measured AFTER the pulse is sent to the servo, not before.
-It is NOT waiting a few ms for the servo to move and stabilize position

Do you think that could be messing up the results?
When I have the Arduio send the two sets of results to the serial port on my PC, SOME values DO match up, but others may be wayyyy off. This MUST be because it's not taking the readings from one 120 degree sweep in the SAME POSITION as the second set of readings (they should BOTH be taken in the same positions on the servo axis). So this has do do with a timing problem, maybe? Or is it something else? When I get a chance, I'll add in a delay after the servo routine (right after it pulses out the pulse width to the servo), and put the 'readPing()' routine AFTER that delay. Maybe that'll fix it... :-/
19  Forum 2005-2010 (read only) / Syntax & Programs / Re: Timing Problem on: June 01, 2008, 10:41:50 pm
Okay - so I decided that cool security systems like the ones you see in futuristic sci-fi movies are really cool, so I decided to start making one myself. It may be kind-of ineffective the way I'm doing this, but hey, the thing looks really cool and intimidating when in action. BUT - I've got a timing problem. Basically, the whole setup is a ultrasonic rangefinder mounted on a standard hobby servo, that pans ~ 120 degrees as the ultrasonic ranger (it's a Parallax 'Ping)))') 'scans' the environment. The device checks the ultrasonic rangefinder between every pulse to the servo. Well, little did I know that there's a huge varying delay between the time the ranger sends out an ultrasonic signal, and when it receives that signal (a couple milliseconds). THIS is a problem, because the pulse width is messed up on the servo, and it throws the readings off (it scans 120 degrees in one direction, then reverses direction and scans that 120 degrees, comparing the results from each direction. How can I fix this? Do I need to mess with the 'delayMicroseconcds' part and do some math and make a scale to keep everything even? Or is my claim wrong about the timing problem, and it's in fact something entirely different?
20  Forum 2005-2010 (read only) / Syntax & Programs / Timing Problem on: June 01, 2008, 10:41:36 pm
NOTE: READ THE BELOW POST FIRST *I MESSED UP AND WENT OVER ON CHARACTERS*

Here'e the code (ignore any commented-out code and subroutines that are not called upon):

Code:
int servoturretPin = 3;
int pulses = 0;
int sensVal[10];
int prevSensVal[10];
int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 8; // LED connected to digital pin 13
boolean increment;
int i;
int prevcnt;
int newcnt;
int done;
int a;
int x;
int prevtime;
int delaytime;

void setup() {
  Serial.begin(9600);
  pinMode(servoturretPin, OUTPUT);
  pinMode(ledPin, OUTPUT);      
}

void loop()
{
  Scan();
}

void Scan() {
  
  if(done == 2) {                     // This if for debugging; it scans as much as it needs to to get results, then shows you them
    printVals();
  }
  if(pulses >= 2100)                     // Starting here is the code for handling the back-and-forth of the servo
  {  pulses = 2100;  
     increment = true;
    while(pulses >= 1100)
    {
      prevtime = millis();              // Here I TRIED to fix the timing problem; it doesn't work, though
      readPing();                         // read the ultrasonic rangefinder
      pulses = pulses - 50;                  // Speed
      digitalWrite(servoturretPin, HIGH);
      delayMicroseconds(pulses);
      digitalWrite(servoturretPin, LOW);
      delay(delaytime);                             // Speed
    }
    if(millis() > 10000) {
      done = done + 1;
    }
    a = 0;
  }
  else if(pulses <= 1100)  
  {  pulses = 1100;  
     increment = false;
    while(pulses <= 2100)
    {
      prevtime = millis();
      readPing();                                // read it again in reverse direction
      pulses = pulses + 50;                  // Speed
      digitalWrite(servoturretPin, HIGH);
      delayMicroseconds(pulses);
      digitalWrite(servoturretPin, LOW);
      delay(delaytime);                             // Speed
    }
    if(millis() > 10000) {
      done = done + 1;
    }
    a = 0;
  }
}                                               // (end of code for handling servo)
void readPing() {
 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
Serial.println(ultrasoundValue);

if(pulses == 1100 || pulses == 1200 || pulses == 1300 || pulses == 1400 || pulses == 1500 || pulses == 1600 || pulses == 1700 || pulses == 1800 || pulses == 1900 || pulses == 2000 || pulses == 2100 && millis() > 10000 ) {
  if(increment == true) {                         // The function of the above 'if' is to ONLY store new values every time pulses is 100 more
    prevSensVal[a] = ultrasoundValue;     // ...(store a total of 10 values in each direction)
    a++;
  }       // The above 'if' is for storing the first set of values
  if(increment == false) {   // and <---- this one if for storing the next set (after reversing direction)
    sensVal[a] = ultrasoundValue;
    a++;
  }
}
for(x = 0; x < 9; x++) {      // For debugging
  if(prevSensVal[x] > 0) {
    prevcnt = prevcnt + 1;
  }
  if(sensVal[x] > 0) {
    newcnt = newcnt + 1;
  }
}
delaytime = 150 - (millis() - prevtime);
}
void printVals() {
  Serial.println("Counters: ");
  Serial.println(prevcnt);
  Serial.println(newcnt);
  Serial.println("Previous");
  for(i = 0; i < 10; i++) {
    Serial.println(prevSensVal[i]);
  }
  Serial.println("Newest");
  for(i = 0; i < 10; i++) {
    Serial.println(sensVal[i]);
  }
  end();
}
void end() {                  // ignore
  delay(500);
  end();
}
21  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: May 15, 2009, 04:29:01 pm
Kazimier,

You may want to start a new thread for that topic.

As for myself, I am trying to figure out how to deal with serial data. I have found out that MIDI data is EXTREMELY time-critical. How can I deal with simultaneously getting MIDI data, sending MIDI data, and communicating to a serial LCD?? These all require serial (to be exact, I'd need 2 dedicated Tx lines, and 1 Rx line). I do not want to spend $65 on an arduino mega; they're really cool, but they are just too expensive. I've heard something about 'serial multiplexers' which I THINK give you more serial I/O, but there seems to be not very much documentation on using them with the arduino, OR Is it possible to build a switching circuit using high-speed transistors that can give me more serial I/O??  :-/
22  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: May 14, 2009, 03:48:43 pm
Kazimier,

It's not very clear what you wish to do with this, but from what I have gotten out of it, you want to make a MIDI Controller/Sampler that will receive MIDI messages from a MIDI keyboard and then produce sound assigned to each key?

I didn't use the 100K resistor; I didn't even connect pin 6 to anything and it works. If you have trouble reading schematics, google "schematic symbols"; there's a huge wealth of information out there on that.
23  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: May 12, 2009, 09:49:34 pm
HOORAY! It works!  ;DI finally got it to work lol. I DIDN'T need the 100Kohm resistor, and I had a few things mixed up it seems. Now I just have to debug all these MIDI messages, and figure out a way to receive, store, and retrieve them quickly and efficiently...
24  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: April 05, 2009, 08:55:41 pm
I am EXTREMELY frustrated! I have spend my ENTIRE Sunday debugging this, but I can't get it to work. I have all the connections correct, I'm pretty sure. I am using a split-end cable which goes right into the female jack on my microKorg synth. I am using a 4N28 opto-isolator. The 220ohm resistor connects to pin 2 on the other end of the cable (the circular, male metal connector end end). To help myself visualize, when looking at the end of the male MIDI jack, I number the pins:
   2.  3.  4.  
1.             5.
pin 4 on this cable connects to pin 2 of the opto. I am NOT using pin 3 (which is GND for the MIDI connector). I shouldn't be, correct? Anyways, with or without, it hasn't worked.

I read the details on using a different value resistor on pin 6 of the opto. For some reason, I SOMETIMES will get a '1' returned with Serial.available(), IF i mess with a potentiometer between 100Kohms and 200Kohms (usually ~170 does it), but it isn't reliable at all. I've got this all set up on a breadboard for now.

It is my understanding that this is supposed to connect to the jack on the MIDI device labeled "MIDI OUT", correct? I am also getting a little confused with perspectives here lol (flip-flopping cable/jack pins 4 & 5 to match male/female jacks/sockets). Have I possibly blown out the optoisolator? I don't see what I'm doing wrong! :'(

FYI: I have been referring to the original schematic on page 1 of this topic.
25  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: March 16, 2009, 07:45:24 pm
I got a Korg MicroKorg for xmas a while back only to find that it didn't have a sequencer built in smiley-sad. So, I've decided I'm going to make an Arduino do some MIDI IN/OUT, and act as a cool sequencer accessory. I'm using a small backlit serial LCD, some multi-color LED bar graph displays, a few HC595's, a large pot, and (possibly) 2 Arduinos. I figure I'll have two Arduinos to make the setup easier to program (master-slave config). I hope to get it to the point where the Arduino(s) will get all key, knob, and other MIDI status messages from the microKorg, and save that info in each step along with the program number (for each unique program sound). It'll then be able to play it back in sequence at a variable tempo. I'll update here if you'd all like!  smiley
26  Forum 2005-2010 (read only) / Interfacing / Re: High-power LED problem on: January 28, 2010, 11:59:20 pm
wait...scratch that part about driving a transistor with a transistor (2N2222). Forgot about the voltage drops
27  Forum 2005-2010 (read only) / Interfacing / Re: High-power LED problem on: January 28, 2010, 11:49:37 pm
Wow thank you all for the help, advice, and analysis  ;D! I don't have the money to spend on a switching power supply, or a constant current supply, so I am still sticking with 'quick and dirty'. I have removed the 3.3V regulators, and replaced them with LM7805 5V ones. I now have a set of 3 adjoined LEDs in parallel (so same voltage drop, right? Not stacking?). Each of the 7805's drives 3 LEDs (so 2 7805's driving 3LEDs each). The two 3-LED groups each have a 10-ohm, 1W resistor tying them to +5V.  Now what transistor should I use to switch each LED on (brought to GND)? I am not bringing the 2 groups to ground, but each LED individually. The 2N2222's can't handle this setup as you all said before (I tested it and they do some pretty weird stuff). Let's take note that I CAN use the 2N2222's to turn on higher-powered transistors that I get, if necessary. Radioshack is the limiting factor here because I need to get this project done really soon. It looks like I have a choice between the: TIP42 (PNP), IRF510 (MOSFET), TIP31 (NPN), TIP3055 (NPN). I think one of those has a base-to-emitter voltage of > 5V so obviously I can't use it. Thanks a lot to you all; I really appreciate it.
28  Forum 2005-2010 (read only) / Interfacing / Re: High-power LED problem on: January 26, 2010, 10:35:36 pm
Okay; I will be replacing the 3.3V regulators with high-current 5V one(s). I will also add the appropriate resistor to each LED, rated for 3W just to be safe.

What is the ideal transistor type to use in this situation? High-gain, low power dissipation? [size=12]All I want to be able to do is drive six of these LEDs using transistors, and still have the most current possible left over for other things, keeping in mind that I only have ~40mA to spare of driving capability from the ATmega328.
[/size]
This should be preferably one from radioshack (even though they charge you an arm and a leg plus another leg). I need to have this project completed soon and I can't deal with more snail mail. I see that they have this one: http://www.radioshack.com/product/index.jsp?productId=2062618&filterName=Type&filterValue=Transistor (IRF510 MOSFET). What would you recommend out of what they have? I.e. what would be best for this situation?

Thank you all for helping and offering your time to assist me!  smiley
29  Forum 2005-2010 (read only) / Interfacing / Re: High-power LED problem on: January 26, 2010, 04:46:04 pm
Okay. I just measured 100mA on the dot with my multimeter.
30  Forum 2005-2010 (read only) / Interfacing / Re: High-power LED problem on: January 26, 2010, 04:21:45 pm
Amidst this mess, I have calculated they are only drawing about 150mA when on, full power.

Here's the odd thing:

I have ran this for a half-hour at a time and the ONLY THINGS that got hot were the 3.3V regulators...!! Note that I have a heatsink on them, as well as a cooling fan. The 2N2222's have no heatsinking save for the PCB traces of solder that hold them in. The LEDs get warm and a heatsink is recommended for them, but I think that in this case they don't need them because they are running at low power (although they're still SUPER bright).

I don't know what to do smiley-sad. I guess I'll have to tear this all apart and re-design it.
Pages: 1 [2] 3 4 ... 12