Problem
I want to communicate with my w7n64x machine and a Seeeduino Mega. Using the USB connection works fine for me, but when I connect to the Seeeduino using the Bluesmirf's Bluetooth connection I can only receive data on the pc, but not send to the Seeeduino. I have the Bluesmirf with the blue antenna (BlueSMiRF Installation Tutorial), therefore I use the default baud rate of 115200. When trying to send anything using the serial monitor of the Arduino IDE I receive an error prompt in the console. My design requires the transmission of commands, as listed in 'protocol'.
The Bluetooth connection is established, as shown in Bluesoleil's status information. The status information shows the data flow of incoming data from the Bluesmirf and outgoing data from the pc, which is corresponding to the bytes I send and receive. The green LED on the bluesmirf is turned on. I have this problem on 2 machines (w7nx64 and w7nx86), reinstalling the bluetooth driver was no success. LynxTerm could also not receive anything by trying the 'ver' test. To replace the power supply for ther Seeeduino did not help as well.
If anyone out there has any suggestions how I can fix this or need more information, please comment my post.Thanks
Error message from Arduino IDE when sending via serial port of Bluetooth connection
[img][/img]java.io.IOException: No error in nativeDrain
at gnu.io.RXTXPort.nativeDrain(Native Method)
at gnu.io.RXTXPort$SerialOutputStream.flush(RXTXPort.java:1201)
at processing.app.Serial.write(Unknown Source)
at processing.app.Serial.write(Unknown Source)
at processing.app.SerialMonitor.send(Unknown Source)
at processing.app.SerialMonitor.access$100(Unknown Source)
at processing.app.SerialMonitor$3.actionPerformed(Unknown Source)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:492)
at javax.swing.JTextField.postActionEvent(JTextField.java:705)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:820)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2886)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
at java.awt.Component.processEvent(Component.java:6040)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:704)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:969)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:841)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:668)
at java.awt.Component.dispatchEventImpl(Component.java:4502)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Setup
This is my hardware setup
Code
This is the running code on the Seeeduino
#include <Wire.h>
#include <ADXL345.h>
int inStream = 0;
int incoming=0;
int x,y,z;
const int vibrePin = 10;
char command[50];
ADXL345 adxl;
boolean accelIsOn =false;
boolean vibreIsOn = false;
void setup() {
pinMode(vibrePin, OUTPUT);
digitalWrite(vibrePin, LOW);
Serial.begin(115200);
accelInit();
vibreOff();
establishContact();
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("0,0,0"); // send an initial string
delay(300);
}
}
void accelInit() {
adxl.powerOn();
//set activity/ inactivity thresholds (0-255)
adxl.setActivityThreshold(75); //62.5mg per increment
adxl.setInactivityThreshold(75); //62.5mg per increment
adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
//look of activity movement on this axes - 1 == on; 0 == off
adxl.setActivityX(1);
adxl.setActivityY(1);
adxl.setActivityZ(1);
//look of inactivity movement on this axes - 1 == on; 0 == off
adxl.setInactivityX(1);
adxl.setInactivityY(1);
adxl.setInactivityZ(1);
//look of tap movement on this axes - 1 == on; 0 == off
adxl.setTapDetectionOnX(0);
adxl.setTapDetectionOnY(0);
adxl.setTapDetectionOnZ(1);
//set values for what is a tap, and what is a double tap (0-255)
adxl.setTapThreshold(50); //62.5mg per increment
adxl.setTapDuration(15); //625?s per increment
adxl.setDoubleTapLatency(80); //1.25ms per increment
adxl.setDoubleTapWindow(200); //1.25ms per increment
//set values for what is considered freefall (0-255)
adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
//setting all interupts to take place on int pin 1
//I had issues with int pin 2, was unable to reset it
adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN );
//register interupt actions - 1 == on; 0 == off
adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 1);
adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1);
adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}
void accelOn(){
adxl.readAccel(&x, &y, &z);
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(",");
Serial.print(z);
Serial.println(";");
delay(50);
}
void accelOff(){
//nothing
}
void vibreOn(){
digitalWrite(vibrePin, HIGH);
}
void vibreOff(){
digitalWrite(vibrePin, LOW);
}
void calibrate(){
// to implement
}
void resetIncoming(){
incoming=0;
memset(command, 0, sizeof(command));
}
void loop() {
inStream = Serial.read();
if(inStream >=0)
{
Serial.print(inStream, BYTE);
command[incoming] = char(inStream);
incoming++;
processCommand();
}
runCommand();
}
void processCommand(){
if(strcmp (command, "AccelOn")==0){
//schalte accelerometer ein und gebe daten aus
accelIsOn = true;
resetIncoming();
}
if(strcmp (command, "AccelOff")==0){
//schalte accelerometer aus
accelIsOn = false;
resetIncoming();
}
if(strcmp (command, "VibreOn")==0){
//schalte vibre ein
vibreIsOn= true;
resetIncoming();
}
if(strcmp (command, "VibreOff")==0){
//schalte vibre aus
vibreIsOn= false;
resetIncoming();
}
if(strcmp (command, "Calibrate")==0){
//kalibriere
calibrate();
resetIncoming();
}
}
void runCommand(){
if (accelIsOn){
accelOn();
}
else{
accelOff();
}
if(vibreIsOn){
vibreOn();
}
else{
vibreOff();
}
}
Protocol
- To initialise the connection, the Seeeduino sends continously (0,0,0) until it receives something via the serial port.
- Sending the command "AccelOn" makes the Seeeduino sending the data from the attached accelerometer.
- Sending the command "AccelOff" stops the print out of the accelerometer data.
- Sending the command "VibreOn" toggles the vibration motor on.
- Sending the command "VibreOff" toggles the vibration motor off.
- Sending the command "Calibrate" does nothing yet.