XBee and ATtiny - delays in responses

Hi,

What I'm working towards is having an Arduino + XBee coordinator reading GPS data and then broadcasting data (probably a digit 0-9) to a network of ATtiny + XBee router nodes which will then trigger vibration motors in response.

I currently have an XBee coordinator attached to my laptop and X-CTU via an XBee Explorer. I'm using the keyboard to send 0s and 1s to a router XBee.

The router is attached to an ATtiny45 on a breadboard, currently powered by an Arduino UNO as per the programming set up as per the MIT tutorial. I've run the burn bootloader command to set it to run at 8MHz and the XBee is connected via software serial.

There's an LED on Pin 4 and I'm running this code:

#include <SoftwareSerial.h>
SoftwareSerial XbeeSerial(0, 1);
int outputPin = 4;

// a byte to receive data:
char inByte = 0;

void setup () {
  // set pins to input and output appropriately
  pinMode(outputPin, OUTPUT);

  // start up the serial connection 
XbeeSerial.begin(9600);
}

void loop () {

// get any incoming data:
     if (XbeeSerial.available() > 1) {
      // read a byte
        inByte = XbeeSerial.read();
  
     // light the LED if a 1 has been received
     }
   if (inByte == '1') {
   digitalWrite(outputPin, HIGH);

   }
   // douse the LED if anything else was received 
   else if (inByte == '0'){
   digitalWrite(outputPin, LOW);
   }
}

It's kind of working - so when I send a 1 the LED lights and when I send a 0 it turns off ...except in practice I'm finding I need to send a couple of 1s or 0s for a change to take place and there can be delays of several seconds. Ideally I'd like to send a single digit and for the response to be instant.

I'm new to both XBees and ATtiny, can anyone suggest how to get this please?

I already have the XBees configured with packetization timeout (AT RO) set to 0. Is there anything else I should change either in the modem set-up or with the ATtiny chip, perhaps?

Thanks,
nikki

SoftwareSerial XbeeSerial(0, 1);

Why are you doing software serial on the hardware serial pins?

PaulS:

SoftwareSerial XbeeSerial(0, 1);

Why are you doing software serial on the hardware serial pins?

ATtiny45 has no UART.

Serial communication may not be reliable when using the internal oscillator as the system clock.

Still learning how to read pinout diagrams...

Are MOSI and MISO on the ATtiny equivalent to RX and TX on pins 0 and 1 on the Arduino?
(Or are you saying it's something different, PaulS?)

Would I be right in thinking that to add an external clock to the ATtiny45 I put a crystal across physical pins 2 and 3, with caps between 2 and 4 and 3 and 4? [datasheet]

I have some 16MHz crystals and 22pF caps from making breadboard arduinos, can I use them? I notice the list in the IDE under tools > board only has an option for a 20MHz external clock...

This is the chip I'm using: http://uk.rs-online.com/web/p/microcontroller/6962614/

...and would I need to do anything to undo the 8MHz bootloader command step I did before?

nikki:
Are MOSI and MISO on the ATtiny equivalent to RX and TX on pins 0 and 1 on the Arduino?

On the Arduino, MOSI is pin 11, MISO is pin 12. These are the SPI data transfer pins, pin 13 is the SPI clock pin.

Would I be right in thinking that to add an external clock to the ATtiny45 I put a crystal across physical pins 2 and 3, with caps between 2 and 4 and 3 and 4?

Yes.

I have some 16MHz crystals and 22pF caps from making breadboard arduinos, can I use them? I notice the list in the IDE under tools > board only has an option for a 20MHz external clock...

An entry for a 16MHz clock can be added to the boards.txt file.

...and would I need to do anything to undo the 8MHz bootloader command step I did before?

Yes, do "burn bootloader" using the 16MHz entry in boards.txt. (Note for ATtiny, there is no bootloader, the "burn bootloader" command just sets the fuses, which will configure the MCU to use an external crystal.)

Grand - thanks!

Will give it all a google and a try later...

Haven't looked at it, but making a 16MHz entry in boards.txt may be as simple as copying the 20MHz entry, renaming it (prefix on each line) and changing f_cpu to 16000000.

Partial success!

Adding a 16Mz external clock was as simple as adding the following to boards.txt in the hardware folder:

attiny45-16.name=ATtiny45 (external 16 MHz clock)
attiny45-16.bootloader.low_fuses=0xfe
attiny45-16.bootloader.high_fuses=0xdf
attiny45-16.bootloader.extended_fuses=0xff
attiny45-16.upload.maximum_size=4096
attiny45-16.build.mcu=attiny45
attiny45-16.build.f_cpu=16000000L
attiny45-16.build.core=arduino:arduino
attiny45-16.build.variant=tiny8

However it doesn't seem to make any difference to the response to the incoming XBee data - I still need to send "0" or "1" twice before the LED changes state.