Arduino-Sphero-Library icon indicating copy to clipboard operation
Arduino-Sphero-Library copied to clipboard

Only works with Arduino Mega

Open cmonr opened this issue 12 years ago • 7 comments

My intention for this library is for it to be fast enough that the user doesn't notice that it's even there. This requires the library to use a baud rate of at least 115200.

However, many Arduino boards tie the only available UART port to the Serial debugger (which imo they should). This leaves only the SoftSerial library for use.

When I first started writing the library, I attempted using the SoftSerial library, but found it was insufficient for my needs. This has resulted in me only supporting Arduino devices with multiple HardwareSerial objects.

If desired, other Arduino devices could be supported, with the drawback that using the Serial terminal in the Arduino IDE would not work. Also reprogramming the Arduino would require the constant disconnecting and reconnecting of the TX and RX lines.

cmonr avatar Sep 01 '13 03:09 cmonr

I'm likely wrong (haven't touched serial much) but can't you use that UART port when the board is disconnected from the debugger?

On 1 Sep 2013, at 04:12, Cruz Monrreal II [email protected] wrote:

My intention for this library is for it to be fast enough that the user doesn't notice that it's even there. This requires the library to use a baud rate of at least 115200.

However, many Arduino boards tie the only available UART port to the Serial debugger (which imo they should). This leaves only the SoftSerial library for use.

When I first started writing the library, I attempted using the SoftSerial library, but found it was insufficient for my needs. This has resulted in me only supporting Arduino devices with multiple HardwareSerial objects.

If desired, other Arduino devices could be supported, with the drawback that using the Serial terminal in the Arduino IDE would not work. Also reprogramming the Arduino would require the constant disconnecting and reconnecting of the TX and RX lines.

— Reply to this email directly or view it on GitHub.

JW97 avatar Sep 01 '13 03:09 JW97

Yes, but then every time you want to reprogram the Arduino, you need to disconnect the Bluetooth device, then pllug it in again, which imo is a real hassle and seems a bit silly.

The other limitation is that you can not get simple debug information from the Serial terminal.

cmonr avatar Sep 01 '13 03:09 cmonr

Hi can you tell me some more details if I want to connect arduino nano with sphero?

xan117 avatar Apr 07 '14 20:04 xan117

To connect to the Nano, you'd have to use TX0 and RX0, instead of TX1 and RX1. You'd also have to replace all instances of Serial1 to Serial, which means you'd lose debugging capability. Aside from that, the instructions in the repo should be the same.

The other issue you will come into is that since the Arduino Nano is reprogrammed via UART, in order to reprogram the Nano, you'd need to unplug the Bluetooth Adapter every time.

cmonr avatar Apr 07 '14 20:04 cmonr

Thank you for your quick reply. But I am still facing some issues. Its not connecting it. this is what I am uploading. Please let me know if you think I should change Serial1 to serial for your library too.

On Mon, Apr 7, 2014 at 5:56 PM, Cruz Monrreal II [email protected]:

To connect to the Nano, you'd have to use TX0 and RX0, instead of TX1 and RX1. You'd also have to replace all instances of Serial1 to Serial, which means you'd lose debugging capability. Aside from that, the instructions in the repo should be the same.

The other issue you will come into is that since the Arduino Nano is reprogrammed via UART, in order to reprogram the Nano, you'd need to unplug the Bluetooth Adapter every time.

Reply to this email directly or view it on GitHubhttps://github.com/cmonr/Arduino-Sphero-Library/issues/1#issuecomment-39782511 .

xan117 avatar Apr 07 '14 21:04 xan117

/************************************************ Written by Cruz Monrreal II Created on 06-26-2012 MOdified on 10-20-2012

Updates can be found here: https://github.com/cmonr/Arduino-Sphero-Library ************************************************/

void setup(){ // Give user a chance to power cycle Bluetooth Module delay(5000);

// Init USB Serial
//Serial.begin(115200);   // Default Baud Rate
Serial.println("Initializing Bluetooth");

// Init Blutooth Serial
// Uncomment to change baud rate
/*Serial1.begin(115200);
sendCmd("$$$");
sendCmd("U,115200,N");  // *** Replace this with desired Baud Rate ***
sendCmd("---");
*/

// Reconnect to Bluetooth and configure to master
Serial.begin(115200);  // *** This too ***
sendCmd("$$$");
sendCmd("SM,1");
sendCmd("---");

Serial.println("\nEntering Command Mode");
sendCmd("$$$");

Serial.println("\nScanning for Spheros...");
sendCmd("I,10");

}

void loop(){ long start; String line; String sphero_id=""; boolean commandComplete;

line = ""; commandComplete = false; while(!commandComplete){ while(Serial.available()){ unsigned char tmp = Serial.read(); if (tmp == '\n'){ // End of Line if (line.indexOf("Sphero") != -1){ //Save result //We can't exit because we need to wait for the command to finish if (sphero_id == ""){ sphero_id = line; Serial.println(line); } }

    if (line.indexOf("Done") != -1)
      // We can leave now...
      commandComplete = true;

    line = "";
  }else
    line.concat(char(tmp));
}

}

if (sphero_id != ""){ Serial.print("Connecting to "); Serial.println(sphero_id.substring(13, sphero_id.indexOf(',', 13)));

// Connect to Sphero Address
sendCmd("C," + sphero_id.substring(0, 12));
Serial.println("Connected.");

// Save address
sendCmd("SR," + sphero_id.substring(0, 12));

// We're done here!
sendCmd("---");
Serial.println("\nConfiguration complete!\nYou're Sphero's address has

been saved in the Bluetooth Module\n\nHave fun ^^;");

// Idle...
while(true);

} }

void sendCmd(String cmd){ String line = "";

// Send command if (cmd == "$$$") Serial.print(cmd); else Serial.println(cmd);

// Short delay... delay(100);

// Show which cmd is being sent Serial.println("> " + cmd);

while(1){ if (Serial.available()){ unsigned char tmp = Serial.read(); if (tmp == '\n') break; else line.concat(char(tmp)); } }

// Show Response Serial.println(line); }

On Mon, Apr 7, 2014 at 6:05 PM, Asif Hasan [email protected] wrote:

Thank you for your quick reply. But I am still facing some issues. Its not connecting it. this is what I am uploading. Please let me know if you think I should change Serial1 to serial for your library too.

On Mon, Apr 7, 2014 at 5:56 PM, Cruz Monrreal II <[email protected]

wrote:

To connect to the Nano, you'd have to use TX0 and RX0, instead of TX1 and RX1. You'd also have to replace all instances of Serial1 to Serial, which means you'd lose debugging capability. Aside from that, the instructions in the repo should be the same.

The other issue you will come into is that since the Arduino Nano is reprogrammed via UART, in order to reprogram the Nano, you'd need to unplug the Bluetooth Adapter every time.

Reply to this email directly or view it on GitHubhttps://github.com/cmonr/Arduino-Sphero-Library/issues/1#issuecomment-39782511 .

xan117 avatar Apr 07 '14 21:04 xan117

What Bluetooth breakout board are you using? Do you know that the RN-41 is entering command mode?

Unfortunately, like I mentioned, one of the drawbacks to using Serial is that you cannot get any debug messages. The next thing you need to do is comment any Serial.print statements that were only being used as debug statements. Things like "Serial.print("Connecting to");". Any print statement that was using Serial before needs to be disabled, otherwise that data will be sent to the Bluetooth module and confuse it.

cmonr avatar Apr 07 '14 21:04 cmonr