Show Posts
Pages: [1] 2 3 ... 13
1  Forum 2005-2010 (read only) / Troubleshooting / Re: How do I use AVR studio? on: October 07, 2008, 05:45:20 am
westfw, thanks for sharing that little nugget, lots of things just made all kindza sense for me.

techx, if you're not finding what you need here, the polite thing to do is thank people for their time trying to help and try something else.
2  Forum 2005-2010 (read only) / Troubleshooting / Re: Stereo Arduino (Help) on: September 18, 2008, 09:19:34 am
The other option is to adopt one of the sample-based audio players and let an interrupt handle updating the output on a regular (and fast) schedule.

The interrupt will need to handle two outputs instead of one, but with port manipulation, that shouldn't be an issue.

It's a bit daunting compared to your basic bit banging audio, so I've not tried it yet, but it's next on my list for my binaural compass widget... which only plays a single frequency beep at the moment.
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Cmps03 does not run... on: October 10, 2008, 01:22:33 pm
A few suggestions:

I've been using other I2C compasses, and you usually need to wait between the command and reading out the reply from the sensor. As it stands, I think you may be bombarding the sensor with commands and never giving it a chance to breathe.

Also, the wire library is a little quirky in how it handles the address of the sensor. If you look at the examples in the playground [edit: uh, the hmc6354 example in the playground seems to be gone, never mind, see below for another example], you will see that the address is usually modified before being used. This means that you are probably not talking to your sensor at all, or rather that it does not realize you are talking to it.

Putting those comments together, here is how I would do it:

Code:

#include <Wire.h>

#define CPMS03Address  0xC0
int slaveAddress;             // This is calculated in the setup() function

byte data[2];                        // This will hold the raw data from the sensor

int result;                    // This will hold the value that data represents

int i = 0;

void setup()
{
 
 // Shift the device's documented slave address (0xC0) 1 bit right
 // This compensates for how the TWI library only wants the
 // 7 most significant bits (with the high bit padded with 0)

 slaveAddress = CPMS03Address  >> 1;   // This results in the 7 bit address to pass to TWI

 while( millis() < 500) { delay(10); }  // The HMC6343 (for example) needs a half second to start from power up
 
 Wire.begin();

}

void loop()
{

 Wire.beginTransmission(slaveAddress);
 Wire.send(0x01);             // Send a "Get Data" command (e.g. (0x50 for the HMC6343)
                         // or the register number in your case: 0x01
 Wire.endTransmission();
 
 delay(2);                    // The HMC6343 needs at least a 1ms (microsecond) delay
                              // after this command.  Use whatever the data sheet says.

 // Read the 2 heading bytes

 Wire.requestFrom(slaveAddress, 2);        // Request the 2 bytes of data
 i = 0;
 while(Wire.available() && i < 2)
 {
   data[i] = Wire.receive();
   i++;
 }

result = data[0];
result |= data[1] << 8;

Serial.println(result);

}


I haven't tried that code and I don't have that sensor, so you may need to tweak it a bit, but at the very least you need that address trick to make it work, I suspect.
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Timers on: September 23, 2008, 10:59:54 am
I dunno, seems like a lot of effort for little reward, IMHO.

Let's see how bad the error is if you mismeasure the time by one millisecond using millis().

For one G acceleration, the error on speed for one mS error on time is not quite one cm/s, and the error on position is 5 microns. (9.8m/s/s for 0.001 second and 0.5*9.8m/s/s for 0.001 second squared, respectively)

Accelerometers are quite accurate for short durations, and position dead reckoning drifts not due to error on delta time but simply because of integration's tendency to amplify small errors over time.

IOW, I suspect you get much more inaccuracy from noise in the sensor than from the error on how long the measurement took.

If the measurement takes a lot less than a couple mS to be done, then you could perform X measurements, measurement how long that took and divide by X.

At the very least, I would see how much accuracy I got that way before trying to measure durations under the millisecond, since that requires extra work without necessarily helping much.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to make the LED react on input on: September 24, 2008, 06:14:42 am
Sorry to hear that, better luck on the next one!
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to make the LED react on input on: September 23, 2008, 05:12:42 am
So the arduino measures 0-5V just fine with the potentiometer, and you know you have 0.2V at the amplified microphone, but when you connect the two, the arduino measures 0?

(going to lunch, by the way, so I won't be able to reply for a bit)
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to make the LED react on input on: September 23, 2008, 04:54:34 am
Well, now we know that your circuit works to measure 0-5V signals.

This probably means that the signal from the microphone is too small relative to the 0-5V amplitude you are measuring, as Mike was saying earlier, I believe.

You will need to amplify it somehow. You should mention this to your professor as how to do this will depend on what parts you have available in class.
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to make the LED react on input on: September 20, 2008, 02:22:01 pm
You're welcome and good luck on Monday!  smiley-wink
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to make the LED react on input on: September 20, 2008, 05:06:37 am
It's normal to get a floating value if there is nothing connected to the pin when you read it (i.e. when you disconnected your microphone), so that is nothing to worry about. Odd values in the absence of a ground connection are also normal.

If you have a potentiometer (a variable resistance with a knob you turn to change the value), you could try to connect one end of it to 5V, the other to ground (the same ground as your Arduino) and to put the middle connection (the one with the changing value) to your microphone input.

You should be able to see the value in the serial monitor, with Mem's code running, go from nearly 0 to nearly 1023 as you turn the knob.

If you do not have a potentiometer, you can try the same thing with various pairs of resistors in series... something called a voltage divider.
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to make the LED react on input on: September 19, 2008, 07:26:40 am
What Grumpy Mike and Mem are trying to help you with is to print the values you are measuring out to the serial port. In order for you to see anything, you need to ask your computer to show you what the Arduino is sending it.

In the IDE (the software on your computer you use to send your programs to the Arduino) there is a row of buttons you must be using for this. There is one to compile, one to save and one to send the program to the Arduino. After that, last button on the right, there is one called serial monitor.

Try clicking on the serial monitor button just after you have sent Mem's code to your Arduino, and hopefully after a little wait you should see some numbers appearing in a new window. These numbers are the data measured by your Arduino.

Once this works, please tell us what those numbers are (an average value is fine, we don't need hundreds of samples).

Good luck!

11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Color change timer on: October 05, 2008, 05:06:31 am
Keep having fun with Arduino and pretty soon, this will all be second nature.  smiley-wink
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Color change timer on: October 05, 2008, 01:24:33 am
Hi Eclipsemints,

When you tried the red blink code by itself, it was the only thing in the main loop of the sketch... that is, inside void loop(). Anything inside void loop() will repeat forever, so in that case, the red link blinked.

When you moved it into your original code, it no longer repeats, because only the entire void loop() repeats. So you flash the various leds, toggle the red led once, and then immediately, either turn everything off if switchpin is high, and restart the loop or go straight to restarting the loop and if switchpin is low, start with cyan (light blue) in which the red led is off.

What you need to do is put the red blink code into its own loop, for example a while loop, which will continue looping as long as (i.e. while) switchpin is low.

Here is the reference for the while loop, see if you can change your code to put the red blink inside one, with the stay-in-loop-while-this-is-true condition (switchpin == low).

Good luck!  smiley-wink
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: Color change timer on: October 03, 2008, 03:23:39 am
Quote
     digitalWrite(ledPinB, output); //blink Blue LED
      output = !output;
      digitalWrite(ledPinG, output);  //blink Greene LED
      output = !output;
      digitalWrite(ledPinR, output);  //blink Red LED
      output = !output;

If you enter that sequence with output HIGH then blue is high, green is low and red is high and you exit with output LOW.

If you enter it with output LOW (e.g. looping around a second time), then blue is low, green is high and red is low, and you exit with output HIGH.

In other words, you always have either green on alone, or blue and red on together: green and purple.

If you want to cycle thru three states (blue, red and green) you need a state variable (e.g. output) that can hold three values, so not a boolean. For flexibility, you might want three booleans, one per LED.
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: manual control of a melody on: October 03, 2008, 04:58:53 am
Working from memory, there's a loop that toggles the audio pin high/low at a speed determined by the note (frequency) for a certain duration (actually a certain number of cycles depending on the frequency).

Sounds like you should change that loop's exit condition so that you stay in it until the next button press, rather than after a given number of cycles.

You may want to debouce that button press, tho.
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Binary sketch PROBLEM on: September 23, 2008, 11:04:18 am
Duncha hate it when the developer doesn't use a comma or a space for thousands and millions?  smiley-wink
Pages: [1] 2 3 ... 13