Hi all,
Please find below the sketch I used to troubleshoot with my Bluetooth module fitted with a little switch allowing to switch from "AT mode" (command) to "transparent mode" (data).
My Bluetooth breakout (based on the BC417143 chip) and powered at +5V, has an RS232 TTL serial interface with 0/3.3V levels.
So, I built a 3.3V to 5V level shifter with some common passive components (see EXAMPLE#2 below in the sketch).
I used an UNO arduino with a software serial (SoftwareSerial or SoftSerial+TinyPinChange libraries) to communicate with the TTL RS232 interface of the Bluetooth break out.
The sketch loaded in the UNO:
/*
USB RS232 TTL adapter: (for example, almost equivalent to http://arduino.cc/en/Main/USBSerial but without DTR line)
=====================
This sketch loaded in an Arduino UNO or MEGA allows to drive a Software TTL Uart via the serial console of the Arduino IDE.
Thus, it's possible to make an ATtiny or a Bluetooth module to dialog with the serial console of the Arduino IDE.
The serial console of the Arduino IDE can be obviously replaced with a terminal such as HyperTerminal or TeraTerm (Windows) or Minicom or GtkTerm (Linux).
Due to limitations of SoftwareSerial/SoftSerial librairies, working is half-duplex (no possible transmisson during reception).
By RC Navy 2012
http://p.loussouarn.free.fr
*/
//#include <SoftwareSerial.h> // Comment this line to use SoftSerial library and uncomment the 2 lines below
#include <SoftSerial.h> // Comment this line to use SoftwareSerial library and uncomment the line #include <SoftwareSerial.h> above
#include <TinyPinChange.h> // Comment this line to use SoftwareSerial library and uncomment the line #include <SoftwareSerial.h> above
/*Note:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 */
#define TTL_SERIAL_RX_PIN 3 /* Adjust here (UNO ou MEGA Arduino side) */
#define TTL_SERIAL_TX_PIN 2 /* Adjust here (UNO ou MEGA Arduino side) */
#define SERIAL_RATE 9600 /* Adjust here the serial rate. ATTENTION: set the same data rate for the serial console in the Arduino IDE! */
/* Object/variables */
//SoftwareSerial TtlSerial(TTL_SERIAL_RX_PIN, TTL_SERIAL_TX_PIN); // Comment this line to use SoftSerial library and uncomment the line below
SoftSerial TtlSerial(TTL_SERIAL_RX_PIN, TTL_SERIAL_TX_PIN); // Comment this line to use SoftwareSerial library and uncomment the line above
/*
EXAMPLE#1: DEBUG OF AN ATTINY VIA AN UNO/MEGA WITH THE SERIAL CONSOLE OF ARDUINO IDE or WITH A TERMINAL, e.g WITH HYPERTERMINAL or TERATERM (Windows), or MINICOM or GTKTERM (Linux)
=========
,---------------------, ,-----------------------,---, ,----------------,
| ATtiny | | Arduino UNO/MEGA | | | PC |
| ,--|TinyTx 1K TtlSerialRx|--, Sketch ,-, | | | Arduino IDE |
| Sketch with | >---------####------------> | -------------> | >-> >---------> |
| SoftSerial or |SS| RS232 TTL |SS| UsbRs232Ttl |S| |S/U| USB | Serial Console |
| SoftwareSerial | <---------####------------< | <------------- | <-< <---------< |
| '--|TinyRx 1K TtlSerialTx|--' '-' | | | |
| | | | | | |
'---------------------' '-----------------------'---' '----------------'
(see sketch below)
Legend:
======
SS: SoftSerial or SoftwareSerial
S: Native Serial
S/U: UNO ou MEGA built-in Serial/USB adapter (on-board)
1K: Resistors for protection (in case of short circuit between pins)
EXAMPLE#2: SERIAL<->BLUETOOTH ADPATER VIA AN UNO or MEGA ARDUINO
=========
+5V +5V
--- ---
| |
| #
,-----------------+--, # 4.7K ,-----------------------,---, ,----------------,
| VCC | # | Arduino UNO/MEGA | | | PC |
| BLUETOOTH UART |BT_Tx 1N4148 | TtlSerialRx|--, Sketch ,-, | | | Arduino IDE |
| TX>-------|<|---+----####----> | -------------> | >-> >---------> |
| Module | RS232 TTL 150 |SS| UsbRs232Ttl |S| |S/U| USB | Serial Console |
| RX<-------+--####------------< | <------------- | <-< <---------< |
| (I/0=3.3V) |BT_Rx | 2.2K TtlSerialTx|--' '-' | | | |
| GND | # | (VCC=+5V) | | | |
'----+--------+---+--' # 3.3K '-----------------------'---' '----------------'
| Switch | | # (see sketch below)
'-.-.----' | |
| | --- ---
'-' GND GND
AT Mode<- -> Transparent Mode
Legend:
======
SS: SoftSerial or SoftwareSerial
S: Native Serial
S/U: UNO ou MEGA built-in Serial/USB adapter (on-board)
*/
void setup()
{
Serial.begin(SERIAL_RATE);
TtlSerial.begin(SERIAL_RATE);
}
void loop()
{
/* Forward characters arriving from TtlSerial to USB via Serial */
if(TtlSerial.available() > 0)
{
Serial.write(TtlSerial.read());
}
/* Forward characters arriving from USB via Serial to TtlSerial */
if(Serial.available() > 0)
{
TtlSerial.write(Serial.read());
}
}
Once it works , you can easily switch to an ATtiny85 or a DigiSpark.
@digistump: it seems you did a typo for the path correction in SoftSerial library (in SoftSerial.h) on GitHub.
You wrote:
#include "<TinyPinChange.h>" instead of #include <TinyPinChange.h> (double quotes shall be removed)
Hope this will help!