Skip to content

Instantly share code, notes, and snippets.

@staticfloat
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staticfloat/d5e892c21bf81a187fe4 to your computer and use it in GitHub Desktop.
Save staticfloat/d5e892c21bf81a187fe4 to your computer and use it in GitHub Desktop.
/*
* This sketch should be run on a brand new FoneAstra board that has been flashed with the appropriate bootloader, fuse & lock bits.
* The sketch configures FoneAstra's BT module with the name "FoneAstra-{last 4 hex digits of RN-42's MAC address}.
* It configures the RN-42's UART to 38400 bps. This results in the lowest combined UART error rates for the RN-42 &
* FA's ATMega running with a 8Mhz crystal. 0.2% on both ends.
* After flashing & running this sketch on FA, all other sketches should configure the ATMega's h/w UART at 38400 like so:
* Serial.begin(38400);
*
* Code adapted from Sparkfun....see the commented section below. Ignore the bit about making appropriate connections because
* the RN-42 is already connected to FA on the PCB.
*
* Bluetooth Mate Echo
by: Jim Lindblom - jim at sparkfun.com
date: 3/15/11
license: CC-SA v3.0 - Use this code however you'd like, for any
purpose. If you happen to find it useful, or make it better, let us know!
This code allows you to send any of the RN-42 commands to the
Bluetooth Mate via the Arduino Serial monitor. Characters sent
over USB-Serial to the Arduino are relayed to the Mate, and
vice-versa.
Here are the connections necessary:
Bluetooth Mate-----------------Arduino
CTS-I (not connected)
VCC------------------------5V or 3.3V
GND--------------------------GND
TX-O-------------------------D2
RX-I-------------------------D3
RTS-O (not connected)
How to use:
You can use the serial monitor to send any commands listed in
the RN-42 Advanced User Manual
(http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf)
to the Bluetooth Mate.
Open up the serial monitor to 9600bps, and make sure the
pull-down menu next to the baud rate selection is initially set
to "No line ending". Now enter the configuration command $$$ in
the serial monitor and click Send. The Bluetooth mate should
respond with "CMD".
The RN-42 module expects a newline character after every command.
So, once you're in command mode, change the "No line ending"
drop down selection to "Newline". To test, send a simple command.
For instance, try looking for other bluetooth devices by sending
the I command. Type I and click Send. The Bluetooth Mate should
respond with "Inquiry, COD", follwed by any bluetooth devices
it may have found.
To exit command mode, either connect to another device, or send
---.
The newline and no line ending selections are very important! If
you don't get any response, make sure you've set that menu correctly.
*/
#include <SoftwareSerial.h>
#include "foneastrapins.h"
void setup()
{
//this controls power to the BT module
pinMode(BT_PWR_PIN,OUTPUT);
digitalWrite(BT_PWR_PIN,HIGH);
delay(1000);
Serial.begin(115200); // RN-42 defaults to 115200bps
Serial.print("$$$"); // Enter RN-42 command mode. The orange LED should start flickering pretty fast after this.
delay(1000); // Short delay, wait for RN-42 to send back CMD
Serial.println("S-,FoneAstra"); //set the name to FoneAstra-{last 4 hex digits of RN-42's MAC address}
delay(1000);
//set baudrate to 38400 bps. this gives the lowest UART error rate for both the RN-42 & the ATMega running with a 8Mhz crystal.
// the error rate is 0.2% for both ends at this speed. RN-42 has its lowest UART error rate of 0.03% at 115.2 kbps, however
// the ATMega with a 8Mhz crystal has a 3.5% error rate at this speed. 38400 bps gives the lowest error rate.
Serial.println("SU,38");
delay(5000); //watch the orange LED flicker fast for a few more secs.
Serial.println("---"); //exit the RN-42 command mode. Orange LED blinks at 1 sec after this.
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment