Author Topic: Digispark and bluetooth module  (Read 11288 times)

Subtle

  • Newbie
  • *
  • Posts: 1
Digispark and bluetooth module
« on: April 10, 2013, 09:19:04 am »
Hello, I've been trying to get some simple bluetooth serial communication going on with the digistump and I've been having some troubles.
I first tried using the standard Arduino SoftwareSerial librairie but that gives me an error stating that SoftwareSerial only supports standard clock speeds. Ok fine.

So I moved on to the digiSpark SoftSerial Librairie, that gave me a link error saying the librairie couldn't find TinyPinChange.h, So I looked into the SoftSerial.h and found the line was hard coded so I changed "../TinyPinChange/TinyPinChange.h" to <TinyPinChange.h> and that seemed to work alright.

Now the problem I have is I can't seem to transfer data over bluetooth and read it on an Android device. I'm connecting fine, and everything seems alright. But I can't seem to transfert data either by using bluetooth.write() or bluetooth.println() I'm a bit confused, has anyone used bluetooth with the digispark properly? I've seen at least one project go by here that was using it, but the code showed him using the arduino SoftwareSerial librairie... which I don't know how he got to work...

Here's my code:
Code: [Select]
#include <SoftSerial.h>
#include <TinyPinChange.h>

#define RX 3
#define TX 4

SoftSerial bluetooth(RX, TX);

void setup()
{
  Serial.begin(9600);
  bluetooth.begin(57600);
}

void loop()
{
  digitalWrite(1, HIGH);
  bluetooth.println("Test Connection working"); // This is the line that I can't seem to read on android.
                                                // Though I've had this work on an Uno before so the android setup isn't the problem :(
  delay(1000);
 
}

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Digispark and bluetooth module
« Reply #1 on: April 10, 2013, 11:27:59 am »
Here is a thread about getting softwareserial library to work http://digistump.com/board/index.php/topic,212.0.html


I'll fix the issue with softserial path for the next release


As far as the bluetooth module - if it was me I'd likely try sending serial data to a known working device (unless you've tested the bluetooth module already) such as an Arduino or another Digispark. Then you'd know if the bluetooth or serial was the issue.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Digispark and bluetooth module
« Reply #2 on: April 11, 2013, 06:50:14 pm »
I've uploaded the modified softwareserial library here: https://github.com/digistump/DigisparkArduinoIntegration

RC Navy

  • Jr. Member
  • **
  • Posts: 54
  • When you like, even too much, it is not enough!
Re: Digispark and bluetooth module
« Reply #3 on: April 13, 2013, 03:17:07 am »
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:
Code: [Select]
/*
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!
« Last Edit: April 13, 2013, 03:31:26 am by RC Navy »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Digispark and bluetooth module
« Reply #4 on: April 13, 2013, 02:41:33 pm »
RC Navy - thanks! - I've fixed the typo