Show Posts
Pages: [1] 2 3 ... 13
1  Using Arduino / Programming Questions / Re: issue with custom class on: January 21, 2014, 06:13:55 pm
hmm. well odd thing happened. Finally got chance to go through this again, and on a whim used a different arduino with exact same code, It fixed the problem. Wiring exactly the same, except it was a Leonard instead of a DUE. works perfect now, no setup change. Very strange.
2  Using Arduino / Programming Questions / Re: issue with custom class on: January 06, 2014, 12:25:55 pm
He's using analogRead, so he's got the pin numbers right.  Although I think A0 and A1 would still work.  I think analogRead can handle either way.

I knew those changes wouldn't fix your current problem, it was just some tips for the class as a whole. 

You say when you unplug one they still both go up.  What is the analog pin connected to when it is not plugged to the mic?  Nothing?  That would be a floating pin and you'll never explain why you get any particular reading out of a floating pin.  I'm no expert on hooking up microphones so I don't know if they need to be pulled to ground or anything like that, but it's starting to sound like hardware.  If the crosstalk was in the software, I would expect to see the same numbers for both mics every time.  But that isn't the case.  Maybe the crosstalk is on the wires. 

when I was unplugging I just unplugged A0 and A1 one by one, left ground in then plugged them back in, so A0 was in and A1 was out then A0 was out and A1 was in-- just to see if both mics were working. They both seem to pick up sound on separate pins, but the values are crossing somewhere.
3  Using Arduino / Programming Questions / Re: issue with custom class on: January 03, 2014, 05:36:41 pm
tried to implement those changes, no luck.


main.ino
Code:
#include "mic.h"

 
Mic micOne;
Mic micTwo;

void setup()
{
   Serial.begin(9600);
   micOne.setPin(0);
   micTwo.setPin(1);
}
 
 
void loop()
{
   micOne.setMicLevel();
   Serial.print(micOne.getMicLevel());
   micTwo.setMicLevel();
   Serial.print(", ");
   Serial.println(micTwo.getMicLevel());
}

mic.h
Code:
#ifndef MIC_H
#define MIC_H

class Mic {
  public:
    Mic();
    int pin;
    void setPin(int);
    void setMicLevel();
    double getMicLevel();
    double volts;
    static const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
  private:

};

#endif

mic.ino
Code:
#include "mic.h"

Mic::Mic(){
  volts = 0;
}


void Mic::setPin(int _pin) {
 pin = _pin;
 Serial.print("pin set to: "); Serial.println(pin);
}

void Mic::setMicLevel() {
   unsigned long startMillis= millis();
   unsigned int peakToPeak = 0;   // peak-to-peak level
   unsigned int signalMax = 0;
   unsigned int signalMin = 1024;
   while (millis() - startMillis < sampleWindow){
      unsigned int sample = analogRead(pin);
      if (sample < 1024) {   // toss out spurious readings
         if (sample > signalMax) {
            signalMax = sample;  // save just the max levels
         }
         else if (sample < signalMin) {
            signalMin = sample;  // save just the min levels
         }
      }
   }
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   volts = (peakToPeak * 3.3) / 1024;  // convert to volts
}

double Mic::getMicLevel(){
  return volts;
}

4  Using Arduino / Programming Questions / Re: issue with custom class on: January 03, 2014, 05:23:13 pm
I can't see the problem in that code.  Maybe it is wiring or hardware?  Are the mics as close together in real life as they are in the diagram?  Maybe they're both picking up.


I will add a couple of comments about your class though I don't think they're causing this problem they'll save you a couple of pitfalls later with the code.

I would make the variable sample local to the setMicLevel method.  It's not used anywhere else and that method will be updating the value and then just leaving you with the last value it read as a member.  I don't think that will be very useful so why keep it around. 

The other thing I would do is move the global sampleWindow into the class.  I guess you made it global so all Mic objects have to share the same value.  Have a look at the static keyword.  You can put it in the class and make it static and all objects will share the same value.  You can even have static methods to get and set the value.  It doesn't really affect the performance of this sketch so much, but it's always good to encapsulate things together if they go together.  Otherwise every time you use this class you'll have to remember that you need to declare that variable. 

Also, it's not clear whether this is the case or not, but all the code in the last window of the prior post should be in a .cpp file in the folder with the .h file.  From the first post it looks like it might be in a .ino.  Maybe I'm reading it wrong, but just in case. 

mics are definitely not close enough to pick up each other with that kind of sensitivity, so its not that. I can unplug one and blow into it and it turns both up, then plug it back in and unplug other one (separate pins) and do same and both numbers go up. So it seems to be something in the code.

that last file is a .ino file, so yeah I think pretty much the same.

I am currently changing those suggestions around too, thanks for advice.
5  Using Arduino / Programming Questions / Re: issue with custom class on: January 03, 2014, 04:30:36 pm
hmm, found one global that should have been moved to class, but still no luck:

Code:
#include "mic.h"

const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
//const int threshold = 0.07;
 
Mic micOne;
Mic micTwo;

void setup()
{
   Serial.begin(9600);
   //pinMode(11, OUTPUT);
   //pinMode(12, OUTPUT);
   micOne.setPin(0);
   micTwo.setPin(1);
}
 
 
void loop()
{
   micOne.setMicLevel();
   Serial.print(micOne.getMicLevel());
   micTwo.setMicLevel();
   Serial.print(", ");
   Serial.println(micTwo.getMicLevel());
}

mic.h:
Code:
#ifndef MIC_H
#define MIC_H

class Mic {
  public:
    Mic();
    int pin;
    unsigned int sample;
    void setPin(int);
    void setMicLevel();
    double getMicLevel();
    double volts;
  private:

};

#endif

Code:
#include "mic.h"

Mic::Mic(){;
  volts = 0;
}


void Mic::setPin(int _pin) {
 pin = _pin;
 Serial.print("pin set to: "); Serial.println(pin);
}

void Mic::setMicLevel() {
   unsigned long startMillis= millis();
   unsigned int peakToPeak = 0;   // peak-to-peak level
 
   unsigned int signalMax = 0;
   unsigned int signalMin = 1024;
   // collect data for 50 mS
   //
   while (millis() - startMillis < sampleWindow){
     //Serial.println("test");
      sample = analogRead(pin);
      //Serial.println(sample);
      if (sample < 1024) {   // toss out spurious readings
         if (sample > signalMax) {
            signalMax = sample;  // save just the max levels
         }
         else if (sample < signalMin) {
            signalMin = sample;  // save just the min levels
         }
      }
   }
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   volts = (peakToPeak * 3.3) / 1024;  // convert to volts
}

double Mic::getMicLevel(){
  return volts;
}
6  Using Arduino / Programming Questions / issue with custom class on: January 03, 2014, 04:09:46 pm
I am writing a class that filters out some values, for better readings and its having some issues. The original sketch works perfect with one mic, but alas I need several, so I am starting with two and hence need a class.

here is the original:
Code:
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
 
void setup()
{
   Serial.begin(9600);
   pinMode(12, OUTPUT);
}
 
 
void loop()
{
   unsigned long startMillis= millis();  // Start of sample window
   unsigned int peakToPeak = 0;   // peak-to-peak level
 
   unsigned int signalMax = 0;
   unsigned int signalMin = 1024;
 
   // collect data for 50 mS
   while (millis() - startMillis < sampleWindow)
   {
      sample = analogRead(0);
      if (sample < 1024)  // toss out spurious readings
      {
         if (sample > signalMax)
         {
            signalMax = sample;  // save just the max levels
         }
         else if (sample < signalMin)
         {
            signalMin = sample;  // save just the min levels
         }
      }
   }
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   double volts = (peakToPeak * 3.3) / 1024;  // convert to volts
 
   if(volts > 0.16){
    digitalWrite(0, HIGH);
   }
   else { digitalWrite(0, LOW); }
   Serial.println(volts);
}

and here is the one with classes I am writing now:

main.ino:

Code:
#include "mic.h"

const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
const int threshold = 0.07;
 
Mic micOne;
Mic micTwo;

void setup()
{
   Serial.begin(9600);
   //pinMode(11, OUTPUT);
   //pinMode(12, OUTPUT);
   micOne.setPin(0);
   micTwo.setPin(1);
}
 
 
void loop()
{
   micOne.setMicLevel();
   micTwo.setMicLevel();
   Serial.print(micOne.getMicLevel());
   Serial.print(", ");
   Serial.println(micTwo.getMicLevel());
}

mic.h:
Code:
#ifndef MIC_H
#define MIC_H

class Mic {
  public:
    Mic();
    int pin;
    void setPin(int);
    void setMicLevel();
    double getMicLevel();
    double currentMicLevel;
    double volts;
  private:
    unsigned long startMillis;
    unsigned int peakToPeak;   // peak-to-peak level
    unsigned int signalMax;
    unsigned int signalMin;
};

#endif

mic.ino:
Code:
#include "mic.h"

Mic::Mic(){
  currentMicLevel = 0;
  volts = 0;
}


void Mic::setPin(int _pin) {
 pin = _pin;
 Serial.print("pin set to: "); Serial.println(pin);
}

void Mic::setMicLevel() {
   unsigned long startMillis= millis();
   unsigned int peakToPeak = 0;   // peak-to-peak level
 
   unsigned int signalMax = 0;
   unsigned int signalMin = 1024;
   // collect data for 50 mS
   //
   while (millis() - startMillis < sampleWindow)
   {
     //Serial.println("test");
      sample = analogRead(pin);
      //Serial.println(sample);
      if (sample < 1024)  // toss out spurious readings
      {
         if (sample > signalMax)
         {
            signalMax = sample;  // save just the max levels
         }
         else if (sample < signalMin)
         {
            signalMin = sample;  // save just the min levels
         }
      }
   }
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   volts = (peakToPeak * 3.3) / 1024;  // convert to volts
}

double Mic::getMicLevel(){
  return volts;
}

I am getting some really weird output from it that doesn't seem to make sense here is idle reading:
Code:
0.15, 0.18
0.14, 0.15
0.19, 0.17
0.15, 0.14
0.11, 0.16
0.15, 0.18
0.17, 0.22
0.17, 0.13
0.20, 0.15
0.14, 0.17
0.14, 0.21
0.19, 0.23

then a reading from when mics are peaking:

Code:
3.30, 3.29
3.29, 3.30
3.30, 3.30
3.30, 3.30
3.29, 3.29
3.30, 3.29
3.30, 3.30
3.29, 3.30
3.30, 3.30

Problem is that they seem to both be linked, when one goes up they both do, in example above I am blowing into only one mic.

here is how I have it wired:
7  Using Arduino / General Electronics / Re: Using VIN at 9v makes high pitch sound on: December 31, 2013, 07:13:08 pm
Dosn't sound right to me either.
What is the arduino connected to? Are you sure it is the arduino?
Are you sure that it is DC comming from your wall supply and not AC?

its definitely DC. arduino isn't connected to anything, I disconnected everything to isolate it and make sure I wasn't doing something silly.
8  Using Arduino / General Electronics / Re: stepping down 12c AC to 6v AC in small space on: December 29, 2013, 05:26:05 pm
Hmm, tricky, induction motors are very inductive.  Yes a power resistor would be
bulky since it needs to dissipate the heat.  A transformer is still the obvious solution...

are there transformers that can fit in that small of an area? I have about 1/2inch to fit components
9  Using Arduino / General Electronics / Re: stepping down 12c AC to 6v AC in small space on: December 29, 2013, 04:37:23 pm
What are the power or current requirements?  If the load is constant a resistor might be
enough.

here is what I am powering https://www.dropbox.com/s/z1sbkxll448xqu2/2013-12-28%2013.29.33.jpg
its a motor, and behind it I have a rectifier so I can run 2 LEDs. There used to be a lightbulb but it burned out, and I am assuming that dropped the voltage roughly 6v, so I have to compensate for it else the motor gets very hot.

problem with resistors is I would need something like a 5w+ resistor which I have only seen HUGE version of, maybe I am missing something? Those are a bit big for what I need.
10  Using Arduino / General Electronics / stepping down 12c AC to 6v AC in small space on: December 29, 2013, 04:22:32 pm
I don't have the room to put a transformer in since space is small and need to drop 12vac to 6vac in a safe way (this will be on top of a christmas tree). I did some research and seems zener diodes are the way to go, however I am not sure how this would work with AC, how to connect them or even what ratings to look for. Any help would be greatly appreciated, thanks!
11  Using Arduino / General Electronics / Using VIN at 9v makes high pitch sound on: December 28, 2013, 01:43:32 am
I am splitting 9v from wall transformer to VIN and I get a high pitch sound coming from arduino, doesn't sound right. Any idea what could be causing this? Multimeter tells me I am definitely getting 9v.
12  Using Arduino / Audio / Re: talk detection on: December 23, 2013, 06:14:52 pm
You need more gain so maybe a two stage amplifier is required.

hmm, alright --don't know much about them though, wouldn't even know where to begin. I did build this one http://www.instructables.com/id/Arduino-Audio-Input/

would it be something similar with two op amps? and could I even build that and connect it to my arduino mic so I don't need larger mic?
13  Using Arduino / Audio / talk detection on: December 23, 2013, 05:48:47 pm
I've tried several things to get arduino to detect talking like the mic breakouts and building my own opamp and plugging a more sensitive mic into the opamp, but none seem to be able to detect low enough levels that is talking.

anyone have any suggestions?
14  Using Arduino / Audio / Re: Control Arduino by sound on: December 18, 2013, 11:26:21 am
Sorry for double-posting, but I am having problems with my circuit.

I bought all the parts needed for the circuit posted earlier (http://circuitdiagram.net/simple-mic-pre-amp-based-lm358.html), except no potentiometer since I don't need one, and a LM386N instead of an LM358.

However, my microphone has 3 wires and not 2. I've read that the two-wire mics have the power and output linked together. Does anyone know if it is it possible to make a preamp with these parts? Or do I have to build a different circuit with different parts?

When first learning something new I usually aim high so I can progress more quickly, but this time I may have bitten off more than I can chew. smiley-red I've been researching for several hours now, but can't find anything conclusive (that I can understand anyway), so I don't want to finish a circuit only to fry everything. I don't have enough money to buy a ton of replacement Arduinos and components, so I'd rather get it right the first time.

Thanks to anyone that can help!

that 3rd wire might be phantom 48v volts. depends on the mic-- you might have to supply it with extra boost.

http://www.dt4u.com/jpg/phantom.jpg
15  Using Arduino / Installation & Troubleshooting / Re: Serial port already in use. on: December 14, 2013, 12:19:20 pm
I am assuming its because leonardo continues to read serial even when window is closed
No, that doesn't make sense.  "Serial port in use" is on the PC side, not the Leonardo's side.

If you load Blink on the Leonardo and keep trying to reload it, do you still get the serial port in use?

Yeah, I wrote that with the Uno and Mega in mind.  The Leonardo is different.  Although, it would be good to use lsof to find out what is holding the port open (something has to be).

nope, like i mentioned earlier, it only happens when I have serial communication it seems, simple sketches like blink don't seem to have an affect.
Pages: [1] 2 3 ... 13