Show Posts
Pages: 1 [2] 3 4 ... 13
16  Forum 2005-2010 (read only) / Syntax & Programs / Re: Using pow() from math.h on: December 17, 2006, 01:05:24 am
Myeah you're right, but I was mostly asking about the error, pow isn'wasn't really my motivation, it was mostly out of curiosity.
17  Forum 2005-2010 (read only) / Syntax & Programs / Using pow() from math.h on: December 16, 2006, 02:37:46 pm
I have included math.h in my sketch in the intention of using the pow() function. However, if I use the function the program won't build anymore and bails out with:

/Users/xsmurf/Applications/Development/Arduino/arduino-0006/tools/avr/bin/../lib/gcc/avr/4.0.3/../../../../avr/bin/ld: region text is full (/tmp/build33002.tmp/Parallax_4x4_Keypad_74C922.elf section .text)

Couldn't determine program size: tools/avr/bin/avr-size: '/tmp/build33002.tmp/Parallax_4x4_Keypad_74C922.hex': No such file


Any ideas how I could make this work??
18  Forum 2005-2010 (read only) / Syntax & Programs / Re: simple soft-button issue. on: December 10, 2006, 11:21:03 pm
Here's a little video of the result, including a pulsating LED without using delay()
http://www.youtube.com/v/krln7ZwSt8E

Code:
/* Software Pulsating LED using PWM
 * --------------------------------
 *
 * This example does not use delay() as to not block the cpu from processing other stuff
 *   the down side is it might jerk off when stuff interrupts the cpu.
 *
 * (cleft) 2005 by Matthieu Lalonde
 * <http://smurfturf.net>
 * <mailto:mlalonde(at)smurfturf(dot)net>
 *
 */
// Pins definition
#define statusLED 13
#define actionBtn 12         // The input button
#define protoLED  11         // The output led

/* ** Program variables ** */
// Button variables
int btnVal     = 0;           // Used to store the button's value on cycle
int softVal    = 0;           // The software value of the button
int bounceInterval = 50;      // bounce interval in cycles
int bounceTime = 0;           // Bounce cycle counts
int lastBtnVal = HIGH;        // Last cycle's button value
// Pulsation variables
long previousMillis  = 0;      // Will store last time LED was updated
int interval         = 10;     // interval at which to blink (milliseconds)
int i                = 0;      // Cycle counter for the pulsating effect
int valLED           = 0;      // Stores the current PWM value for the LED
int stopNextRun      = 0;
/* *********************** */

void setup () {
  pinMode(protoLED, OUTPUT);
  pinMode(actionBtn, INPUT);

  Serial.begin(9600);
  reportAVRState(3, 1);
}

void loop() {
  btnVal = digitalRead(actionBtn);

  if (btnVal) {
    readRemoteSoftVal();
  }

  if (btnVal == LOW && lastBtnVal == HIGH && bounceTime != -1) {
    lastBtnVal = LOW;
    Serial.println("Going low");
  }

  if (bounceTime == -1 && btnVal == HIGH) {
    bounceTime = 0;
  }

  if (btnVal == LOW && lastBtnVal == LOW) {
    bounceTime++;
    if (bounceTime >= bounceInterval) {
      bounceTime = -1;
      btnVal = HIGH;
      Serial.println("Action button debounced!");
    }
  }

  if (btnVal == HIGH && lastBtnVal == LOW) {
    softVal = !softVal;
    lastBtnVal = HIGH;
    Serial.print("Going high with softVal to: ");
    Serial.println(softVal);
  }

  // We want the LED to be off!
  if (!softVal) {
    digitalWrite(protoLED, softVal);
    previousMillis = 0;
    valLED = 0;
    i = 0;
  }
  // Pulsate that shiny thing!
  else {
    // check to see if it's time to blink the LED; that is, is the difference
    // between the current time and last time we blinked the LED bigger than
    // the interval at which we want to blink the LED.
    if (millis() - previousMillis > interval) {
      previousMillis = millis();   // remember the last time we blinked the LED

      i++;
      // Pulsating up
      if (i < 175) {
        interval = 15;
        valLED = i;
      } // Let's light it up for a bit more time in the middle
      else if (i == 175) {
        valLED = 175;
        interval = 20;
      } // Pulsating down
      else if (i < 350) {
        interval = 10;
        valLED = (175 - (i - 175));
      } // The led is off, the loop restarts
      else {
        i = 0;
        valLED = 0;
        interval = 20;
      }

      analogWrite(protoLED, valLED);
    }
  }
}

void readRemoteSoftVal( void ) {
  int incomingByte = 0;

  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    if (incomingByte == 49) {
      btnVal&= LOW;
    }
  }

  btnVal&= HIGH;
}

// Reports the state of the controller via pin 13's led and serial
void reportAVRState(int howManyTimes, int leaveOn) {
  int i;

  pinMode(statusLED, OUTPUT);

  for (i=0; i< howManyTimes; i++) {
    digitalWrite(statusLED, HIGH);
    delay(200);
    digitalWrite(statusLED, LOW);
    delay(200);  
  }

  if (leaveOn) {
    digitalWrite(statusLED, HIGH);
  }

  Serial.println("AVR Initialized");
}
19  Forum 2005-2010 (read only) / Syntax & Programs / Re: simple soft-button issue. on: December 09, 2006, 03:42:50 pm
I got around implementing soft debounce and figured I could post the code, maybe others will find it useful, maybe others will be able to tell me if I did anything wrong. It works very nicely as far as I can see.

Code:
int statusLED  = 13;
int flashLED   = 11;
int actionBtn  = 12;
int btnVal     = 0;
int softVal    = 0;
int bounceTime = 0;
int lastBtnVal = HIGH;

void setup () {
  pinMode(statusLED, OUTPUT);
  digitalWrite(statusLED, HIGH);
 
  pinMode(flashLED, OUTPUT);
  pinMode(actionBtn, INPUT);
  
  Serial.begin(9600);        // connect to the serial port
  Serial.println("Initialized");
}

void loop() {
  btnVal = digitalRead(actionBtn);
  if (btnVal == LOW && lastBtnVal == HIGH && bounceTime != -1) {
     lastBtnVal = LOW;
     Serial.println("Going low");
  }
  
  if (bounceTime == -1 && btnVal == HIGH) {
    bounceTime = 0;
  }
  
  if (btnVal == LOW && lastBtnVal == LOW) {
    bounceTime++;
    if (bounceTime >= 50) {
      bounceTime = -1;
      btnVal = HIGH;
      Serial.println("Action button debounced!");
    }
  }
  
  if (btnVal == HIGH && lastBtnVal == LOW) {
    softVal = !softVal;
    lastBtnVal = HIGH;
    Serial.print("Going high with softVal to: ");
    Serial.println(softVal);
  }
  
  digitalWrite(flashLED, softVal);
}
20  Forum 2005-2010 (read only) / Syntax & Programs / Re: simple soft-button issue. on: December 09, 2006, 01:56:09 am
Thanks for the pointers! I've been able to make this work. The code was refined. I did not have to take the noise into account with the switch and code I'm using (the switch is the one included on the SparkFun protoshield). The only thing that could still be integrated (noise excluded) is soft debounce, as it's now tracking changes of LOW to HIGH state. I'll have to look into it, but I don't think it would be so hard to do. I'll post an update when I do. Here is what I came up with.

Code:
int statusLED  = 13;
int flashLED   = 11;
int actionBtn  = 12;
int btnVal     = 0;
int softVal    = 0;
int lastBtnVal = HIGH;

void setup () {
  pinMode(statusLED, OUTPUT);
  digitalWrite(statusLED, HIGH);
 
  pinMode(flashLED, OUTPUT);
  pinMode(actionBtn, INPUT);
  
  beginSerial(9600); // Connect to the serial port, used for debugging
}

void loop() {
  btnVal = digitalRead(actionBtn);
  if (btnVal == LOW && lastBtnVal == HIGH) {
     lastBtnVal = LOW;
     Serial.println("Going low");
  }
  
  if (btnVal == HIGH && lastBtnVal == LOW) {
    softVal = !softVal;
    lastBtnVal = HIGH;
    Serial.println("Going high");
  }
  
  digitalWrite(flashLED, softVal);
}

Hopefully this will help others too smiley
21  Forum 2005-2010 (read only) / Syntax & Programs / Re: simple soft-button issue. on: December 06, 2006, 02:28:49 pm
Well, adding a bit of delay at the bottom of the (btnValue == LOW) statement seems to help. It works nicely with a "static" LED. If I use a flashing LED though, it will turn it on, but the problem is the same when trying to turn it off.
22  Forum 2005-2010 (read only) / Syntax & Programs / simple soft-button issue. on: December 06, 2006, 02:08:44 pm
I'm sorry if this is a little stupid, I'm totally new to this (I got the board yesterday ;D )
I'm trying to code a "soft button". Press once the circuit turns on (a LED in this case) press another time and it turns off... It actually works, but only partially. Most of the times when I hit the button the LED will light up until I release the button. If I press many times in a row it will however produce the desired effect and turn on or off the LED.

Code:
int flashLED    = 11;
int statusLED   = 13;
int actionBTN   = 12;
int btnValue    = 0;
int softValue   = 0;
 
void setup(void) {
  // initialize inputs/outputs
  pinMode(flashLED, OUTPUT);
  pinMode(statusLED, OUTPUT);
  pinMode(actionBTN, INPUT);
  digitalWrite(statusLED, HIGH); // I just want to know when the AVR is done booting
}
 
void loop(void) {
  btnValue = digitalRead(actionBTN);

  if (btnValue == LOW) {
    if (softValue == 0) {
      softValue = 1;
    } else {
      softValue = 0;
    }
  }
 
  if (softValue == 1) {
    digitalWrite(flashLED, HIGH);
  } else {
    digitalWrite(flashLED, LOW);
  }
}
23  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with the ENC28J60 on: October 12, 2007, 05:24:32 pm
I'm waiting for the WizNet eval board as we speak... We'll see what happens smiley-wink
24  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with the ENC28J60 on: September 18, 2007, 05:15:12 pm
It does look like you do smiley-razz

How does a shield sounds like? I'm trying to see if it'd be worth setting up a kit... let me know what you guys think!
25  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with the ENC28J60 on: September 17, 2007, 09:09:24 pm
And finally, in pictures ^-^


(Click for full flickr experience)


There's a lot more info, access to code and bug listing on the trac site.
There's still a lot of documentation work to be done, but it'll come!
26  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with the ENC28J60 on: September 17, 2007, 01:56:27 pm
Kuk: at this stage there is no plan for TCP support. The mega168 is small and TCP processing is heavy. I'm not saying it won't come but there are other priorities. Just like kg4wsv was saying were closer from an EthProxy than anything... I will post details (schematic, doc, etc) very soon. Meanwhile, the code is available above.
27  Forum 2005-2010 (read only) / Interfacing / FIRST PING! on: September 17, 2007, 02:38:16 am
I sorry if this post is rather dry when it should be rather high, but I don't have anything to show (I don't have LCD at hand to do the ethernet LCD or something). But here it is...

I have the honour to present you the very first ping replies!

Code:
PING 192.168.0.126 (192.168.0.126) from 192.168.0.12: 56 data bytes
64 bytes from 192.168.0.126: icmp_seq=0 ttl=64 time=1.341 ms
[...]
64 bytes from 192.168.0.126: icmp_seq=4 ttl=64 time=1.245 ms

--- 192.168.0.126 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 1.235/1.283/1.341/0.039 ms

I've written functions to allow using the ENC's internal checksum functions. And it worked! This is an issue however because as noted in the errata #15, use of the DMA for checksuming can cause drop packets. I guess for some this would be fine; it has the added advantage of having a zero footprint in the stack! Either ways this is a huge step as it confirms that the hardware is up and running and that most of the software runs fine!

There are no words to explain my joy! ;D ;D ;D
28  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with the ENC28J60 on: September 16, 2007, 04:51:53 pm
The code is now under version control using SVN. You can checkout a copy at svn+http://svn.mlalonde.net/Ethduino or browse the repository on the Trac site. Packets are still not getting received by applications, but they are getting sent (i can tcpdump them). As far as I can see, the checksum is definitely to blame. If anyone has an idea about this I'd really like to ear. As for running on the Mega168, so far so good... there's a good 6~8k free without all the debugging stuff which laves enough room for some business logic. (there's still definitely more things that could be done to reduce code size even further)
29  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with the ENC28J60 on: September 14, 2007, 03:51:44 pm
I'm in the process of seeing what I can do with µIP, it seems to have better checksum handling at least. And I wouldn't mind switching as µIP has a much better stack and properly support tcp.

EDIT: Doesn't seem like such a good idea. uIP is a little too feature complete for a mega168. And I won't even talk about OpenTCP. Looks like I'm going to stick with AVRLib.

30  Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with the ENC28J60 on: September 14, 2007, 12:31:33 am
The latest code can be obtained here. Have fun smiley
Pages: 1 [2] 3 4 ... 13