Show Posts
Pages: 1 2 [3] 4 5 ... 25
31  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 11, 2014, 05:13:33 pm
I did some things ...
I don't see a description of what you did.  A schematic would help.

Can one suggest a ready to use solution if there is one?
Here's what I use: a cheap homemade circuit to connect the audio output of the PC to the Arduino.  A schematic is attached.  The Thevenin equivalent of the voltage divider is a 10K resistor and a 2.5V DC supply.  10K is suitable for an analog input, as described in the datasheet.  Note that there's nothing in series with the analog input.  I've verified that my PC won't output a 5V peak-to-peak signal, so I don't worry about overdriving the analog input.  You may prefer to use two 10K resistors, and a 5K in series, for an equivalent impedance of 10K, with the 5K providing a measure of protection for the analog input.  This scheme isn't really suitable unless the input is stiff enough to drive the equivalent impedance of the voltage divider; otherwise, the signal level will drop.

I added a 100K resistor to ground from the signal input.  That's because I suspect that the audio output is capacitively coupled, just like my input.   Without the resistor, the DC voltage between the two capacitors is essentially undefined.  Because I'm using an electrolytic capacitor, and I presume that the audio output does, too, I add the resistor to keep the DC level between them at ground, and make sure that the capacitor polarities are proper.  I can't say that it's necessary; I just like having it in the circuit.

Advantages are that it's cheap, easy to build, and I can define the analog input quite precisely by generating my own audio content.  The primary disadvantage is that it doesn't lend itself to real-world inputs:  The input impedance is so low it would pull down most guitar inputs, and it has no protection from analog overvoltage, as you might get from an amplifier output intended for a speaker. 

Criticism is welcome.
32  Using Arduino / Programming Questions / Re: interrrupt with timed LEDs on: May 09, 2014, 11:06:21 am
This:
Code:
pinMode(ledPins[0], OUTPUT);
pinMode(ledPins[1], OUTPUT);
and this:
Code:
Serial.begin(9600);
never go in the same sketch.
i don't see the conflict.  As long as neither of ledPins[0] and [1] are 0 or 1, what goes wrong?
33  Using Arduino / General Electronics / Re: Measuring AC mains on: May 09, 2014, 10:33:51 am
Here's an application note from Atmel on this very subject:  http://www.atmel.com/Images/Atmel-2566-Single-Phase-Power-Energy-Meter-with-Tamper-Detection_Ap-Notes_AVR465.pdf.  They use a voltage divider on the power line, capacitively coupled to a DC voltage divider at the analog input, and the AVR's power supply is earthed.  I'd say that scheme is a bit delicate for connection to a power line.  A resistor in series with the analog input, with a couple of diodes to the supply voltages, would go a long way toward protecting that input from transients. 

The app note also describes controllable amplifier for the current input, since the dynamic range of the current levels that a meter will see is very wide.  You may not need that, if you don't need a lot of resolution at low current. 

What are you going to do with this data?  That'll affect which solutions might work for this project.
34  Using Arduino / Project Guidance / Re: PWM arduino uno problem? on: May 06, 2014, 11:45:30 pm
Can anybody tell me how to calculate duty cycle?

The Wikipedia article is reasonably clear, and not too complex.  http://en.wikipedia.org/wiki/Duty_cycle
35  Using Arduino / Programming Questions / Re: Changing ISR's return address to a function's memory location? on: May 05, 2014, 04:45:41 pm
I see this as a solution to the problem of synchronizing ADC readings.  I admit, though, that my understanding of the OP's goal is kind of fuzzy.
  • Set the ADC to auto-trigger on external interrupt 0
  • Set a timer to run at the appropriate frequency
  • Set that timer to deliver a PWM output
  • Connect that PWM pin to external interrupt 0 on both Arduinos
The datasheet says that the ADC prescaler is reset when the ADC is auto-triggered by an event, to assure a fixed delay from the trigger event to the start of conversion.  That will ensure that the samples taken by the two Arduinos are in sync to within what I'd expect to be a couple of system clock cycles, without intervention from the program.  Without some kind of active synchronization of ADC readings, they'll drift apart quite quickly, due to the difference in the frequencies of the two ceramic oscillators.

If the intent is to make power measurements on a single-phase circuit, I think that taking readings of current and voltage alternately on a single Arduino would be accurate enough.  Fiddling with a unity power factor calculation, close to full scale, in Excel, I get an error of about 0.1% by reacting alternate readings as if they were taken simultaneously.  Interpolating one set, I get about the same results.  That seems to be plenty accurate for a metering application, but there's no guarantee that's what the OP is up to.
36  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 04, 2014, 08:41:07 pm
OK.  If you don't have the FFT and display program working yet, you probably want to start on them.  Eventually, you'll process an array of analog data with your FFT code.  You can start now, using test data.

I'd like to know if anyone has built a working tuner on the Arduino based on the FFT.
37  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 02, 2014, 06:16:08 am
I think I will talk to my  master and coment about your solution ...
Please do. 

Once you capture the signal, how do you intend to process it?  After you process the signal, how do you intend to show the user whether he's in tune, and which way to tune?
38  Using Arduino / Audio / Re: Testing a new sound sensor. on: May 01, 2014, 05:32:21 pm
Here's a page with some reviews of what appears to be the same product:  http://club.dx.com/reviews/text/135533.  From what the reviewers say, the output is unamplified, and the single integrated circuit on the board is a comparator rather than an amplifier.  Conventional wisdom says you need amplification on the order of 100X with an electret, on a 5V system.  In order to use it meaningfully, you will probably have to add an op amp.  You can see how sparkfun did it, here - https://www.sparkfun.com/datasheets/BreakoutBoards/Amplified-Mic-v10.pdf
39  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 01, 2014, 01:10:56 pm
These statements -
  • ... my [knowledge] in electronic is really bad.
  • In this [project] the [guy] allows to use the op Amp of my preAmp (TL071).
  • My project should in one [month] and I'm really ... in a hurry!
- make me wonder if this a school project.  Is it?
40  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: April 30, 2014, 05:58:06 pm
With an output impedance of 1K for the preamp, a simple voltage divider should work as an offset circuit.  Here's a way to do it:
http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/.
Some things to think about with regard to that circuit:
  • It's not necessary to use a potentiometer to adjust the DC offset level, if you're willing to live with some inaccuracy in your DC offset.
  • This scheme uses 100K resistors in the voltage divider.  The ATMega328 datasheet suggests an input resistance of 10K or less to ensure that the input capacitors on the ADC have time to charge fully.  The equivalent DC input impedance for this circuit is 50K.  There might be some impact on accuracy.  You could use lower-value resistors, but not too low - you don't want to load down the output of the preamp.  A couple of 20K's would yield an equivalent DC input resistance of 10K.
  • I'd add a high-value resistor - maybe 100K - between the hot leg of the audio input and ground.  If the output of the preamp is capacitively coupled, as I suspect, then that point won't have a well-defind DC voltage.  I can't provide a good theoretical justification for that, though; my bias is strictly intuitive.
So for sure I need another circuit?
Not absolutely for sure.  That preamp could be anything; there's no way to guess its output characteristics.  It might have a nicely-biased audio + DC output, centered at 2.5V, just waiting to be hooked to an Arduino, but I doubt it - it'd be an odd preamp.  I'll go out on a limb and say, yes, for sure you need another circuit.  Doing otherwise risks damaging an analog input to your Arduino, or damaging the the IC generally. 
41  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: April 30, 2014, 01:41:26 pm
First things first:
The preamp output is probably centered at ground, meaning that it's negative with respect to ground some of the time.  A negative voltage on an analog pin can damage your Arduino.  You'll need an input circuit to offset the input signal so that it doesn't go below ground.   We'd need to know the output impedance of your preamp to describe an appropriate input circuit; maybe that's listed in the specs somewhere.
42  Using Arduino / Programming Questions / Re: Problem with retrieving the same value multiple times from program memory on: April 28, 2014, 02:44:37 pm
Checking all the messages with this statement:
Code:
Serial.print(strlen(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[i])))));
shows a longest length of 16, for "Room photo limit", menu_2, menu_table[2].  The minimum size of the array that would contain it is 17, allowing for the string-ending 0x00 at the end.  So,
... the longest string is not more than 15 characters long ...
is off by a couple, but I'd expect that a buffer sized at 20 would work.  I sized it at 17, and it worked; sized it at 16, and I got quirky output, but it ran; sized at 10, again odd output, but it ran.  But, I'm running a simple test program - if I overwrite some RAM, it's not so likely that it'll do something to mess up the program flow.

With the longest output string needing only 17 characters, a buffer size of 20 ought to work.  If increasing the buffer size worked, I suspect that something else is afoot, and that it's still lurking in your code.  Maybe you're using the buffer someplace else, where it's too small. 

I'll ask that you do this:  Start with your code, and delete stuff and add stuff until it looks more or less like the code I posted.  What I want most is that the string definitions you're using right now survive into the reduced program unchanged.  Then check and see if it works.

43  Using Arduino / Programming Questions / Re: Problem with retrieving the same value multiple times from program memory on: April 28, 2014, 07:51:05 am
... copy the string to a char array and print that to the LCD ...
I'm pretty sure that's what happens here, quoting from the OP's sketch:
Code:
lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(menu_table[2]))));
and in the code the OP complains about:
Code:
lcd.print(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));

strcpy_P() seems to copy a C string from an address in program memory to an address in RAM.  The first argument is a pointer to a RAM buffer, and the second is a pointer to a character array in program memory.  Best I can tell, strcpy_P() returns the address of the destination, just like strcpy().  So, I think the code moves data from program memory to RAM, and then lcd.print()'s from RAM.  That's what seems to happen when I Serial.print() it.

As for whether Serial.print() distinguishes between character pointers to RAM and to program memory, it appears to me that it doesn't.   Here's test code:
Code:
prog_char menu_0[] PROGMEM = "Sensitivity";

char buffer[40];  // Plenty big

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println("From program memory:");
  Serial.println(menu_0);

  Serial.println();

  Serial.println("From RAM:");
  Serial.println(strcpy_P(buffer, menu_0));

  Serial.println();
  Serial.println();
  delay(100);
}
Using strcopy_P(), the output is, "Sensitivity," as expected.  Using a pointer to program memory, the output is blank.  Because menu_0 likely points to unused RAM, I think it could print just about anything.
44  Using Arduino / Programming Questions / Re: Problem with retrieving the same value multiple times from program memory on: April 27, 2014, 10:55:07 pm
I tried it, using Serial rather than lcd, and it just printed the expected results over and over.  Test code appears below. 

Maybe something funny is going on in lcd, but I don't see it.  Or, maybe something's wrong with the code you're not showing.  My personal favorite crystal-ball guess is that buffer is declared somewhere as a character pointer, or it's declared as a character array that's too small to hold the message, and strcpy_P() overruns the buffer and writes into other memory locations.  You didn't show that part of the code, though, so it's just a guess.

I'll suggest that you write a minimal sketch that demonstrates the problem you're trying to solve, using Serial rather than lcd.  I think you'll get more participation if you post something that compiles, and doesn't make us assemble hardware to try it for ourselves.  I think you'll also get more help if you make the effort to isolate the problem to a short, compilable sketch, so that we don't have to pore over miles of code, or write our own code to get your snippets to run.

See the sticky post, "How to use this forum - please read," at the top of this forum listing.  In particular, see item #11, where it says, among other things,
Quote
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.

Test code follows.  I deleted a whole bunch of declarations that aren't relevant to the posted code.
Code:
prog_char menu_0[] PROGMEM = "Sensitivity";
prog_char menu_1[] PROGMEM = "Room photo cut";
prog_char menu_2[] PROGMEM = "Room photo limit";
prog_char menu_3[] PROGMEM = "OS photo cut";
prog_char menu_4[] PROGMEM = "OS photo limit";

prog_char msg_0[] PROGMEM = "Not Used";
prog_char msg_1[] PROGMEM = "Saving....";

PROGMEM const char *menu_table[] = {
  menu_0, menu_1, menu_2, menu_3, menu_4
};

PROGMEM const char *msg_table[] = {
  msg_0, msg_1
};

char buffer[40];  // Plenty big

void setup() {
  Serial.begin(115200);
}

void loop() {
 
  for (int menuOption=0;menuOption<=6;menuOption++) {

    Serial.print(menuOption);
    Serial.print(": ");

    if(menuOption == 3){
      Serial.print(strcpy_P(buffer, (char*)pgm_read_word(&(menu_table[2]))));
      Serial.print("  ");
      Serial.println(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));
    }

    if(menuOption == 4){
      Serial.println(strcpy_P(buffer, (char*)pgm_read_word(&(menu_table[3]))));
    }

    if(menuOption == 5){
      Serial.print(strcpy_P(buffer, (char*)pgm_read_word(&(menu_table[4]))));
      Serial.print("  ");
      Serial.println(strcpy_P(buffer, (char*)pgm_read_word(&(msg_table[0]))));
    }

    if ((menuOption < 3) || (menuOption > 5)) {
      Serial.println("No message.");
    }

    delay(100);
  }
  Serial.println();
}

Sample output:
Code:
2: No message.
3: Room photo limit  Not Used
4: OS photo cut
5: OS photo limit  Not Used
6: No message.

0: No message.
1: No message.
2: No message.
3: Room photo limit  Not Used
4: OS photo cut
5: OS photo limit  Not Used
6: No message.
45  Using Arduino / Programming Questions / Re: Changing ISR's return address to a function's memory location? on: April 25, 2014, 10:16:36 pm
I don't quite follow. 
... (read_voltage) wants to be called on each external interrupt. I'm doing it this way as my read_voltage function takes ADC reads using the timer compare match functionality which relies on interrupts of lower priority.
It looks like you've set up free-running analog conversions, controlled by Timer0.  At the same time, it sounds like you want to start a conversion when external interrupt 0 fires. 

Have I got that right? 
Pages: 1 2 [3] 4 5 ... 25