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
Appreciate to anyone can help!