David,
Your code does not do what you expect:
setup() will be executed before
loop(), so you send "Goodnight moon!" and "Hello, world?" before you echo one received character on the other serial line.
What you should do is run
#include <AFSoftSerial.h>
AFSoftSerial mySerial = AFSoftSerial(3, 2);
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() // run over and over again
{
if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
if (Serial.available()) {
mySerial.print((char)Serial.read());
}
}
and when your Arduino is running listen to the incoming data on the BT and send something to the USB.
I'm not familiar with how to do it on Mac, but maybe you can figure it out based on what I do on GNU/Linux: I have /dev/ttyUSB0 as the serial line to the Arduino and /dev/rfcomm0 as a serial device to the BlueSMiRF (see [
1]). Now I open two terminals, one will listen to the BT module with
tail -f /dev/rfcomm0, and in the other I send something to the Arduino, like
echo "foo" > /dev/ttyUSB0.
I hope this helps.