Show Posts
Pages: 1 ... 102 103 [104] 105
1546  Using Arduino / Programming Questions / Re: serial driven robot on: December 27, 2011, 09:08:01 pm
and?
1547  Using Arduino / Programming Questions / Re: serial driven robot on: December 27, 2011, 09:04:44 pm
The loop() in the robot will never receive anything because you keep throwing it away with Serial.flush(). Remove that statement and try again.

Pete
1548  Using Arduino / Programming Questions / Re: HMC5843L Compass Chip simple programing question on: December 27, 2011, 07:39:32 pm
OK, how about enlightening me as to what you did to fix it. It might help others in the future too.

Pete
1549  Using Arduino / Programming Questions / Re: Problem with Arduino receiving two-byte serial data stream on: December 27, 2011, 06:05:03 pm
You should not flush the serial buffer because you don't know what has been received. You will be continuously throwing away a command character or data character.

Replace your loop() function with this:
Code:
void loop(void)
{
char cmd,value;

if(Serial.available()) {
cmd = Serial.read();
// If it's not a command character, ignore it and wait for the next one
if(cmd != 'T' && cmd != 'L' && cmd != 'B')return;
// got the command, now wait for the data char
while(Serial.available() == 0);
value = Serial.read();
// got the command and value, now do the command
switch(cmd) {
case 'T':
throttle = map(value, 0, 255, 70, 255);
digitalPotWrite(throttle, throttleSelectPin);
break;
case 'B':
brake = map(value, 0, 255, 70, 255);
digitalPotWrite(brake, brakeSelectPin);
break;
case 'L':
  lights = value;
  if(lights == 0)
  digitalWrite(lightsSelectPin, LOW);
  else
  digitalWrite(lightsSelectPin, HIGH);
  break;
  }
  }
 }

Pete
1550  Using Arduino / Programming Questions / Re: HMC5843L Compass Chip simple programing question on: December 27, 2011, 02:04:39 pm
Do you have a spec sheet for the HMC5843L? It would also help if you could point to some code that works - i.e. code that reads the compass and returns a heading in degrees. I can only find the HMC5843 online and it doesn't seem to work quite the same (or your setup code is wrong).
Also, the values returned by the compass for each axis may not be directions, but a measurement of the magnetic field in which case you have to calibrate your program to what the chip returns.

Pete
1551  Using Arduino / Programming Questions / Re: Code review on: December 25, 2011, 06:59:57 pm
FWIW, you could use this:
const unsigned char DEG = 223;

and this (%c instead of %s):
    sprintf(printbuf,"Water: %d%c", int(temp[BURNER_POST]), DEG);

which saves a whole byte  smiley-grin

Pete
1552  Using Arduino / Programming Questions / Re: HMC5843L Compass Chip simple programing question on: December 25, 2011, 06:50:52 pm
The specs that I found for that chip say that it returns a value from -2048 to +2047 inclusive. If 0 is zero degrees then I would replace this:
Code:
      if(x>0)
       {
          res = map(x, 0, 246, 0, 90);
       }
       else if(x<0)
       {
         if(x!=0)
         {
           res = abs(x);
           res = map(res,0,255,90,0);
           res = 270+res;
         }
         else
          res = 0;
       }

with this:
Code:
 if(x >= 0)res = map(x,0,2047,0,180);
  else      res = map(x,-1,-2048,360,180);

Pete
P.S. the map function returns an integer so you might as well declare res to be an integer as well.
1553  Using Arduino / Programming Questions / Re: Drifting in a for loop with digitalwrite on: December 25, 2011, 03:27:32 pm
I would try this with a timer interrupt.

Pete
1554  Using Arduino / Programming Questions / Re: Code review on: December 25, 2011, 11:25:44 am
Quote
Do you have a better suggestion?
Code:
const unsigned char DEG = 223;
unsigned char is 0-255.

Quote
I hope someone can give me a pointer to how to avoid having the strings in ram.
Look for PROGMEM which puts the strings in program memory. But they are accessed differently.

Pete
1555  Using Arduino / Programming Questions / Re: if else problem on: December 24, 2011, 07:35:16 pm
The semicolon at the end of this line:
Code:
if (inputPin == val );
terminates the if statement. So it means "if inputPin equals val, do nothing"

The loop() should be:
Code:
void loop()
{
 if (inputPin == val )
  {
    digitalWrite(ledPin, LOW);
  }
 if else (inputPin == val)
  {
    digitalWrite(ledPin, HIGH);
}


Pete
1556  Using Arduino / Programming Questions / Re: commenting out #define causes error on: December 24, 2011, 10:36:57 am
That problem and its solution should be a sticky!

Pete
1557  Using Arduino / Displays / Re: LCD line 1 wont display when SDcard not inserted on: December 23, 2011, 07:56:21 pm
My guess is that somehow the ChipDetect pin from the SD is also connected/shorted/shared to some part of the LCD display and when the card isn't inserted the CD pin goes low and grounds something. When the card is in, CD is high and all is well.

Pete
1558  Using Arduino / Sensors / Re: DHT11 Sensor on: December 23, 2011, 07:41:18 pm
Did you download and install the DHT library in the correct place?

Pete
1559  Using Arduino / Programming Questions / Re: Reverse geocache code on: December 23, 2011, 05:24:05 pm
Yup.
Code:
                if (stage == 5);
That semicolon is killing you! Get rid of it.

I also note that you have commented out the code which sets the location for stage 5.

Then there's this code (without the semicolon) which will grant access when you are at stage 4:
Code:
            /* Are we close?? */
            if (distance_meters <= RADIUS) {
                stage++;
                EEPROM.write(0, stage);
                if (stage == 5)
                {
                    Msg(lcd, "Access", "granted!", 2000);
                    servo.write(OPEN_ANGLE);
                }
            }

To grant access at stage 5 you need:
Code:
            /* Are we close?? */
            if (distance_meters <= RADIUS) {
                if (stage == 5)
                {
                    Msg(lcd, "Access", "granted!", 2000);
                    servo.write(OPEN_ANGLE);
                } else {
                  stage++;
                  EEPROM.write(0, stage);
               }
            }

Pete
1560  Using Arduino / Programming Questions / Re: Why does this stop after about 30 seconds? on: December 22, 2011, 10:47:34 pm
You set previousMillis1 and previousMillis2 in the loop() function and then set them again in Pin1() and Pin2(). If you had set them only in loop(), the program would have worked.

Pete
Pages: 1 ... 102 103 [104] 105