Show Posts
Pages: 1 2 [3] 4 5 ... 248
31  Using Arduino / Programming Questions / Re: Arduino Xbee flex sensors to servo motor communication problems on: August 20, 2014, 07:15:23 am
Try using print instead of println in the sending code. Look up what flush does too - it's likely not what you think. Alternatively, just get rid of it.
32  Using Arduino / Programming Questions / Re: Help with Serial parsing for GUI. on: August 20, 2014, 06:54:59 am
Why are you reading the serial port in the processData function at all? I'd expect that routine to be making decisions based on the data string it was passed; printing it and then ignoring it seems odd.
33  Using Arduino / Programming Questions / Re: set cursor was not declared in this scope on: August 18, 2014, 02:34:40 pm
The compile error may be related to which LiquidCrystal library you are using. Try using a different one.

Doesn't look like it - the first use of setCursor correctly uses an lcd object. The second doesn't.
34  Using Arduino / Programming Questions / Re: set cursor was not declared in this scope on: August 18, 2014, 09:43:21 am
Code:
  if (i==0) lcd.setCursor(16,0);
35  Using Arduino / Programming Questions / Re: Where can I learn programming for arduino? on: August 17, 2014, 07:58:55 am
Jeremy Blum's youtube tutorials often come up when this question is asked - disclaimer: have not watched them myself.
36  Using Arduino / Programming Questions / Re: [HELP!] Weird GPS data and micro SD card problem on: August 16, 2014, 06:19:44 am
Your GPSdata function only populates and returns struct A if there is data coming in from the gps. If there wasn't, which will often be the case because serial data transfer is slow, loop will pick up whatever happened to be on the stack and treat it as an instance of GPSstruct. As you see, that stack content is garbage.

You must ensure that GPSdata always returns a valid struct - make the return the very last line of the function. Make struct A global, or better, a static variable in GPSdata.
37  Using Arduino / Project Guidance / Re: Drink Mixer (precise liquid dispensing) on: August 15, 2014, 08:44:05 am
Here's a thread on the same topic http://forum.arduino.cc/index.php?topic=249364.0

There's a link in there to the drinkmotizer, which does the same job but uses linear actuators to work the optics rather than raising the glass.

Optics seem like a good solution - what's giving you pause there?
38  Using Arduino / Project Guidance / Re: Where do I begin? reading data from Weather Station and display it on: August 14, 2014, 08:36:52 am
Given the size of the data stream and the general paucity of RAM on most arduinos, I'd be inclined to to try parsing it field by field as you receive it. Serial data transmission is slow compared to the Arduino clock speed so you should have plenty of time. Given the age of your weather station, I'd expect the baud rate to be pretty low too.

As you read the serial stream, keep note of which field you're on so you know how big it is and whether you want it. If you do, copy it to a little buffer and call a routine to process it, which will likely consist of a switch statement controlled by field number.

Of course, if your sketch is simple enough, you may do just as well buffering a complete packet but the above method may help when you start adding features and use up your remaining RAM.

39  Using Arduino / Project Guidance / Re: where/how to place "blink without delay" on: August 14, 2014, 06:20:24 am
My apologies - it wasn't specifically directed at you - it was a general observation - we're all idiots on occasion.
40  Using Arduino / Project Guidance / Re: where/how to place "blink without delay" on: August 13, 2014, 07:36:04 am
In this case, once I realized that two independent BWD's would do the job I took the BWD example and did a bit of copy & paste - you can see the evidence in some of the variable names I lazily left unchanged.

At that point, the LED code was complete. From there it was just top down design & functional decomposition to complete the management of the pump i.e. I tweaked the ManagePump function and when I came to a bit I didn't immediately want to do, I assumed a function that would do what I needed so I could complete the one I was working on.

That assumed function turned out to be GetPumpInterval. It in turn assumed that there would one day be a function that knows whether it is daylight or not. The Daylight function turned out to need no more support functions so that was that.

So, the LDR came last because I didn't need it until I wrote the Daylight function. It was obvious of course that it would have to be read at some point, but initially, I didn't know when that point would be.

With this approach, assuming a function you need and filling it in later, it sometimes feels that the program is almost writing itself. In a more complex piece of software, you will likely need much more design up front, but even then, you can use this technique when you get into the details - it lets you focus on a little bit of code at a time rather than worrying about the big picture.

Of course, it's not infallible - sometimes you'll find that some idiot (yourself) has painted themselves into a corner and you'll need to backtrack until you untangle the mess you've made  smiley-wink   
41  Using Arduino / Project Guidance / Re: Can a single gps reciever get a RTK accuracy? on: August 12, 2014, 08:03:30 am
Quote
even under the best conditions, the reported position wanders around in a seemingly random path

This is done by design. Its to prevent civilian uses of GPS getting a completely accurate position.

It sounds like you're talking about selective availability which did indeed introduce position error for non-military users. According to wikipedia, that 'feature' has been disabled since 2000. The variation in position observed is due to (among other things) atmospheric & space interference.
42  Using Arduino / Programming Questions / Re: The difference between while and if statements. on: August 11, 2014, 02:23:46 pm
"Arduino Cookbook" it says while and if statements are interchangeable in most cases.
In which section? I just gave the if & while parts a cursory glance & couldn't see any such thing.
43  Using Arduino / Project Guidance / Re: where/how to place "blink without delay" on: August 11, 2014, 07:26:42 am
Here's an adaptation of your earlier requirements using millis and functions:
Code:
const int ledPin =  13;     
const int PumpPin =  12;     
const int LDRPin = A0;

const unsigned long DAY_PUMP_OFF   = 60UL*60UL*1000UL;
const unsigned long DAY_PUMP_ON    = 15UL*60UL*1000UL;
const unsigned long NIGHT_PUMP_OFF = 30UL*60UL*1000UL;
const unsigned long NIGHT_PUMP_ON  = 30UL*60UL*1000UL;

unsigned long previousLEDMillis = 0;        // will store last time LED was updated
unsigned long previousPumpMillis = 0;       // will store last time Pump was updated

unsigned long interval = 1000;           // interval at which to blink (milliseconds)
unsigned long PumpInterval;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(PumpPin, OUTPUT);
PumpInterval=GetPumpInterval(LOW);  // Start with the pump off
}

void loop()
{         
BlinkLED();
ManagePump();
}

void ManagePump()
{
static int PumpState=LOW;
unsigned long currentMillis = millis();
 
if(currentMillis - previousPumpMillis > PumpInterval)
  {
  previousPumpMillis = currentMillis;   

  if(PumpState == LOW)
    PumpState = HIGH;
  else
    PumpState = LOW;

  digitalWrite(PumpPin, PumpState);
  PumpInterval=GetPumpInterval(PumpState);
  }
}

unsigned long GetPumpInterval(int PumpState)
{
unsigned long PumpInterval;
if(Daylight())
  if(PumpState==LOW)
    PumpInterval = DAY_PUMP_OFF;
  else
    PumpInterval = DAY_PUMP_ON;
else   
  if(PumpState==LOW)
    PumpInterval = NIGHT_PUMP_OFF;
  else
    PumpInterval = NIGHT_PUMP_ON;
   
return PumpInterval;   
}

bool Daylight()
{
static bool IsDaylight=true;
int LDRReading=analogRead(LDRPin);
if(LDRReading>600)
  IsDaylight=true;
if(LDRReading<400)
  IsDaylight=false;
return IsDaylight;
}

void BlinkLED()
{
static int ledState = LOW;   
unsigned long currentMillis = millis();
 
if(currentMillis - previousLEDMillis > interval)
  {
    previousLEDMillis = currentMillis;   

    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    digitalWrite(ledPin, ledState);
  }
}
Compiled, not tested.

It blinks a led all the time and doesn't implement your power, night or day leds. Neither does it have an led that blinks during the pump off period. All of these should be easy enough to implement with a couple more functions. Note that this approach keeps the LED and pump control completely separate and thus rather easier to follow.
44  Topics / Home Automation and Networked Objects / Re: Chicken food dispenser on: August 09, 2014, 06:37:44 am
At trigger time, start the motor. Monitor the switch until it reads zero. Delay a few milliseconds to take care of switch bounce. Monitor the switch until it reads one. Stop the motor.
45  Using Arduino / Programming Questions / Re: Scrolling Algorithm for LEDs that Follow Someone on: August 08, 2014, 02:02:32 pm
Post all of your code.

Quote
Also, after maybe 30 seconds

That's often  a sign that you've used an int variable to store millis in rather than unsigned long.
Pages: 1 2 [3] 4 5 ... 248