Show Posts
Pages: 1 [2] 3 4 ... 6
16  Using Arduino / Sensors / Re: Help with signal conditioning on: November 29, 2012, 09:39:19 pm
This is another test.
The 16 values moving average of the derivative was calculated on the fly by the Arduino.
It appears that it stays 0 when there is no activity, picks up immediately when I blow on the sensor and drops immediately when I stop blowing, remaining negative or 0 for most of the decay.

The interval between the time th signal begins fading and the moving average reaches 0 (at about 3.7 seconds) is 111 ms.

So far, it's the most reliable signal of sensor activation I found.

Thanks again!

P.S. On the plot I multiplied the value of the moving average by 50 so to be able to superimpose it to the actual signal.

17  Using Arduino / Sensors / Re: Help with signal conditioning on: November 29, 2012, 02:33:33 pm
Thanks for the quick and thorough reply.

I'll test your code and post the results!

I have the results.

The graph did not show well because there are two bands at 0 and 100 but it looks like we are getting something. The 16 values running average of the derivative in particular seems to pick up nicely when the signal is increasing or decreasing or staying relatively steady.
I am attaching the spreadsheet itself so you can take a look.

Thanks for your help
18  Using Arduino / Sensors / Help with signal conditioning on: November 29, 2012, 01:43:34 pm
Hello All,
  I am not sure if my problem has a hardware or software solution but any help will be appreciated.

I am experimenting with the Modern Devices Wind Sensor:

in the attempt to make a midi wind controller with Arduino.

The sensor is very responsive and has a nice resolution BUT, a very slow decay time.
In other words, when you stop blowing, the output takes several second to reach baseline.
If I take the output at face value, my instrument would keep playing for several seconds after I stop blowing.

I am attaching a graph I obtained by plotting analog read vs. time.
In the upper graph I gave four quick "pulse" breaths, in the lower one I did a sudden start, steady blow for a few seconds and sudden stop.
As you can see, in either case it takes up to 10-15 seconds to go back to baseline.

The topic has been discussed a few month ago @ modern devices forum but without a real solution, and my fiddling with software (since I am a total newbie when it comes to electronics) didn't carry me very far.

Since I suspect this is hardly a unique problem, I wonder if somebody can point me to a software algorithm or an hardware solution to obtain nice square waves (sharp attack, sustain and, what's missing here, a sharp release).

Thank you

19  Using Arduino / Sensors / Re: Capacitor Value for Capacitive Touch Sensor on: November 28, 2012, 09:12:01 am
The value is by no means crucial - probably anything from a few hundred pF upto 0.1uF will work fine.  Note that this circuit isn't protected from static discharge.


BTW I was vaguely aware of the static discharge issue, is it a real problem? How would I protect from it, I cannot ground the touch sensors, can I? That would make the thing not work.

Thanks again
20  Using Arduino / Sensors / Capacitor Value for Capacitive Touch Sensor on: November 27, 2012, 10:03:09 am
Hello all,
  I am experimenting (successfully) with a capacitive sensor I found here:

I have a quick question: in the tutorial it says "... a capacitor of 1nF is recommended in line with the pin to decouple 50Hz noises."
It just occurred to me that in the U.S. the AC frequency is 60 Hz.
Would a different value capacitor work better?
If so, which value?



21  Using Arduino / Programming Questions / Very quick question about byte and int. on: November 22, 2012, 12:01:14 pm
I noticed that a lot of example sketches that I download from here or elsewhere use int type constants and variables instead of byte even when byte would be enough:

const int LED = 13 ;  // 13 is < 256, byte would be enough

With an 8 bit MCU I would think using byte would be better (faster and half the memory) than int.

My question is: is there a drawback in using byte rather than int or, putting it in another way, an advantage using int instead of byte when byte is enough?

22  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 22, 2012, 11:51:18 am
Thanks guys,
   I read your posts several times and I think I understand your solutions.

While I am not arguing that "my" solution is either more elegant or more proper, I am arguing it is more practical because:

1) It involves one data file (.hh) instead of two (.h and .c)
2) can be used with variables and constants
3) allows the first dimension to be [] and therefore the sketch can calculate the size at execution time without knowing it at coding time.
4) No need to keep the three files synchronized (that's really a corollary of #3).

Please correct me if I am wrong.

Thanks again, I'm learning a lot.
23  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 04:38:51 pm
I posted an example for you earlier.

You should never declare a variable in a .h file - that's so un-c that it will get you fired in most places. Declaring a variable in .h files creates localized global variables at each inclusion of those .h files.

Instead, declare the variable in the .c file and if such variables are to be referenced somewhere else, "extern" such variables.

Yes, thank you. I saw your earlier post but I did not fully understand that, sorry smiley

So, the example I just asked Nick about is not correct because I AM declaring the variable in an .h file?


P.s. I'm glad I am not a programmer, finding a job these days is a pain ....
24  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 04:34:54 pm

So, if I understand correctly:

In a separate file called mydata.h  I put:

const int data [] [2] = {
// and so on...

} ;

(assuming it's small enough to fit in RAM)

And then in the main sketch I put:

#include "mydata.h" ;

Is it that simple?
That would have the additional advantage that I can put several arrays in the same file (if I need them) and just use an #include in the main sketch.

What about the mentioned extra .cpp file?

25  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 04:07:49 pm
I don't like #includes in the middle of a declaration, personally. Why not just put the whole array into a separate file (including the declaration, and the trailing brace)?

I thought of doing something like that but I don't know how to do it  smiley-roll-sweat
Even thought of creating a "Library" but when I consulted the reference on how to do that I thought it was a bit of an overkill for my purpose.

Also, my way (well, the one I learned form a c++ forum) does not require two files (.h and .cpp) but just one: .hh  (and by the way, I have no clue of the meaning of the .hh extension ....) which would seem to me more practical.

But again, I don't have much experience and I would not be surprised if there were a better way. smiley

Come to think of it, is the .h and .cpp business the same as creating a library?
26  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 03:39:24 pm
Your idea of "large" and mine must differ.

It was probably a small test file just to demonstrate the problem... smiley

Indeed smiley
I made up a couple of quick text files, one with strings, the other with integers, to see if I could make the darn thing work!

And when I finally made it to work (again, I did not do anything different from last night, today it just worked) it also works with the "real" thing.

It turns out that I was able to reduce the actual table, by organizing the data in a different way to a mere 400 bytes or so, well below the RAM restrictions.

Small size still, probably by your (and my) standards. smiley-razz
27  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 02:55:28 pm
Your approach wouldn't work if multiple files make wants to reference the data in "numbers.hh".

Sorry, that I didn't understand.
Once I have my data in an array, I can reference that in the sketch, I won't need to reference "numbers.hh" anymore.

28  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 02:43:10 pm
That approach works if the data is referenced from one source file.

Yes, that was exactly my goal:
ONE file, separate from the sketch itself, containing all my data.

Besides, nothing would prevent me to use another #include for a different set of data:

static const int data[] [2] = { 
#include "E:\DataPath\numbers2.hh"

static const byte other_data[] [3] = { 
#include "E:\DataPath\other_numbers.hh"
29  Using Arduino / Programming Questions / Re: Importing a large lookup table - EUREKA on: November 21, 2012, 10:50:50 am
Ok, I think I did it.
I found a way to keep a large array of data in a separate text file and importing it in my sketch as an #include.
The advantages of doing that are:
-  you can modify and update your data file without touching the sketch.
-  you don't have to put an unsightly long declaration in your code.
-  you don't even have to re-verify your code after modifying the data but you have to re-upload it

I thought this was a fairly established thing to do but I could find hardly any documentation.
I am posting my solution here hoping it may be helpful to some other newbie.

/* This examples illustrates how to import numeric data from a separate Text file

   By Luca Brigatti - 2012
   witht he help of the folks in the Arduino programming forum.

   Note: Leaving the first dimension empty: data[][2]
   and using: sizeof(data)
   to calculate the size of the array in bytes eliminates the need to know beforehand
   how many values are there in the file.
   The operation: maxIndex = sizeof(data) / 4 - 1
   return the highest index number of the first dimension:  data[maxIndex][2]
   The denominator (4 in this case) is the product of the number of bytes per data type (2 bytes per integer)
times the size of the second dimension ([2] in this case)
   The text file being read: "numbers2.hh"
   contains something like that:
   // Example of bidimensional numeric data array
   // The actual numbers can be any int (if the data array is int)
  {4,}, // Second element here will be 0, Like:  {4,0},

Note: {,4},   i.e leaving the first place empty is NOT allowed. 

// Main importing instructions. data[][2] can be a variable
static const int data[] [2] = {  
// Put the name of the file with the complete Path
#include "E:\Downloads\Devices\Arduino\arduino-1.0.1\data\numbers2.hh"

int maxIndex ;
int arraySize ;

void setup() {
  Serial.begin(9600); // Initiate serial
  arraySize=sizeof(data);  // Gets the size of the array in bytes
  maxIndex = arraySize/4 - 1; // Size /2 (bytes in an int) /2 (for a bidimensional array) - 1 (as index starts at 0)  
  // Print dimensions of the array
  Serial.print("Array Size (bytes): ");
  Serial.println (arraySize);
  Serial.print ("# of rows: ");

void loop () {
  // Print all the data in the array, over and over again
  for (byte i=0; i<=maxIndex; i++) {
    Serial.print (data[i][0]);
    Serial.print (" , ");
    Serial.println (data[i][1]);
30  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 21, 2012, 09:58:53 am
I've never heard of a compiler producing random errors.
Incomprehensible, infuriating, annoying, yes. Random, no.

Perhaps random was not the right term, incomprehensible is better.

I was getting something like (I don't remember it verbatim and the error did not show up again, this morning):
variable char[] already defined
when I never defined a variable called char[].
In a previous sketch I had defined
char* data[]

Maybe there is some reason for it {the pointer was still in the computer/arduino memory ??) 
But if there is it is definitely not obvious  smiley-mad

Pages: 1 [2] 3 4 ... 6