Arduino Due with Bluefruit

Hi,

Im stuggling with figuring out how to connect my arduino Due board with the bluefruit Bluetooth device. Im currently using serial 1 on the Due and when i swap it to my Uno board it works fine.

(On the due board it says cannot find device)

Im just using example 1 of the library to test connection.

the Due is a 3.3V device so take care if the external device uses 5V logic
which serial port did you use, e.g. Serial1 on pins 18 Tx1 and 19 Rx1
post your code?

which library?

It is probably a pile of blue berries are you sure you do not have that confused with a Bluetooth device? You will probably need some spare Duo boards. I highly recommend you get a copy of the Arduino Cookbook and skim it cover to cover and read the sections pertinent to your project. This book will probably save you several Arduinos over the next few months.

1 Like

This is the current code, it includes the other moduel that im connecting too but i only care about the bluetooth currently.

//BLE Libraries and Functions
#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"

#include "BluefruitConfig.h"

#define FACTORYRESET_ENABLE 1
#define MINIMUM_FIRMWARE_VERSION "0.6.6"
#define MODE_LED_BEHAVIOUR "MODE"

Adafruit_BluefruitLE_UART ble(Serial1, BLUEFRUIT_UART_MODE_PIN);
bool ble_connection_status = false;

void error(const __FlashStringHelper*err) {
Serial.println(err);
while (1);
}

//Gradient Libraries and Functions

#include<Wire.h>

const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

int minVal=265;
int maxVal=402;

double x;
double y;
double z;
int count = 0;

void setup() {

Serial.begin(115200);

//BLE

Serial.println(F("Initialising the Bluefruit LE module: "));
if ( !ble.begin(VERBOSE_MODE) )
{
error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
}
Serial.println( F("BLE Active. If using BLE please connect device.") );
Serial.println();
ble.verbose(false);

//Gradient

Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
}

bool getUserInput(char buffer[], uint8_t maxSize)
{
TimeoutTimer timeout(100);

memset(buffer, 0, maxSize);
while( (!Serial.available()) && !timeout.expired() ) { delay(1); }

if ( timeout.expired() ) return false;

delay(2);
uint8_t count=0;
do
{
count += Serial.readBytes(buffer+count, maxSize);

} while( (count < maxSize) && (Serial.available()) );

return true;
}

bool connection_status(){
if(ble.isConnected() && !ble_connection_status)
{
Serial.println("BLE Connected");
ble_connection_status = true;
}

if(!ble.isConnected() && ble_connection_status)
{
  Serial.println("BLE Disconnected");
  ble_connection_status = false;
}

}

void BLE_Comms(){
// Check for user input
char inputs[BUFSIZE+1];

if ( getUserInput(inputs, BUFSIZE) )
{
// Send characters to Bluefruit
Serial.print("[Send] ");
Serial.println(inputs);

ble.print("AT+BLEUARTTX=");
ble.println(inputs);

// check response stastus
if (! ble.waitForOK() ) {
  Serial.println(F("Failed to send?"));
}

}

// Check for incoming characters from Bluefruit
ble.println("AT+BLEUARTRX");
ble.readline();
if (strcmp(ble.buffer, "OK") == 0) {
// no data
return;
}
// Some data was found, its in the buffer
Serial.println(ble.buffer);
ble.waitForOK();
}

void Gradient(){
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);
AcX=Wire.read()<<8|Wire.read();
AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();
Tmp = Wire.read()<<8 | Wire.read();

int xAng = map(AcX,minVal,maxVal,-90,90);
int yAng = map(AcY,minVal,maxVal,-90,90);
int zAng = map(AcZ,minVal,maxVal,-90,90);

x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);

if(x > 90 & x < 270){
x = 0;

}
else if(x > 270){
x = 360 - x;
}

if(y > 90 & y < 270){
y = 0;
}
else if(y > 270){
y = -(360 - y);
}

byte Temperature = (((Tmp/340.00+50.53)*(9/5))+32);

byte X_BLE = x;
byte Y_BLE = y;
char inputs_2[BUFSIZE+1];
itoa(Temperature,inputs_2,10);

if(count == 10){
  count = 0;
}

if(count == 0){
ble.print("AT+BLEUARTTX=");
ble.print("Temperature = ");
ble.println(Temperature);
ble.waitForOK();
delay(200);
}

ble.print("AT+BLEUARTTX=");
ble.print("X Angle = ");
ble.println(X_BLE);
ble.waitForOK();
delay(200);
ble.print("AT+BLEUARTTX=");
ble.print("Y Angle = ");
ble.println(Y_BLE);
ble.waitForOK();
delay(200);
count++;

}

void loop() {
connection_status();
Gradient();
BLE_Comms();
}

Ive posted the code and libraries below

Also the duo does still work on thos rx/tx pins, theyve been verified with a gps module that uses them.

Welcome! Guidelines: Please read the advice in the topic "How to get the best from this forum". How to get the best out of this forum Use code tags<>

:joy: Yeah, right! After I got the Arduino Cookbook (and several others), I started buying Arduinos like they were going out of style!

Yea I did as well but I now have a bunch of projects that are running 24/7 using them:-)

1 Like

The Adafruit Bluefruit LE UART contains an ARM processor with 3.3V logic levels so I do not think there is any damage or need for logic level converters.

Study the tutorial to use the device. For example, the tutorial says use hardware UART with CTS/RTS flow control, if possible, but your schem does not show CTS/RTS.

Where is this "on the board"? What happened, where did it say anything and did you try just the example sketch from the library?

I did try the example from the sketch library, i and it work on a Ardunio UNO, i think that theres something with hos the Ardunio Duo reads/takes in communication v.s. the Arduino UNO

I understand that. Why do you think that?
I notice you don't have this line in your code:

Serial1.begin(115200);

maybe try that

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.