Show Posts
Pages: [1] 2 3 ... 25
1  Using Arduino / Audio / Re: MCP4922 problem on: August 27, 2014, 08:50:40 am
The MCP4922 datasheet says the output channel is selected by the most significant bit of the input message.  Here's the datasheet, with the message structure described on page 24:  http://ww1.microchip.com/downloads/en/DeviceDoc/22250A.pdf.

To switch to channel B, try changing this:
Code:
msg1=msg1 | 0b01010000;
to this:
Code:
msg1=msg1 | 0b11010000;
2  Using Arduino / Audio / Re: Frequency Detection on: August 25, 2014, 08:53:47 am
I am interested in creating various visual effects based on analog audio signals. I started by trying to detect pitches in the chromatic scale for the frequency range of a 22-fret guitar in standard tuning:
A lot of people have posted on this forum intending to build a guitar tuner with an Arduino Uno, and using the FFT for automatic pitch detection. I haven't seen anyone report success.  If you're going to do pitch detection this way, you'll have to be ingenious.

Quote
82.4 (E2) - 1174.7 Hz (D6) ...
... sampling rate ... ~2350 ...
Accurately identifying 1174 Hz with a sample rate of 2350 Hz will be challenging.  The Nyquist criterion says that the sample rate has to exceed twice the frequency of the highest frequency signal component with significant content, not the highest frequency that you're interested in.  2350 is pretty close to twice 1174, so doing this detection will take a nearly perfect brick-wall filter.  You'll need a higher sample rate, and an aggressive filter.  Forum member pito has identified an eighth-order single-chip elliptical filter family that uses switched capacitors, whose cutoff frequency depends on either an external capacitor or an external clock signal.  The datasheets can be reached from here: http://www.maximintegrated.com/en/datasheet/index.mvp/id/1899.

Quote
I keep running into resolution limitations for low frequencies due to frequency bin size.
The resolution of the FFT can be improved with parabolic interpolation.  Here's a description from a guy at Stanford:  https://ccrma.stanford.edu/~jos/parshl/Peak_Detection_Steps_3.html.  The idea is that an input signal whose frequency doesn't exactly match a specific FFT output frequency will show up spread over several adjacent FFT output values.  It's estimated by identifying a local peak in the bins, and fitting a parabola to the the peak and its two adjacent values, calculating the axis, and calling that the estimated frequency.  I've never tried it with the FFT, but it has worked for me with YIN.  Note, though, that the input values to the interpolation are completely different kinds of objects than the output of the FFT.  You may get different results.

Quote
The first referenced project doesn't use YIN.  It estimates pitch by examining the time between zero-crossings with the highest slope.  That's going to have a high error rate, because guitar harmonics aren't precisely integer multiples of the fundamental - their phase rotates with regard to the phase of the fundamental, so they contribute their slope to the sum at varying points in the cycle.  As for what the error rate might be, I can't say.  It might be entirely acceptable.

Quote
I would also like to detect the fundamental frequency of strummed chords, and this method seems vulnerable to complex signals.
YIN isn't applicable to polyphonic signals.  It looks for a near match between one segment of the input and another segment some time later, and uses the time interval between those two segments as the inverse of the frequency.  If a signal has two components of roughly equal amplitude at, say, 1 Hz and 1.5 HZ, YIN will estimate the frequency at the least common multiple, 3 Hz.

If you mean that you want to identify the lowest component of the signal, you're in for a bit of a challenge: chord components can easily be within a minor third of one another, overlapping in the FFT output enough to confound parabolic interpolation.  If you want to do that reliably, I think you'll have to look at multiple cycles at fine resolution.  

You don't say that you hope to identify individual strings in a polyphonic signal.  If you do, that's a lot of work.  Here's an Apple patent on that process:  https://www.google.com/patents/US8592670?dq=8592670&hl=en&sa=X&ei=Y3_5U_buBZW2yATqj4Jo&ved=0CB0Q6AEwAA.  It's feasible with an iPhone, running at more than a gigahertz, with gigabytes of storage; less feasible on an Arduino.  
  
Quote
I'm beginning to wonder whether the Arduino is up to the task ...
Think a bit about how much latency you can tolerate.  The Arduino can be persuaded to do interesting things if they don't take too much memory, but they sometimes take a long time.  I've gotten reliable frequency identification for guitar-like signals in the 80-880 Hz range using YIN, but it takes about 150 milliseeconds to identify a string on the low end of the range.  That's way too much latency if I'm trying to control a MIDI device, as the output would be always a sixteenth note behind the rest of the band at 100 beats per minute, but it's OK for other things, like identifying the frequency for a tuning application.

Quote
I'm looking at my $20 chromatic tuner and wondering how it can do this for so cheap
One thing to consider is that it doesn't do it all that fast.  150 milliseconds is practically imperceptible in that application.  Another is that the tuner may use application-specific ICs to do its work.  Here's a link to the only one I can find, quoted at about 6.5 USD in 10K lots:  http://www.tuneric.com/literature.html.

Edit: grammar and spelling
3  Using Arduino / General Electronics / Re: Is it possible 7490 is skipping number on 7 digit display? on: August 17, 2014, 11:43:58 pm
Post your code, maybe?  And maybe a schematic? 
4  Using Arduino / Audio / Re: FFT with DUE and TFT on: August 13, 2014, 11:29:37 pm
The example runs, but only at a buffer size of 2048. If I try to change it in the libraries, the DUE does nothing.
If you could tell us, specifically, what you did to change the array size, it might lead to a solution.
5  Using Arduino / Programming Questions / Re: MATHS help reqired for HSI project. on: August 13, 2014, 10:44:24 pm
After a few tries, I still can't grasp what you're trying to do.  It looks like this:
  • read an accelerometer,
  • make some calculations, and
  • turn on some neopixels based on the results.
Beyond that, I'm befuddled.

Here's something, though it's almost certainly not the primary problem.  In the sketch, I find this in loop():
Code:
  x, y, z = attitude();
and this in attribute():
Code:
  return (x,y,z);
It looks like that code is intended to return three values from attribute().  That won't work - C++ allows a straightforwared return of only a single value from a function.  I'm fairly certain that code doesn't do what's intended.  The function appears to work, because the values x, y and z are global values, and they're directly modified in attribute().  But, they're not returned to loop(); in fact, only z is returned.  To see it break, use local variables rather than global inside attribute(), return them, and watch what happens to the values of the first two variables.

I can't be certain, but I don't see any evidence that you've tested the various tasks that you're trying to program separately.  Things like:
  • reading the accelerometer, printing the results to the terminal, and confirming that they match the expected results based on the accelerometer's orientation
  • running calculations on known test data rather than the accelerometer's output, printing those, and observing that the results are what's expected, and
  • running the display routines on known test data, and observing that the expected lights come on while the others stay off.
As things stand, there could be problems - maybe more than one - with any of those tasks.  If you test in smaller pieces, there will be fewer hurdles to get past in order to help.  Right now, we have to decipher the post - something I haven't been able to do - analyze the program, find the libraries, analyze them, and get up to speed on this particular accelerometer.  The list of people who will do that is a short list; I'm not on it. 

Can you post a minimal sketch that compiles, and illustrates a specific problem, and then describe specifically what you expected, and what you got?
6  Using Arduino / Audio / Re: FFT with DUE and TFT on: August 07, 2014, 10:00:42 pm
How is the analog signal connected now?  Your question about an op amp or diode suggests that there may be a problem with that connection.  Please be specific.

The Due doesn't want a 5V input - it wants something between 0V and 3.3V.  See the warning on the product page, here:http://arduino.cc/en/Main/ArduinoBoardDue.

Running the FFT with calculated data will eliminate uncertainty about the analog input.  I'd suggest getting it working with known data before trying to integrate it with analog acquisition.  I'd also recommend acquiring and printing raw analog data, to make sure that you're getting the analog inputs you expect, and get that working before trying to integrate it with the FFT.

You can get by without an op amp, but, as far as I know, a diode won't help you.  The canonical method for connecting a bipolar analog signal to an analog input is to use a voltage divider connected between 3.3V and 0V, and capacitively couple the input signal to the midpoint of the divider, and take the analog input from that point.  That method provides no protection for the input, though - it'll be up to you to make sure that the input signal doesn't go out of range.  

You seem to have access to a signal generator.  Those usually have a DC offset that you can set to 1.65V, and it will still be up to you to set the amplitude to avoid a signal excursion outside the safe range.  

Finally, I don't see anything about the frequency of the input signal, and I don't see anything controlling the analogRead() frequency other than the time it takes to get a reading.  If your input frequency is low, and the analogRead() speed is fast, you might be seeing only part of the input cycle, with weird results.
7  Using Arduino / General Electronics / Re: 220VAC to 12DC on: August 03, 2014, 09:03:44 am
... I need something smaller ....
Maybe you'd like to elaborate on what "smaller" means, and tell us what other requirements you have?  This process goes faster if we don't have to guess.
8  Using Arduino / General Electronics / Re: Reduced phone ringing voltage on: July 13, 2014, 12:47:59 pm
I think that you want a circuit that signals the Arduino when the phone rings.

A schematic of a gizmo called a "ring detector" from Velleman is attached.  Here's a link to the product page, where you'll find a link to the user manual, the source of this schematic:  https://www.vellemanusa.com/support/downloads/?code=K8086.  The manual is long on assembly instruction, and short on theory.  Note that Velleman's blurb for this device doesn't mention any regulatory approvals, so I presume it has none.  Proceed at your own risk.

The device blinks an onboard LED, and optionally operates an onboard relay.  Power for the relay coil comes from an offboard power supply, presumably because it takes more current that can be surreptitiously drawn from the phone line.  That supply doesn't appear to come standard with the device.  I don't think you want a relay output, anyway, so you can do without it, and without the circuitry that drives it.  You can replace everything to the right of the red line with a pullup resistor, an input pin's internal pullup resistor, or, as has been suggested in this thread, a retriggerable one-shot multivibrator.  You can do without the LED, if you don't need a visual indication.

The purpose of 1M resistor R1 escapes me, but it limits current to microamps, so it almost might as well not be there.  A purist might omit it.  As a phone technician, you'll know a lot more about the possible effects of that resistor on the system than I will.  Maybe you can illuminate?

I have previously believed that ringing voltage was supplied by reversing the polarity of TIP and RING. Today, I'm not so sure.  You'll know, though, and you can use that information, along with knowledge of transients that Might appear on phone circuits, to select the right voltage rating for capacitor C1.

Otherwise, the circuit looks OK to me.  Capacitor C1 blocks DC, so there's no current when the line is on-hook.  The back-to-back zener diodes block current when the AC peak voltage is below 20V, so there's also no current when the phone is off-hook.  he full-wave rectifier ensures that it's balanced, and will operate when TIP and RING are reversed.  The only time the circuit conducts is when the phone rings.  The phone system used to ring electromechanical bells, with coils and switches, so I'd expect that it can deal with considerable chaos during ringing, and I wouldn't expect it to be annoyed by anything this circuit could do. 

Alternatively, you could just buy one of these devices.  Amazon has them for about 23 USD, and I've seen a price of about 11 pounds, exclusive of VAT, on a UK site.
9  Using Arduino / Programming Questions / Re: Modify the PWM Output frequency. on: July 11, 2014, 01:26:58 pm
You stopped reading too soon.  It also says,
Quote
Varying the timer top limit: fast PWM
Both fast PWM and phase correct PWM have an additional mode that gives control over the output frequency.
This part of the tutorial specifically addresses changing the PWM frequency.
10  Using Arduino / Audio / Re: Elektret Micophone on: July 06, 2014, 01:45:17 pm
You don't describe your level of experience with the Arduino, or with electronic circuits in general.  I'm going to make a guess about both of those, based on your earlier posts.  Please pardon me if I describe things that seem elementary to you.

For the convenience of others reading this thread, I'm attaching the schematic from the referenced "instructables" posting.

I'd recommend checking the amplifier's DC conditions.  First, I'll repeat two earlier recommendations:
  • Power the circuit from the Arduino's 5V.  The purpose of that is to make sure that the amplifier's output voltage doesn't exceed 5V.  If the amplifier output voltage gets above the level of the Arduino's power supply, it could damage your Arduino.
  • Make sure that the ground of the amplifier circuit is connected to the Arduino's ground.  If the circuit's current doesn't have a way to return to the Arduino's power supply, it won't operate.
Here's how to check the DC output level:
  • Remove the electret from the circuit.  The purpose of that is to make sure that voltage readings won't be affected by sounds in the room, so that we can read the DC voltages in peace.
  • Measure the voltage at the collector of Q1.  That will be the junction between the transistor and the 10K resistor R3.  By my calculations, that should be between about 0.8 volts and 1.3 volts, depending on the actual DC current gain of your particular transistor.
  • If you don't have a voltmeter, then connect the collector of Q1 to analog input A5, and run your program.  Again, by my calculations, you should see analog readings between about 125 and 170, depending on the actual transistor characteristics.
I haven't built the circuit; my calculations could be wrong.  

If you don't get those values, something's likely to be askew.  In that case, I'd recommend disconnecting the amplifier circuit completely, and testing the analog input with the Arduino's onboard 3.3V source.  Connect the 3.3V pin to analog input A5, and run your program.  That should give readings of about 675.  If that test fails, something's certainly askew.

As DVDdoug aptly says, the value 4685 is bigger than any value that the ADC can register.  I don't see any way that your program could show that reading, so I'll presume that it's a typing error.

[Edit: spelling]
11  Using Arduino / Audio / Re: Elektret Micophone on: July 05, 2014, 10:00:08 am
Are you using the output coupling capacitor, called "C2" in the instructables schematic?  That capacitor is intended to block the DC component of the output signal.  The ADC needs to see that DC component, because it can't read voltages below zero.

Here's my suggestion for what to try next:
  • Power the circuit from the Arduino's 5V supply.  Be sure to connect the circuit ground to the Arduino ground.
  • remove C2 and connect the output of the transistor, "Q1," to the analog input.
  • Try it again.
12  Using Arduino / General Electronics / Re: Minimising power consumption on soil hygrometer sensor on: July 03, 2014, 08:13:10 am
How often do you typically need to water those plants?  I'd think that a sample frequency of, say, ten times the watering frequency should be adequate.  To get a visible indication, you might to capture the state of the monitor's output at the end of the measurement cycle - maybe in a continuously-powered CMOS memory element - and use that, along with the 0.4 Hz astable multivibrator that you already have, to blink an LED.   Or, if it suits you, you can enable the indication with a button, so it'll only flash when you ask it.
13  Using Arduino / Audio / Re: Lightning Detection on: July 02, 2014, 11:00:39 am
If you want to get pictures of lightning, an audio input won't be effective as a trigger.  Unless the lightning strike is right on top of your system, the stroke will be over before any sound reaches it. 

You mention a surveillance system.  What kind of thing is that?  Is it specifically intended for lightning detection?
14  Using Arduino / Programming Questions / Re: ds3231 and time libraries on: June 29, 2014, 09:05:43 pm
With elegantly economical prose, jremington said,
That is not helpful. Can you provide a link?

I concur.  A google search for "arduino," "library," "ds3231" yields a huge array of hits.  I'm not willing to try and guess which one you picked.

At this link - http://forum.arduino.cc/index.php?board=4.0, the entry into the "Programming Questions" section of this forum, you'll find, at the top of the list of posts, an entry entitled, "How to use this forum - please read."  Please read it, follow the link, and do what it suggests.  In particular, these entries from item #11, "Tips for getting the most out of your post," are particularly relevant to your question:
  • Mention which Arduino you have.
  • Post a complete sketch (program code)! If you don't you waste time while people ask you to do that. However, with coding problems, if possible post a "minimal" sketch that demonstrates the problem - not hundreds of lines of code. If the problem goes away in the minimal sketch, it wasn't where you thought it was.
  • If you get an error, post the error (copy and paste). Not just "I got an error".
  • If you are using a library that does not come with the IDE (in other words, you downloaded it from somewhere) please post a link to this library.
[emphasis mine]

I think that it would be a trivial effort for you to name your Arduino, post a short sketch that illustrates your problem, post the errors, and post a link to the library. 

Figuring out what's wrong with your code can be a lot of work.  We'll help, if you'll do most of it. 
15  Using Arduino / Programming Questions / Re: ds3231 and time libraries on: June 29, 2014, 02:51:53 pm
What time libraries are you talking about?
Pages: [1] 2 3 ... 25