CrossRoads: I ordered the board you suggested. Not sure what advantage it will have over the FTDI basic board, but I guess I will find out.
Jack: I added a FTDI header and tried using the FTDI basic board I have and when I try to upload the program, I am getting "stk_500_getsync(): not in sync: resp=0x00" I am including the schematic and the code. The differences I see in what I did and what you showed is that I don't have a reset button and don't couple through a 100nf cap. Also, you are pulling the SDA and SCL pins high through a resister (can't read value), and I am not. Could any of these differences be the cause of my problem.
I am able to program the chip through the ICSP port, but I can't see the serial output using that method.
I don't think it is important to my questions, but just FYI: This is for a remote for my robot and sends joystick data and micro adjustment data to the robot through xbee using a 10 byte packet starting with 255 and ending with 254.
#include <SoftwareSerial.h>
SoftwareSerial xBee = SoftwareSerial(2,3);
int hPin = 0; // Joystick Horizontal Pot data
int vPin = 1; // Joystick Vertical Pot data
int bumpPin = 3; // analog pin for bump movement
int bumpVal = 0; // to hold the bump direction selected.
int dir = 0; // bump direction (for minor position adjustments)
int valV = 0; // Vertical data
int valH = 0; // Horizontal data
int V = 0; // remapped vertical data
int H = 0; // remapped horizontal data
int lastV = 0; // last V value
int lastH = 0; // last H value
int debugging = 0; // 1 if debugging, 0 if not
const int greenLED=9; const int yellowLED=10; const int redLED=11; const int whiteLED=12; // LED lights
const int button1=5; const int button2=6; const int button3=7; const int button4=8; // bump buttons
void setup() {
pinMode(greenLED,OUTPUT); pinMode(redLED,OUTPUT); pinMode(yellowLED,OUTPUT); pinMode(whiteLED,OUTPUT); // LEDs
pinMode(button1,INPUT); pinMode(button2,INPUT); pinMode(button3,INPUT); pinMode(button4,INPUT); // buttons
digitalWrite(greenLED,HIGH);
Serial.begin(9600);
xBee.begin(9600);
if (debugging==1)
Serial.println("now Sending...");
}
void loop() {
// check for bump button pushes
bumpVal=analogRead(bumpPin);
if (debugging==1) {
Serial.print("bumpVal = ");
Serial.println(bumpVal);
}
if (bumpVal < 100)
dir = 0;
else if (bumpVal < 300)
dir = 3;
else if (bumpVal < 500)
dir = 1;
else if (bumpVal < 700)
dir = 4;
else dir = 2;
if (debugging==1) {
Serial.print("dir = ");
Serial.println(dir);
}
//if bump button has not been pushed, process joystick data
if (dir == 0) {
if (debugging != 1) {
// read the joy stick poteniometors
valV=analogRead(vPin);
valH=analogRead(hPin);
//convert analog signal to the range 0 to 250
V=map(valV,0,1024,0,250);
H=map(valH,0,1024,0,250);
sendStatus(V,H,0,0,0,0); // Send out through xBee
delay(30);
}
}
else // othewise bump in the desired direction
bump(dir);
}
void bump(int d) {
if (debugging==1)
Serial.println("in bump routine");
sendStatus(0,0,d,0,0,0);
delay(500);
}
void sendStatus(byte V, byte H, byte s1, byte s2, byte s3, byte s4) {
// this is the heart beat. If the Rx does not recieve
// this every cycle, it will automatically stop the motors
int HB=5;
// Add up all the data and take the mod of that number divided by 250. Send this
// as sort of a checksum to verify that data was complete and correct. I am using
// 250 as the modulo to avoid a result of 254 or 255 (and maybe 251..253 for later use)
int CK = (V+H+s1+s2+s3+s4+HB) % 250;
if ((V-lastV != 0) || (H-lastH != 0)) {
if (debugging==1) {
Serial.print(255);
Serial.print(",");
Serial.print(V-125);
Serial.print(",");
Serial.print(H-125);
Serial.print(",");
Serial.print(s1);
Serial.print(",");
Serial.print(s2);
Serial.print(",");
Serial.print(s3);
Serial.print(",");
Serial.print(s4);
Serial.print(",");
Serial.print(HB);
Serial.print(",");
Serial.print(CK);
Serial.print(",");
Serial.println(254);
} else {
xBee.write(255);
xBee.write(V);
xBee.write(H);
xBee.write(s1);
xBee.write(s2);
xBee.write(s3);
xBee.write(s4);
xBee.write(HB);
xBee.write(CK);
xBee.write(254);
}
digitalWrite(redLED,HIGH);
delay(100);
digitalWrite(redLED,LOW);
}
lastV=V;
lastH=H;
}