processing and arduino + bluetooth

Hi,
I've recently worked on a project which wants to receiving data from arduino to processing via bluetooth module(Hc-05).

What I'm trying to do is simply sending ' 1 ' or '0 ' to tell processing to draw a string(like ' 1 ' = taichi, ' 0 ' = FLOW)

arduino code

#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); // RX, TX

const byte ledPin = 13;
char val;

void setup() {
  pinMode(ledPin, OUTPUT);

  BT.begin(9600);
  BT.println("Happy Birthday!");
   
}

void loop() {
  if (BT.available()) {
   val = BT.read();
   switch(val){
    case '0':
     digitalWrite(ledPin, LOW);
      break;
    case '1':
     digitalWrite(ledPin, HIGH);
      break;
   }
  }     
}

processing code

import processing.serial.*;

Serial BT;
float val;
PFont f;

void setup(){
  size(640, 360);
  
  //printArray(PFont.list());
  f = createFont("Serif-48.vlw", 24);
  textFont(f);
  
  println(Serial.list());
  BT = new Serial(this, "/dev/cu.HC-05-DevB", 9600);
}

void draw(){
  if(BT.available()>0){
    // read the value from serial port
    val = BT.read();
    println(val);
    
    background(255);
    textAlign(CENTER);
    drawType(width * 0.25);
  }
}

void drawType(float x){
  if(val > 0){
  line(x, 0, x, 65);
  line(x, 220, x, height);
  fill(0);
  textSize(36);
  text("taichi", width * 0.5, height * 0.5);
  }
  
  if(val <= 0){
    fill(0);
    textSize(72);
    text("FLOW", width * 0.5, height * 0.5);
  }
}

I use CoolTerm to build up the bluetooth serial connection, however, when I ran processing I got this message:
Error opening serial port/dev/cu.HC-05-DevB: Port busy :confused:

Appreciate to anyone can help!

What I'm trying to do is simply sending ' 1 ' or '0 ' to tell processing to draw a string

That is NOT what the Arduino is doing.

void draw(){
  if(BT.available()>0){

You should NOT be doing serial i/o in draw(). Do it in a function called serialEvent(), after using the bufferUntil() method in setup(), to define when serialEvent() should be called.

You have two readers and zero writers. No wonder nothing happens. No one is talking.

PaulS:
That is NOT what the Arduino is doing.

Thanks for reply

Would you please explain more specific about this?

If I want to send data() from arduino to processing by sensor(i.e. humidity sensor, LDR, or else),
how can I program it? Any reference I can study it?

Would you please explain more specific about this?

Processing is supposed to be listening, for specific input, isn't it? That is why it is doing Serial.read().

So, that means that whatever is at the other end of the port needs to be writing, doesn't it?

Writing is not done using xx.available() and/or xx.read(). It is done using xx.write(), xx.print(), or xx.println() (where xx is an instance of HardwareSerial or SoftwareSerial).

If I want to send data() from arduino to processing by sensor

You'll have a very difficult time sending a function to Processing by using a sensor. You could read data from a sensor and send that data to Processing.

   int lightLevel = analogRead(lightSensorPin);
   BT.println(lightLevel);