Reading data from a bluetooth port

Hello, I am trying to read data sent by a nRF51822 Bluetooth LE module (Adafruit Feather M0 Bluefruit LE). I modified the bleuart_datamode sketch given as example to send the same data via bluetooth and USB serial. I can see the Bluetooth data on my iPad with the Bluefruit LE connect app so I know that my board is sending stuff in the air. Using processing however I can read the serial data but I get a null string from bluetooth. I suspected a baud rate problem so I tried everything... I don't get any error message though. The code is compiling and running but I get a null string...

Any idea ? Thanks !

import processing.serial.*; 

Serial mySerialPort;          
Serial myBluePort;
PFont myFont;          
String serialString;       
String blueString;
int lf = 10;            // ASCII linefeed aka '/n'

void setup() { 

  frameRate(1000);
  size(400,200); 
  myFont = loadFont("ArialMT-18.vlw");  // Processing>Tools>Create Font 
  textFont(myFont, 18); 
  printArray(Serial.list());  

  mySerialPort = new Serial(this, Serial.list()[1], 115200); 
  mySerialPort.bufferUntil(lf); 

  myBluePort = new Serial(this, Serial.list()[0], 1200); 
  //myBluePort = new Serial(this, Serial.list()[0], 2400); 
  //myBluePort = new Serial(this, Serial.list()[0], 4800); 
  //myBluePort = new Serial(this, Serial.list()[0], 9600); 
  //myBluePort = new Serial(this, Serial.list()[0], 14400);
  //myBluePort = new Serial(this, Serial.list()[0], 19200); 
  //myBluePort = new Serial(this, Serial.list()[0], 28800); 
  //myBluePort = new Serial(this, Serial.list()[0], 38400); 
  //myBluePort = new Serial(this, Serial.list()[0], 57600); 
  //myBluePort = new Serial(this, Serial.list()[0], 76800); 
  //myBluePort = new Serial(this, Serial.list()[0], 115200); 
  //myBluePort = new Serial(this, Serial.list()[0], 230400); 
  //myBluePort = new Serial(this, Serial.list()[0], 250000); 
  //myBluePort = new Serial(this, Serial.list()[0], 460800); 
  //myBluePort = new Serial(this, Serial.list()[0], 921600); 
  //myBluePort = new Serial(this, Serial.list()[0], 1000000); 
   myBluePort.bufferUntil(lf);
} 

void draw() { 

  if ( mySerialPort.available() > 0) serialString = mySerialPort.readString();
  if ( myBluePort.available() > 0) blueString = myBluePort.readString();

  background(0); 
  text("Receiving serial data : " + trim(serialString), 10,20); 
  text("Receiving bluetooth data : " + trim(blueString), 10,40); 

} 
Sign In or Register to comment.