Skip to content

Serial Port Issues 3: XBee’s and Serial

October 23, 2009

Not to beat a dead horse, but when I’ve finished beating my own head against this wall maybe I will be able to hand off some little snippet that I’ve learned to someone else around here.  I thought I learned this a few months ago, but clearly not, so let that be a warning as well: USE YOUR PCOMP OR LOSE YOUR PCOMP.

If any old hands could give me some advice here I’d greatly appreciate it:  I’m pleased to announce that I’ve got my Arduino talking to my laptop via XBees.

I’ve got (2) new problems:

1. I cannot program my Arduino via XBee.  The serial ports ID’d are usbserial-A6007zfq, whether /tty. or /cu.  Arduino’s either looking for usbserial-A7006Sv5, or it’s saying “Problem uploading to board.”  I’ve looked through the Arduino site but I can’t find anything about this issue.

cu

cu
— but, no worries, I reprogrammed my Arduino via USB, and then succeeded in sending serial data to it via the XBee.  So the next problem:

2. The values are all mapping completely differently than before, and I can’t help but think it has something to do with the fact that the accelerometer is being powered differently.  It’s on the Arduino with the XBee and a 9v battery.  The other XBee is on an Explorer at the USB port.  Theoretically it shouldn’t matter since the accelerometer is still being powered off the same 3.3v, but I wonder.

I’m happy to remap, but this seems somewhat arcane.

Arduino Code:

unsigned long lastTime;

// analog input pins
int pinaccX = 0;
int pinaccY = 1;
int pinaccZ = 2;

// accelerometer values
int X;
int Y;
int Z;

int valX;
int valY;
int valZ;

// setup loop
// opens our serial communication and setups our pins

void setup()
{
Serial.begin(9600);
Serial.println(“Monkey Engaged!”);
Serial.print (“Time”);
Serial.print(“\t”); //tab
Serial.print(“X”);
Serial.print(“\t”);
Serial.print(“Y”);
Serial.print(“\t”);
Serial.println(“Z”);
}

void loop()
{
while(millis()-lastTime < 1000){ // while(millis()-lastTime < 1000){

// read accelerometer state
X = analogRead(pinaccX);
Y = analogRead(pinaccY);
Z = analogRead(pinaccZ);

valX = map(X,275,425,0,255);
valY = map(Y,275,425,0,255);
valZ = map(Z,260,385,0,255);
}

// update last time so we run every 1000 millis
lastTime = millis();

// print values to serial port for testing
Serial.print (lastTime);
Serial.print(“\t”);
Serial.print(valX);
Serial.print(“\t”);
Serial.print(valY);
Serial.print(“\t”);
Serial.println(valZ);
}

Some Serial Data (x y z):

All were mapped 0-255 in the sketch and it works well when hard-wired with USB.

20000 181 314 191
21000 181 314 191
22000 180 314 189
23000 170 299 187
24000 266 161 234
25000 195 164 342
26000 195 164 344
27000 190 163 342
28000 187 181 346
29000 187 181 346
30000 187 185 350
31000 187 185 348
32000 391 137 234
33000 222 166 44
34000 221 183 46
35000 236 175 57
36000 212 181 44
37000 302 210 87
38000 251 224 342
39000 136 350 193
40000 166 319 226
41000 171 321 228
42000 170 323 230
43000 170 324 230
44000 183 331 234
45000 195 331 236
46000 198 49 216
47000 207 56 199
48000 61 168 208
49000 56 171 199
50000 57 156 204
51000 79 122 189
52000 329 219 201
53000 323 236 210
54000 323 238 212
55000 270 368 173
56000 256 307 185
57000 290 292 181
58000 297 287 185
59000 295 289 179
60000 289 297 185
  • 206000 231 234 418
  • 207000 232 217 403
  • 208000 236 217 403
  • 209000 236 217 403
  • 210000 300 328 83
  • 211000 226 180 77
  • 212000 231 193 83
  • 213000 238 188 87
  • 214000 285 384 267
  • 215000 234 360 301
  • 216000 238 362 299
  • 217000 300 90 189
  • 218000 210 88 218
  • 219000 205 85 216
  • 220000 391 193 195
  • 221000 374 255 240
  • 222000 372 249 234
  • 223000 295 100 275
  • 224000 95 214 212
  • 225000 95 209 214
Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: