Show Posts
Pages: [1] 2 3 ... 18
1  Using Arduino / Networking, Protocols, and Devices / Re: Single Wire Interface Between Two Arduinos on: March 31, 2014, 07:17:49 pm
I got it working!  For posterity here is the solution I found:

I started trying to use one-wire, but the libraries are mainly built for third party IC's and have a lot of overhead I did not want to use if I didn't have to, so I switched to using a multiplexed software serial.

Instead of altering the library, I create my software serial instance in a function such that when the function exists it will go out of scope and close the port.  Then I can use a separate function to create the opposite serial port.  This system works because the slave will only use the bus in response to data from the master.  Thus I can do all the communication with one digital pin and a ground line. 

My code is attached.  Pin 30 is just a dummy pin. I have an Uno and Duemilanove so I don't have a pin 30.  Apparently -1 will work as a dummy pin as well, but I haven't tested this.
2  Using Arduino / Project Guidance / Re: MIDI output in Laser Harp Project on: March 05, 2014, 06:09:39 pm
Awesome,  I am glad to see it working for you.

A boolean is just another variable type like an integer or float.   A boolean simply holds a true or a false value.

In the if statements the && is a logical AND.

thus if I had two boolean variables A and B and I only wanted "some code" to run when they were both true I might write somthing like this:

Code:
if(A && B){
//Some Code
}
3  Using Arduino / Project Guidance / Re: Servo jtter - found a low level workaround - do i understand this? on: March 03, 2014, 10:19:38 pm
I don't intend to derail the power supply discussion as that is often a crucial issue with hobby servos, but I had a very similar issue on a servo driven robotic arm I made a few years back.  The servos were set up correctly, but would present extreme jitter and move uncontrollably throughout their entire range when I tightened all of the joints, but would behave themselves if things were loosened.

What you need to remember is that servos inside are running a PID loop to determine the correct next motion to reach your desired position.  PID loops are great controllers but they must be tuned for the particular dynamics of your system to work well, and this is something that is not possible with typical hobby servos which come preprogrammed for an average case. 

In my case, some infinitesimal motion would cause a derivative term spike (the D in PID) (if you haven't had calculus, think of the derivative as the slope of the line on a graph where position is the Y axis and time is the X axis) the controller would see this and kick the motor in the other direction to stop the change and keep the motor in position, because there was a lot of elastically hung mass this kick would take a fraction of a second to start the mass swinging before the PID controller would see the effect its action had.  Oh... but now it was going way too fast the other way so the controller gives it an extra hard kick in the opposite direction and like a terrible driver it keeps over-correcting back and forth and causes extreme jitter and metaphorically crashed into the ditch.

If you can control the PID tuning variables this is easy to correct by decreasing the D term, but when they are preset your best bet is to either switch servos or alter the dynamics of your system so that they do not produce this kind of positive feedback.  If you can do this by tightening or loosening joints or changing the weight distribution of the load that may be your best option once you have ruled out a power supply issue.

If this doesn't solve it you could use your Arduino to manually read the encoder, control the motor through a typical motor driver, and run your own PID loop with the PID library.  This gives you the ultimate control, but it is a lot more work than simply using a hobby servo.
4  Using Arduino / Project Guidance / Re: MIDI output in Laser Harp Project on: March 03, 2014, 09:51:40 pm
Aah simplicity!

Yes, you were right to be confused by the midi messages as I had them switched around in my mind, so my comments are backwards and some of the variables are thus named in confusing ways. 

Your new code looks good, but you would need to do the same exercise of adding a boolean variable to prevent continually triggering the note.  To add more notes you would add more sensor pins and more sets of if and else statements with the midi note number changed for each one. 

There are of course nifty ways to do this with for loops and arrays, but that is what made the other code so confusing, and copy and paste is comparatively quite easy.  The for loop might save a little program space if you are doing lots of notes, but you would need to write a LOT more code before that became an issue.
5  Using Arduino / Project Guidance / Re: MIDI output in Laser Harp Project on: February 28, 2014, 10:01:44 pm
Yep, I thought that would be the problem. 

This is a very normal type of operation on the Arduino.  What you need to do is store a boolean (true or false) value that represents the last state of the key.  Then you can see if there has been a change and take the appropriate action.  When there hasn't been a change you do nothing.

So...

Before the setup function add a line like this one to declare the Boolean variable (assume true = playing, false = not playing)

Code:
boolean Key1LastState = false;

Then
Code:
if (activeSensor == -1) {
    MIDI_TX(128,40,127);
  } else {
    MIDI_TX(144,40,127);
  }

Turns into

Code:
  if (activeSensor == -1 && Key1LastState == false) {
    // In this case we have a new key pressed for the first time
    MIDI_TX(128,40,127); //Play the note
    Key1LastState = true; // Set the lastState variable
  } else if (activeSensor != -1 && Key1LastState == true) {
   // In this case we have a new key released for the first time
    MIDI_TX(144,40,127);  //Stop the note
    Key1LastState = false; // Set the lastState variable
  }

2 Notes about the above code:
1. I am away from the Arduino IDE right now, so this is uncompiled (error prone code).  If it won't compile look for a typing error first.

2. I know there are simpler ways to write the logic checks in the if statements, but these are the most readable for newcomers.

Oh, and thanks.  I am glad I could help.  This thread has given me a chance to use some of what I just learned in a synthesizer class I took this past January.
6  Using Arduino / Project Guidance / Re: MIDI output in Laser Harp Project on: February 26, 2014, 10:42:15 am
OK, the first error message is due to the fact that NOTE_G3 was somthing that noteplayer defined.  We don't use that note declaration anymore so you can just eliminate the line that causes the error.  At this point it looks fairly stupid to use an entire defined type to keep track of the sensor pin, but let's just go with it.

So delete: sensor[0].note = NOTE_G3;

Now for the note player error, this is caused because you forgot to do what you listed in your post:
Quote
------------------------------------------------------------------------------------------------------------------------------
notePlayer.play(sensor[activeSensor].note)         replaced by      MIDI_TX(144,40,127)
------------------------------------------------------------------------------------------------------------------------------

Now it complains that status is undefined, so all we need to do is copy that declaration from the marimba code to your code:

Code:
unsigned char status;

And do something similar for the definition of midichannel

Code:
#define  midichannel 0;   

Both of these lines should go before the setup function.  At this point it should compile and be ready for actual testing.
7  Using Arduino / Project Guidance / Re: MIDI output in Laser Harp Project on: February 24, 2014, 05:30:54 pm
On a request for further clarification: 

To start I would make a copy of the laser harp sketch as that is the framework that you hope to modify.

Then to start the modifications you need to replace each notePlayer method with an equivalent from the marimba sketch. 

Here are the ones I saw on a quick scan through.

notePlayer.begin(SPEAKER_PIN);  can simply be replaced by a Serial.begin(57600);

notePlayer.stop() could be replaced with the line that stops a note on the midi marimba:  MIDI_TX(128,40,127);

notePlayer.play(...) could be replaced with a simple: MIDI_TX(144,40,127);

In the last example I made it play only a single note # 40 for testing, you should be able to add more notes once you get this working.  I made the velocity the constant 127 because you won't naturally get a velocity from a laser harp.

Copy in the Transmit MIDI function from the bottom of the marimba sketch

Remove the #include <Tone.h>,  and the Tone notePlayer

At this point you should have something fairly close to what you need.  There may be a few leftover variables floating around and such, but it should get you close.  At this point you may find that repeatedly sending the same note over and over again does not work well with the midi synth, but you should be able to hear something. 

See if you can get to this point and post code for however far you got along with a description of what happens.  From there I or someone else should be able to help further.

8  Using Arduino / Project Guidance / Re: Music/Light Show Box, Feasibility Questions on: February 01, 2014, 06:46:14 pm
That's fair.  The effect of harmonics and random noise will vary by the exact song you use.  If you make your own music you could likely find something that would give you a clear correspondence between the FFT result and the audio you are hearing.  You may have particularly good results with synthesizers and other electronic sounds where you can control the harmonics of the instrument.  I would start by looking at the spectrogram of various songs.  If you can easily see something interesting on the spectrogram then you stand a chance of interpreting the music into light.
9  Using Arduino / Project Guidance / Re: Mouse with arduino on: February 01, 2014, 06:38:12 pm
It is quite feasible, but the answer depends on the choice of Arduino.  Do you have one already or are you looking for suggestions?

The Teesy would be the best choice as you can change the board to act like a mouse in the IDE.  http://www.pjrc.com/teensy/td_mouse.html  It is also possible with other Arduinos (like the current Uno) that don't use an FTDI chip to handle the USB, but it is a bit more complicated. 

I assume you have some method for sensing movement in mind.  I don't know if you would be able to recreate a laser mouse very well, but a ball mouse or a mouse that used some other way of sensing motion would be quite doable.
10  Using Arduino / Project Guidance / Re: Music/Light Show Box, Feasibility Questions on: February 01, 2014, 05:55:36 pm
Detecting multiple frequencies at one can be done with something called the Fast Fourier Transform (FFT) and its cousin the Fast Harley Transform (FHT).  http://wiki.openmusiclabs.com/wiki/ArduinoFHT  The basic Arduino Uno can do a reasonable FFT on audio, but you also need to make a special circuit on the input side.  If you really want to do this well you might look into one of the faster Arduino varients like the Due.

The issue you will run into is that most songs have a lot of every frequency as most instruments produce a lot of harmonics we don't consciously hear.  You could likely make something that resembles the visualizer in your favorite audio player, but not much more and you certainly would have a hard time separating parts. 

If you will have a limited selection of songs, I would make the Arduino  trigger the sound playback via something like this https://www.sparkfun.com/products/12000  and have a pre-programmed light show that you would make on your PC in advance.  A carefully designed light show would likely look much better than anything that is algorithmically generated.   
11  Using Arduino / Project Guidance / Re: Locking mechanism for secret drawer. on: February 01, 2014, 05:44:25 pm
If you are using a standard battery or voltage source you cannot "give something too much Amps."  Ohm's law says that the current (Amps) will be equal to the Voltage divided by the resistance.  You define the voltage, the Arduino defines the resistance, and the current just happens.  You can give the Arduino Vin pin 9V at up to 50mA or 9V at up to 1000A and it won't make any difference because the Arduino will only draw what it needs.  The current you see on the power supply is simply the maximum it can deliver before the voltage starts to sag.

That said, definitely do not place a resistor in series with the Arduino power supply, as that could mess things up royally.

The one caveat to this is that if you have something like a large motor sharing the same power supply as the Arduino the motor could cause voltage spikes or sags in the power supply line.  The diode others have mentioned will prevent the spikes while a large capacitor placed on the voltage supply line near the Arduino would get rid of the voltage sags.  This is more for reference and you should be good with just the diode.
12  Using Arduino / Networking, Protocols, and Devices / Re: Single Wire Interface Between Two Arduinos on: January 31, 2014, 05:17:13 pm
Great thanks,

I had though of One-Wire, but I didn't know of a slave library.  I'll give it a look and see if it will work for what I need and how much work the libraries would take to integrate.

I had not though of buffering the built in serial hardware.  To make this method completely robust I would have to make a system that guarantees that both chips won't try to drive the line at the same time.  This shouldn't be too difficult as I should be able to have the master initiate all communication and poll the slave regularly.  I'll have to see if I have any buffer chips floating around.  I don't suppose the Software Serial library would let me do this inside of the chip by swapping pin modes?

Now I just need to finish some of my other projects so I have two free boards to prototype.
13  Using Arduino / Networking, Protocols, and Devices / Single Wire Interface Between Two Arduinos on: January 31, 2014, 01:44:51 pm
I am working on a project that is going to has two parts, a fixed part and a rotating part.  Rather than going into a deep description here you can check out our website that details the project if you need or want to know more.

http://www.calvin.edu/academic/engineering/2013-14-team9/index.html

I want to minimize the number of wires that must cross the rotating to fixed break.  I plan to use a carefully managed coiled or flexible cable to make this connection.  I can't use a typical slip ring because there needs to be a 10.5 inch diameter hole for light to shine through around the center of rotation. 

If I can get this cable down to 3 conductors it will make things easier and give me some more options (like coiled headphone cables.  There will be an ATMEGA328 on each side of the break that can handle all of the local actions including motor driving and encoder reading, but I need to connect them in some way.  If I can get the cable down to 6V, GND, and one signal line that would be ideal. 

Does anyone know of an existing library that could connect two Arduinos with only a shared ground and one signal line?  I could write my own protocol loosely based on the CAN bus if I had to, but I would love to avoid this if possible.  The data rate could be very low(100 bits per second would be sufficient) but it must be bidirectional (Though it will clearly be half-duplex).
14  Using Arduino / General Electronics / Re: Desktop power supply on: January 28, 2014, 03:34:14 pm
I don't have any idea if the motors are the right size or not, but I can define kv for the general knowledge of all involved.

kv defines how many rpm the motor will spin per volt of applied power.  A higher kv motor will need a smaller prop so that it can spin faster with less resistance.   A low kv motor can spin a larger prop.

Judging the overall power of brushless motors is hard.  You can try to use specs like current, size, kv, and weight to get a sense of the motor power, but in the end it is usually a bit of an educated guess.  Usually as long as you are close you can adjust your prop size and pitch to make things work with your exact motor KV. 
15  Using Arduino / General Electronics / Re: Crazy parts prices on: January 28, 2014, 02:38:44 pm
This is definitely typical in the world of wholesale electronics.  I worked for a summer in part sourcing, and pricing fluctuations like these are a huge concern.  They tend to be driven by supply and demand at the component and material level.  Factories tend to make parts in batches, and one large order can deplete the world's supply until another batch is made driving prices up.  Things can also happen at the macro-level much like floods in Thailand disrupted the supply of HDDs a few years back.

Where I worked, we would try to beat this by negotiating long term pricing for 3 years by guaranteeing a given long term demand to the supplier.  Of course this is only an option when you are using more than 10-100K of a part annually and not for us lowly hobbyists.  Some suppliers have been known to change part prices multiple times each day.  Specifically TTI(Mousers parent) and Avnet are known to adjust prices very often.
Pages: [1] 2 3 ... 18