Go Down

Topic: Bluetooth programming questions (Read 22 times) previous topic - next topic

Hi fellow programers ,

Lemme introduce me first , I'm a french student who currently work on a project called "reproduce a daft punk helmet" for my final exam.

I am working with 2 meters of Adafruit 60LED/M strip and acheived something like this for the visor :



The helmet itself is currently being made by a friend of mine.


#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
 #define PSTR
#endif
#define PIN 4

#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 2
#define TxD 3

SoftwareSerial blueToothSerial(RxD,TxD);
String chRecue="";
char recvChar=0;

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(14, 7, PIN4,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, //montage en zigzag : on inverse un bandeau sur 2
NEO_RGB + NEO_KHZ800);

const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };



void setupBlueToothConnection()
{
  blueToothSerial.begin(9600);                           // Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n");             // set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n");    // set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n");             // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n");             // Auto-connection should be forbidden here
  delay(2000);                                            // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n");                // make the slave bluetooth inquirable
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000);                                            // This delay is required.
  blueToothSerial.flush();
}

void setup()
{

  matrix.begin();
  matrix.setTextWrap(false);//bandeau non fermé
  matrix.setBrightness(20);//luminosité des led
  matrix.setTextColor(colors[0]);//init couleur

  Serial.begin(9600);
  Serial.println("init");
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();

}

int x = matrix.width();
int pass = 0;

void loop()
{
  if(blueToothSerial.available())
  {//check if there's any data sent from the remote bluetooth shield
    recvChar = blueToothSerial.read();
    chRecue = chRecue + recvChar;
    Serial.print(recvChar);

    if(recvChar == 13)
    {
      matrix.fillScreen(0);
      matrix.setCursor(x, 0);
      matrix.print(chRecue);
      chRecue="";
    }
  }
  matrix.show();
    delay(100);
}

^ This program is supposed to allow me to connect to any bluetooth device , and display the characters inputted with the usual blutooth monitor , but even with the help of some teachers , we can't get it to work ...

It connect with my BT Monitor on my phone , but impossible to do anything else than that , my module is a Seeestudio shield v2.

I'm here to see if there's any problem with my program and if any of you can provide me with some help.

P.S : Sorry if you see some grammar error , I'm french so it's a little weird to post in english)


Nick_Pyner

I cannot comment on the LEDs, but the bluetooth stuff has me curious and there is a similar thread around at the moment.

For starters, this line
Quote
blueToothSerial.begin(9600);     // Set BluetoothBee BaudRate to default baud rate 38400
is complete nonsense, possibly unnecessary, and also possibly the cause of all your problems.

The command will not set the bluetooth baud rate at 38400, it will not even set the baud rate at 9600. What it does do is tell Arduino to operate at 9600 on the defined port, but that won't do you much good if Bluetooth is set at 38400 by default.

The first thing you need to do is find out what the default baud rate really is. It doesn't really matter what it is, I don't think you would need to change it, but you do need to ensure that Arduino works at the same rate.

I think the bluetooth code is complete junk. I might be wrong but, if that is the case, I submit you have made a pretty bad choice of bluetooth device. Indeed, since I understand this is a wearable device, I think you have made a bad choice anyway.

In the matter of the code, you should be able do what you want with no more code than you would send from a serial monitor. The idea of having to set the Bleutooth name as "SeedBTSlave" every time you switch it on is absolute nonsense.

In the matter of the shield, you might consider putting it on eBay and getting simple JY-MCU module. The actual electronics are the same, it is much cheaper, it is surely more appropriate to the job, and the code is commonly available about a thousand times more sensible.

To get started, you might find this useful

homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

and some background here

homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf

You might even find it will work with the Seed shield. So try it!

Note that Arduino is not involved with the connection between bluetooth and phone.

Robin2

Have a look at serial input basics for simple reliable ways to receive data.

...R

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy