JBT24M Bluetooth Smart Module enabled iPhone and Arduino UNO wireless connection

6 Просмотры
Издатель
iPhone / New iPad Software Download:
Go To App Store Search & Download " Joybien " or " Bluetooth 4.0 UART "


Simplify the wireless connectivity between iPhone 4S and Arduino UNO by using Joybien JBT24M Bluetooth 4.0 BLE Module with Arduino enabled firmware code.

// Bluetooth 4.0 BEL TxRx Project based on Arduion UNO Board
// press Ctrl+Shift+M to open Serial Monit for observing this demostration

void setup()
{
jb_rs232_init(); //* UART Baud rate: 9600/8/n/1
}

void loop()
{
// (step 1) Arduiono UART Tx to Bluetooth Module UART Rx to
//Bluetooth Module RF Tx to Phone Bluetooth RF Rx
arduino_to_phone();
// (step 2) Phone Bluetooth RF Tx to Bluetooth Module RF Rx to
// Bluetooth Module UART Tx to Arduino UART Rx
phone_to_arduino();
}

void jb_rs232_init()
{
Serial.begin(9600); // init 9600/8/n/1
while (!Serial) {;} // wait for UART setup
}
void arduino_to_phone() {
static int jb_show_state = 0;
unsigned long new_t = millis();
static unsigned long old_t = new_t;
switch(jb_show_state){
case 0:
Serial.print("at ");
Serial.print(old_t/1000);
jb_show_state = 1;
break;
case 1:
if((new_t - old_t) GT -1000){ // GT needs to change to
old_t = new_t;
jb_show_state = 0;
}
break;
default:
break;
}
}
void phone_to_arduino()
{
static int inByte = 0; // init

// on Arduino UART Rx event then send out to PC Serial
// Monit with increated by 1
//
if (Serial.available() GT 0) { //GT needs to change
inByte = Serial.read();
Serial.write(inByte + 1);
}
}
Комментариев нет.