I am using the Arduino UNO on a project to grab accelerometer data through the SPI interface and output the data serially to a PC using the Seeedstudio Bluetooth Shield Module.
Bluetooth\
The bluetooth code was based on the sample code provided by Seedstudio at their wiki. The baud rate used is 38400 for the Bluetooth, and the communication at the PC uses baud rate of 9600.
Integration\
The two components are integrated according to the following snippets of code:
void setup(){
// initialize serial
Serial.begin(9600);
// initialize bluetooth pins
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
// Configure SPI
SPI_SETUP();
// Configure accelerometer
Accelerometer_Setup();
// Calibrate
getCalibration();
setupBlueToothConnection();
delay(10);
}
void loop() {
//Short delay
delay(period);
//Get sensor data
getData();
// DEBUG
Serial.print(xAcc);
Serial.print(" ");
Serial.println(yAcc);
// To be replaced by sendData() function
if (blueToothSerial.available()){
recvChar = blueToothSerial.read();
blueToothSerial.print(recvChar);
}
}
void getData()
{
readVal(); // get acc values and put into global variables
// Read data remove offset
xAcc = (xAcc) - xOffset;
yAcc = (yAcc) - yOffset;
}
// Calibrate Accelerometer
void getCalibration()
{
for (int i = 0; i<100;i++)
{
readVal();
sumx+=xAcc;
sumy+=yAcc;
sumz+=zAcc;
delay(period);
}
xOffset = sumx/100;
yOffset = sumy/100;
zOffset = sumz/100;
}
Issue\
The two separate components work very well individually; however, once I integrated the two, I found that as soon as I used the Bluetooth software serial port, the accelerometer data stops updating. To elaborate, if the Bluetooth sends any data out, or receives any data, the accelerometer data will kind of "freeze" to a value.
Additionally, I have observed that after 3-5 seconds, the data will update again.
Any guidance on how I may proceed with the debugging would be highly appreciated!
Your sketch doesn't compile so it's hard to say what is going wrong.
[quote]
sketch_jul08b.cpp: In function 'void setup()':
sketch_jul08b:4: error: 'RxD' was not declared in this scope
sketch_jul08b:5: error: 'TxD' was not declared in this scope
sketch_jul08b:8: error: 'SPI_SETUP' was not declared in this scope
sketch_jul08b:11: error: 'Accelerometer_Setup' was not declared in this scope
sketch_jul08b:16: error: 'setupBlueToothConnection' was not declared in this scope
sketch_jul08b.cpp: In function 'void loop()':
sketch_jul08b:22: error: 'period' was not declared in this scope
sketch_jul08b:28: error: 'xAcc' was not declared in this scope
sketch_jul08b:30: error: 'yAcc' was not declared in this scope
sketch_jul08b:33: error: 'blueToothSerial' was not declared in this scope
sketch_jul08b:34: error: 'recvChar' was not declared in this scope
sketch_jul08b.cpp: In function 'void getData()':
sketch_jul08b:41: error: 'readVal' was not declared in this scope
sketch_jul08b:44: error: 'xAcc' was not declared in this scope
sketch_jul08b:44: error: 'xOffset' was not declared in this scope
sketch_jul08b:45: error: 'yAcc' was not declared in this scope
sketch_jul08b:45: error: 'yOffset' was not declared in this scope
sketch_jul08b.cpp: In function 'void getCalibration()':
sketch_jul08b:53: error: 'readVal' was not declared in this scope
sketch_jul08b:54: error: 'sumx' was not declared in this scope
sketch_jul08b:54: error: 'xAcc' was not declared in this scope
sketch_jul08b:55: error: 'sumy' was not declared in this scope
sketch_jul08b:55: error: 'yAcc' was not declared in this scope
sketch_jul08b:56: error: 'sumz' was not declared in this scope
sketch_jul08b:56: error: 'zAcc' was not declared in this scope
sketch_jul08b:58: error: 'period' was not declared in this scope
sketch_jul08b:61: error: 'xOffset' was not declared in this scope
sketch_jul08b:61: error: 'sumx' was not declared in this scope
sketch_jul08b:62: error: 'yOffset' was not declared in this scope
sketch_jul08b:62: error: 'sumy' was not declared in this scope
sketch_jul08b:63: error: 'zOffset' was not declared in this scope
sketch_jul08b:63: error: 'sumz' was not declared in this scope
Sorry for not updating, but I've been fairly busy with class work in the past little bit.
The problem turns out to be an issue with not having enough power from my laptop's USB port. I have since powered the Arduino with an external power supply and everything is working perfectly.
If a mod would like to close this thread, please feel free to do so.