I've got a spare Mega on hand so I can just use that.
In terms of the packets, would I need to put those markers in, or are the XBees doing that anyways (in which case I would just parse/split them on the Mega)?
At the moment I'm doing a serial call-response so each sensor/arduino is sending a clump of 20 bytes (9 sensors at 2 bytes each, then 2 more bytes for two switches), and then that's getting split in Max/MSP based on the 20 byte chunk, rather than having the actual packet or sensor bytes tagged.
This is my sensor/arduino code:
// i2c Arduino Library
#include <Wire.h>
// 0011110b, i2c 7bit address of HMC5883
#define address 0x1E
// Define sensor variables
int AccX;
int AccY;
int AccZ;
int GyroX;
int GyroY;
int GyroZ;
int SW1 = 9;
int SW2 = 10;
#define aX A0
#define aY A1
#define aZ A2
#define gX A6
#define gY A7
#define gZ A3
// Incoming serial byte
int inByte = 0;
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// Start serial port at 57600 bps:
Serial.begin(57600);
// Set incoming switch mode
pinMode(SW1,INPUT);
pinMode(SW2,INPUT);
// Start i2c communication
Wire.begin();
// Put the HMC5883 IC into the correct operating mode
Wire.beginTransmission(address); //open communication with HMC5883
Wire.write(0x02); //select mode register
Wire.write(0x00); //continuous measurement mode
Wire.endTransmission();
// Send a byte to establish contact until receiver responds
establishContact();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
// Define variables for magnetometer
int MagX,MagY,MagZ;
// Tell the HMC5883 where to begin reading data
Wire.beginTransmission(address);
Wire.write(0x03); //select register 3, X MSB register
Wire.endTransmission();
// If we get a valid byte, read analog ins:
if (Serial.available() > 0) {
inByte = Serial.read();
AccX = analogRead(aX);
AccY = analogRead(aY);
AccZ = analogRead(aZ);
GyroX = analogRead(gX);
GyroY = analogRead(gY);
GyroZ = analogRead(gZ);
// Read data from each axis of magnetometer, 2 registers per axis
Wire.requestFrom(address, 6);
if(6<=Wire.available()){
MagX = Wire.read()<<8; // X msb
MagX |= Wire.read(); // X lsb
MagZ = Wire.read()<<8; // Z msb
MagZ |= Wire.read(); // Z lsb
MagY = Wire.read()<<8; // Y msb
MagY |= Wire.read(); // Y lsb
}
// Send sensor data out
// Accelerometer X
Serial.write(highByte(AccX));
Serial.write(lowByte(AccX));
// Accelerometer Y
Serial.write(highByte(AccY));
Serial.write(lowByte(AccY));
// Accelerometer Z
Serial.write(highByte(AccZ));
Serial.write(lowByte(AccZ));
// Gyroscope X
Serial.write(highByte(GyroX));
Serial.write(lowByte(GyroX));
// Gyroscope Y
Serial.write(highByte(GyroY));
Serial.write(lowByte(GyroY));
// Gyroscope Z
Serial.write(highByte(GyroZ));
Serial.write(lowByte(GyroZ));
// Magnetometer X
Serial.write(highByte(MagX));
Serial.write(lowByte(MagX));
// Magnetometer Y
Serial.write(highByte(MagY));
Serial.write(lowByte(MagY));
// Magnetometer Z
Serial.write(highByte(MagZ));
Serial.write(lowByte(MagZ));
// Switch 1
Serial.write(digitalRead(SW1));
// Switch 2
Serial.write(digitalRead(SW2));
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
void establishContact() {
while (Serial.available() <= 0) {
Serial.write('A'); // send a capital A
delay(300);
}
}