Show Posts
Pages: [1] 2 3 ... 16
1  Using Arduino / Storage / Re: SD Library: Only 31854 bytes available from a 160KB file on: May 25, 2011, 03:01:57 pm
Hi this is in fact an issue, unfortunately we cannot fix it while the virtual Stream object requires returning only a 16 bit int

until then, please use "size() - position()" which will give you the remaining bytes smiley
2  Forum 2005-2010 (read only) / Troubleshooting / Re: I think I fried my Uno on: November 23, 2010, 02:11:42 pm
you might be ok with just a new preprogrammed arduino microcontroller chip, they're $5-$6 at many arduino shops
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Bootloader hack: Auto-start app after upload on: September 08, 2007, 08:47:30 am
Quote
I may be confused because I just woke up, but why not just call app_start() from within the Q command?  Are you planning to trigger the watchdog reset in other ways?  


you totally can but i like to use the WDT because its very 'clean': you know that when you reset you have a fresh slate so that no matter what the bootloader did it will not have any funky registers set when the program runs.

also... you can do this


    // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
    if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
      app_start();  // skip bootloader


which -only- bootloads on external reset. This means that if the power flickrs it will also not start the bootloader. might be a nice safety precaution: if the arduino is 'doing something' and the power turns off and then back on it wont accidentally go into the bootloader (if there's serial data being sent to it)


also...you could use the watchdog timer  to get the micro out of the bootloader as it is a natural way to 'timeout'..instead of doing all that MAXERRORCOUNT/MAXTIMECOUNT stuff smiley
4  Forum 2005-2010 (read only) / Bugs & Suggestions / Bootloader hack: Auto-start app after upload on: September 08, 2007, 01:20:34 am
Ever find yourself wasting SECONDS of your life waiting for the arduino to 'reset' after you upload a new sketch
and then you also have to wait SECONDS for the app to start?
NO MORE!

this quick hack will automatically reset the arduino after uploading and skip the bootloader. To get back into the bootloader, just press the reset button (or use the diecimila 'auto-reset' capability). This hack uses the watchdog timer and MCU status register to figure out how the chip was reset

in main(), change the begining of the code to:


/* main program starts here */
int main(void)
{
    uint8_t ch,ch2;
    uint16_t w;

    ch = MCUSR;
    MCUSR = 0;

    WDTCSR |= _BV(WDCE) | _BV(WDE);
    WDTCSR = 0;

    // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
    if (ch & _BV(WDRF)) // if its a watchdog reset...
      app_start();  // skip bootloader

    /* set pin direction for bootloader pin and enable pullup */
    /* for ATmega128, two pins need to be initialized */


then change the 'Q' command later on...


      /* Leave programming mode  */
      else if(ch=='Q') {
        nothing_response();

        // autoreset via watchdog (sneaky!)
        WDTCSR = _BV(WDE);
        while (1); // 16 ms
      }
5  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: March 07, 2008, 03:05:03 pm
so, nobody who has had problems with this code has posted a screenshot or even told me what version of software they're using. thus its pretty much impossible for me to debug whats wrong.
however, ive posted a new version of the afsoftwareserial library with a volatile asm delay loop.
http://www.ladyada.net/make/eshield/download.html
6  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 25, 2008, 04:11:24 pm
please answer the questions so that i can verify the problems you had

"which version of arduino software are you using? this would be helpful for debugging. thanks!"
7  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 25, 2008, 01:55:33 pm
Quote
I am referring to 9600 baud.

In your pin change interrupt handler, if you don't disable interrupts, how can you be assured the timing is correct? What if timer0 overflows during your recv routine? What if people are using other interrupts?

SIGNAL interrupt handlers, by default, call cli() at the beginning, and sei() at the end so no interrupts will get in the way while it receives data.  i specifically call sei() and cli() for printing
if someone wants an interrupt to go off while receiving/transmitting data, well, they're SOL cause you cant get good timing otherwise smiley

Quote
In whackDelay, how can you be sure the compiler won't optimize away your software delay loop? Maybe consider making those variables 'volatile'  

that could be happening, although it doesnt in my version of the Arduino software (10)
which version are you using? this would be helpful for debugging. thanks!
8  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 25, 2008, 11:51:44 am
Quote
Ladyada,
Tom and I put your software serial up on the scope at the last hack to verify it's correct operation. We couldn't get it to work for the slower baud rates and came to a couple of conclusions about why. First off, thanks everyone at the Hacklab for helping!

Looking through your code, here are some suggestions to help improve your library...

You need to make sure multiple interrupts aren't stacking up without being handled so,

Having delays based on an overflowing timer0 interrupt inside of a pinChange interrupt handler is asking for trouble.
Also, why not disable the pin change interrupt (clear the mask) after the start bit?
When using a software serial, make sure other interrupts aren't screwing up recv delay;

what baud rates are you specifically referring to? what was your test that you couldnt get working?
could you specify where im using timer0 in my code? i dont see it anywhere so im not sure why you're referring to it. there should not be any interrupts that overlap unless, of course, you have the mismatched baud rates, but if you do that you're kinda on your own
9  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 11, 2008, 02:36:49 pm
this is an unreleased project, i posted it "if someone wants to play with it...", it was designed so i could hack and debug my xport shield.
its not a direct replacement for the default softwareserial so if you need multiple serial ports, different baudrates or atmega8/lilypad support then this isnt for you. in fact, it isnt even fully debugged so for all i know it may not work in certain situations.
10  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 10, 2008, 10:19:35 pm
well its pretty trivial to add support for any baudrate. i havent officially released this so ill add 2400 - i didnt realize anything out there used < 4800 smiley-razz
11  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 06, 2008, 12:40:29 am
Quote
Quote
[

er, no..."currently only for Diecimila (16mhz atmega168)"  smiley-wink

er, pity


send me a lilypad an an NG with an 8mhz xtal and ill make it work with 'em!
12  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 06, 2008, 12:39:37 am
Quote
Thanks for that, it will be a huge help.

One question, with interrupts turned off when sending a char, does that mean that receive bits will be lost if they are presented at the same time as a character is being sent?

yes
but the old software serial couldnt do that either so its not really a big deal
13  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 06, 2008, 12:01:52 am
Quote
What a genius, you rock! That fixes a huge problem, that would enable a few serial devices to be connected to one board, how did you do it?

actually you can only have one software serial device at a time (right now) because of the pinchange interrupt. i could adapt it for more but its a real hassle and, well, i figure this is good enough for now.

Quote
Will it work with BT's, Lilypads and NG's?

er, no..."currently only for Diecimila (16mhz atmega168)"  smiley-wink
14  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: software serial2 on: February 05, 2008, 06:55:43 pm
ok i fixed it

http://www.ladyada.net/make/eshield/AFSoftSerial.zip

supports RX and TX, up to 57600 tested. due to the delay inherent in digitalRead() its probably not possible to go any faster.
should probably be poked at by others. currently only for Diecimila (16mhz atmega168)

#include <AFSoftSerial.h>

AFSoftSerial mySerial =  AFSoftSerial(3, 2);

void setup()  {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world...");
}

void loop()                     // run over and over again
{
  if (mySerial.available()) {
      Serial.print((char)mySerial.read());
  }
  if (Serial.available()) {
      mySerial.print((char)Serial.read());
  }
}
15  Forum 2005-2010 (read only) / Bugs & Suggestions / software serial2 on: February 05, 2008, 04:00:05 pm
i need to use software serial to interface with the xport, but i couldnt get consistant results, even at 9600 so i poked at it a little and made a version that uses a pinchange interrupt (for diecimila or NG with chip upgrade only!). now it buffers the input characters to avoid the dreaded 'lost bits' errors i got.
it seems to work great! i will clean it up and make it more 'objecty' and maybe turn it into a library, but if someone wants to play with it...

/*
 * Software UART
 *
 */

int ledPin = 13;                // LED connected to digital pin 13

/***************************************************************************************/

#include <avr/pgmspace.h>

#define altPrint(x) alt_ROMputstring(PSTR(x), 0)
#define altPrintln(x) alt_ROMputstring(PSTR(x), 1)

int rxpin, txpin, altserialdelay = 0;
#define MAX_ALTRX_BUFF 8
char altRXD[MAX_ALTRX_BUFF];
int altrxsize = 0;

SIGNAL(SIG_PIN_CHANGE0)
{
  if ((rxpin >=8) && (rxpin <= 13)) {
    altRecv();
  }
}
SIGNAL(SIG_PIN_CHANGE2)
{
  if (rxpin <smiley-cool {
    altRecv();
  }
}

void altDelay(int delay) {
  while (delay != 0) {
     delay--;
  }
}

void altRecv(void) {
  char i, d = 0;
  if (digitalRead(rxpin))
    return;       // not ready!
  altDelay(altserialdelay-5); // one half bit
  for (i=0; i<8; i++) {
    PORTB |= _BV(5);
    altDelay(altserialdelay*2); // one bit
    PORTB &= ~_BV(5);
    if (digitalRead(rxpin))
      d |= (1 << i);
  }
  altRXD[altrxsize] = d; // save data
  altrxsize++;  // got a byte
  altDelay(altserialdelay*2);
}

void altSerialSetup(int baudrate, char tx, char rx) {
  txpin = tx;
  pinMode(txpin, OUTPUT);
  digitalWrite(txpin, HIGH);
  rxpin = rx;
  pinMode(rxpin, INPUT);
  digitalWrite(rxpin, HIGH);  // pullup!
  if (baudrate == 19200) {
     altserialdelay = 62; // these are determined experimentally
  } else if (baudrate == 9600) {
     altserialdelay = 128;  // these are determined experimentally
  }    
  if (rxpin < smiley-cool {
    // a PIND pin, PCINT16-23
    PCMSK2 |= _BV(rxpin);
    PCICR |= _BV(2);
  } else if (rxpin <= 13) {
    // a PINB pin, PCINT0-5
    PCICR |= _BV(0);    
    PCMSK0 |= _BV(rxpin-8);
  }
}


void altPutchar(char d) {
  int i;
  cli();  // turn off interrupts, make it nice & kleen
  digitalWrite(txpin, LOW);       //start bit
  altDelay(altserialdelay*2);
  for (i=0; i< 8; i++) {
    if (d & 0x1) {
       digitalWrite(txpin, HIGH);
    } else {
       digitalWrite(txpin, LOW);
    }
    altDelay(altserialdelay*2);
    d >>= 1;
  }
  digitalWrite(txpin, HIGH);     // one stop bit
  sei();   // turn on interrupts
  altDelay(altserialdelay*2);  
}

void alt_ROMputstring(const char *str, uint8_t nl) {
  uint8_t i;

  for (i=0; pgm_read_byte(&str); i++) {
    altPutchar(pgm_read_byte(&str));
  }
  if (nl) {
    altPutchar('\n'); altPutchar('\r');
  }
}
void altPrintNumber(uint16_t n) {
      uint8_t cnt=0, flag=0;
      
      while (n >= 10000UL) { flag = 1; cnt++; n -= 10000UL; }
      if (flag) altPutchar('0'+cnt);
      cnt = 0;
      while (n >= 1000UL) { flag = 1; cnt++; n -= 1000UL; }
      if (flag) altPutchar('0'+cnt);
      cnt = 0;
      while (n >= 100UL) { flag = 1; cnt++; n -= 100UL; }
      if (flag) altPutchar('0'+cnt);
      cnt = 0;
      while (n >= 10UL) { flag = 1; cnt++; n -= 10UL; }
      if (flag) altPutchar('0'+cnt);
      cnt = 0;
      altPutchar('0'+n);
      return;
}

int altAvailable(void) {
  
  
}

/***************************************************************************************/



void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  altSerialSetup(9600, 2, 3);
  Serial.begin(9600);
}

int counter=0;
void loop()                     // run over and over again
{
  digitalWrite(ledPin, LOW);    // sets the LED off

  if (altrxsize) {
      Serial.print(altRXD[0]);
      altrxsize--;
  }
  if (Serial.available()) {
      altPutchar(Serial.read());
  }

}

Pages: [1] 2 3 ... 16