Show Posts
Pages: 1 2 [3] 4 5 ... 25
31  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?
32  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. 
33  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.
34  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.

35  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.
36  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.
37  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? 
38  Using Arduino / Programming Questions / Re: Changing ISR's return address to a function's memory location? on: April 25, 2014, 10:42:28 am
... my read_voltage function relies on lower level interrupt priorities such as the Timer compare register match interrupt and ADC conversion complete interrupt to complete it's work.
Can you tell us more about how that works?
39  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 18, 2014, 11:04:53 am
Code:
  float slope = (float)(readings[1]-readings[0])/(readings[3]-readings[2]);
That is going to give you a float of the finished integer operation inside the parens.
Indeed.  It casts the expression inside the parentheses as float.  The parentheses, though, don't wrap the whole expression - they wrap only the numerator.  With the numerator cast as float, the division is carried out in floating point.
Quote
1/5 would give 0.0 not 0.2.
I get a different result.  Here's test code:
Code:
void setup() {
  int readings[] = { 0, 1, 0, 5 };
  Serial.begin(115200);
  float slope = (float)(readings[1]-readings[0])/(readings[3]-readings[2]);
  Serial.println(slope);
}
void loop() {}
Here's output:
Code:
0.20
as expected.
40  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 18, 2014, 07:25:04 am
... dealing with the issue of zero ... help with this?
  • Calcualte the denominator
  • Check to see if it's zero
  • If it is, do something appropriate
  • Otherwise, proceed as usual
"Something appropriate" might be printing a message, like, "Look out! It's gonna blow!"  or maybe shutting something down. or maybe just printing "undefined" instead of printing a number.
41  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 17, 2014, 05:21:37 pm
Here's what I think:
Code:
  float slope = (readings[1]-readings[0])/(readings[3]-readings[2]);
This line calculates the value of the slope.  All of the variables on the right hand side are integers, so the compiler does the whole calculation using integer math, yields an integer result, and dutifully assigns that integer to the float variable slope.

To fix this, you can cast either the numerator or the denominator of the fraction as float, like this:
Code:
  float slope = (float)(readings[1]-readings[0])/(readings[3]-readings[2]);
A purist might cast both as float.

Here's what else I think:
  • You should address the issue of a denominator of zero, as noted above.
  • You should use code tags to post your code.  Any number of confusing things can happen when you don't.
  • You should read "How to use this forum ..., " posted as the first entry in all the many forums.

Finally, please note that you've declared slope twice:  once as a global int, and once as a float local to loop().  I don't see that you ever use the global variable.  You probably don't want it at all.
42  Using Arduino / Audio / Re: arduino FHT on: April 06, 2014, 08:17:17 pm
Quote
Bit 0 = 1:  <wrong stuff snipped>
That is not correct. MUX3...0, the lower 4 bits of ADMUX, select ADC channel 0-8, ...
Indeed, that is not correct.  Edited the original post, using strikeout to leave a trail.

Thanks.
43  Using Arduino / Audio / Re: arduino FHT on: April 06, 2014, 06:40:58 pm
when i assign ADMUX = 0b010000001; this means that i use ADC1  ...
Checking it against the description of register ADMUX in the datasheet:
  • Bit 7 = 1, Bit 6 = 0:  This combination selects reference mode 2, which is described in the datasheet as, "reserved."  I don't know how the reference will behave, but it's likely that it won't do what you expect.
  • [Edit: Delete this, because it's incorrect] Bit 0 = 1:  This selects ADC channel 0, not ADC channel 1.
So, it's not surprising that it doesn't tell you about ADC channel 1.  Maybe that's what you used, or maybe you copied it wrong.  

If you want help, you should probably post some code.  You should tell us what you expected, and tell us what happened instead.  Your code should be a small sketch that illustrates the problem, rather than long stretches of code that are largely irrelevant to your question.
44  Using Arduino / Programming Questions / Re: SPI MISO-MOSI arduino on: April 02, 2014, 07:10:51 am
I think that this bit of code doesn't do what you expect:
Code:
byte data2 = shiftIn (SOMI, SCLK, LSBFIRST);
data2 = (data >>8)& (0XF);
data2 is a byte; it's only 8 bits long.  When you right-shift it by 8 bits, there's nothing left.  After this operation, data2 will always be 0.  Is that what you wanted?
45  Using Arduino / Audio / Re: Best anti-aliasing filter to use for sampling audio on arduino? on: April 01, 2014, 07:39:18 am
TI filter app ... seems to select filter parameters, but doesn't actually tell you anything about how to built the filter in hardware?
I think you're talking about WEBENCH.  When you see the list of filter types at the bottom of the page, push a green "Select" button on the right side of the table.  That'll take you to a schematic.  If you haven't logged in to TI, it'll make you do that first.
Pages: 1 2 [3] 4 5 ... 25