• Enter email to sit in the first row

Here is the new bbmagic_lib_1.4 for Raspberry Pi


bbmagic_lib_1.4 miniatura
bbmagic_lib is a library for communication with BBMagic Bluetooth Smart modules. It is compatible with Raspberry Pi zero W and Raspberry Pi 3 which have Bluetooth Low Energy chip onboard.

Whats new in bbmagic_lib_1.4

Communication with BBMagic DIMMER

int bbm_bt_dimmer(unsigned char *dest_bd_addr, unsigned char *chan) ;
  • unsigned char *dest_bd_addr – pointer to the table contains destination BBMagic DIMMER modules address. Table has six bytes.
  • unsigned char *chan – pointer to the table contains three PWM values of three channels 0, 1 and 3

Example:
Turn on all three PWM channels of BBMagic DIMMER module which has 0xFE4FF394EECD address:

unsigned char bd_addr_dimmer_1[6] = {0xFE, 0x4F, 0xF3, 0x94, 0xEE, 0xCD} ;
unsigned char dimm_val[3] = {0, 0, 0} ;
int i = bbm_bt_dimmer(bd_addr_dimmer_1, dimm_val) ;

Set channel 0 to 10% (25/255), channel 1 to 78% (200/255), and channel 2 to 100%:

dimm_val[0] = 25; dimm_val[1] = 200; dimm_val[2] = 255;
i = bbm_bt_dimmer(bd_addr_dimmer_1, dimm_val) ;

Communication with BBMagic RELAY module

int bbm_bt_relay_on(unsigned char *dest_bd_addr, unsigned char relays) ;
  • unsigned char *dest_bd_addr – pointer to the table contains destination BBMagic RELAY modules address. Table has six bytes.
  • unsigned char relays – flags that point which relay to turn on
    • #define BBM_RELAY_0 1
    • #define BBM_RELAY_1 2
    • #define BBM_RELAY_2 4
    • #define BBM_RELAY_3 8
int bbm_bt_relay_off(unsigned char *dest_bd_addr, unsigned char relays) ;
  • unsigned char *dest_bd_addr – pointer to the table contains destination BBMagic RELAY modules bluetooth six bytes address
  • unsigned char relays – flags that point which relay to turn off
    • #define BBM_RELAY_0 1
    • #define BBM_RELAY_1 2
    • #define BBM_RELAY_2 4
    • #define BBM_RELAY_3 8

BBMagic RELAY relays pinout
Example:
Turn on relays 0 and 3 of the BBmagic RELAY module which has 0xFE43E394DEEE address:

unsigned char bd_addr_test[6] = {0xFE, 0x43, 0xE3, 0x94, 0xDE, 0xEE} ;
int i = bbm_bt_relay_on(bd_addr_test, BBM_RELAY_0 | BBM_RELAY_3) ;

Turm off RELAY_3 output of the module which has 0xFE43E394DEEE address:

int i = bbm_bt_relay_off(bd_addr_test, BBM_RELAY_3) ;

Possibility to turn on and off console messages

int bbm_bt_open(0, 0, 0, int op_mode) ;
  • op_mode equal 0 – bbmagic_lib is quiet
  • op_mode different 0 – console messages are ON

Three LEDs indication available

int bbm_bt_open(int led_rx_pin, int led_tx_pin, int led_run_pin, int op_mode) ;
  • led_rx_pin – receiving bbmagic bluetooth data indication pin, range from 2 to 27.
  • led_tx_pin – sending bbmagic bluetooth data indication pin, range from 2 to 27.
  • led_run_pin – work indication pin, range from 2 to 27.

Values greater than 27 and smaller than 2 turn off indication.
Example:
Rx indication on pin GPIO02, tx indication on pin GPIO03 and run indication on pin GPIO04:

i = bbm_bt_open(2, 3, 4, 0) ;

Rx indication on pin GPIO26, tx indication on pin GPIO19. Work indication is turned off:

i = bbm_bt_open(26, 19, 0, 0) ;

RPI0 RPI3 pinout

Bluetooth MAC address reading available

unsigned char bd_addr[6] ;
int len = bbm_bt_addr_get(bd_addr) ;
printf("my_bt_mac: ") ;
if(len)
{
    do { len-- ; printf("%0.2X", bd_addr[len]) ; } while(len>0) ;
    printf("\n") ;
}else
{
    if(len == -1) printf("bt not opened, use bbm_bt_open(..) first") ;
    else printf("reading error !!\n") ;
    exit(1) ;
}

New library is avilable here: Download

Tagged , , . Bookmark the permalink.

Comments are closed.