Controlling RedBear BLE nRf8001 based devices

62 views
Skip to first unread message

Dave Smart

unread,
Jul 25, 2017, 4:02:42 PM7/25/17
to DroidScript
Hi Guys,

For those of you that might want to easily remotely control ReadBear BLE devices such as the 'Blend Micro' and 'BLE Shield' others we have now implemented the RedBear flavor of UART comms in the DroidScript BLEPlugin.  It makes creating Android apps for these devices 10x easier than using their github samples :) 


You will need to use 1.03 or greater of the DroidScript BLE plugin (an alpha version can be found here):-


Drop it into the DroidScript/Plugins folder on your Android phone and restart DroidScript (create the Plugins folder if it does not exist)



Here is a program to communicate with the 'SimpleControls' sketch from RedBear:-

app.LoadPlugin( "BluetoothLE" );


function OnStart()
{
   
//Create a layout.
    lay
= app.CreateLayout( "Linear", "VCenter,FillXY" );
    lay
.SetBackColor( "#222222" );
   
   
//Create a text box for showing received data.
    txt
= app.CreateText( "", 0.9, 0.6, "Log" );
    txt
.SetBackColor( "black" );
    lay
.AddChild( txt );
   
   
//Create a connect button.
    btn
= app.CreateButton( "Connect", 0.4, 0.1 );
    btn
.SetOnTouch( btn_OnTouch );
    lay
.AddChild( btn );
   
   
//Create an Analog toggle button.
    tglAn
= app.CreateToggle( "Analog Read", 0.4 );
    tglAn
.SetMargins( 0, 0.02, 0, 0 );
    tglAn
.SetOnTouch( tglAn_OnTouch );
    lay
.AddChild( tglAn );
   
   
//Create an LED toggle button.
    tglLed
= app.CreateToggle( "LED", 0.4 );
    tglLed
.SetMargins( 0, 0.02, 0, 0 );
    tglLed
.SetOnTouch( tglLed_OnTouch );
    lay
.AddChild( tglLed );
   
   
//Add layout to app.
    app
.AddLayout( lay );
   
   
//Create BLE component.
    ble
= app.CreateBluetoothLE();
    ble
.SetUartMode( "Hex" );
    ble
.SetOnSelect( OnSelect );
    ble
.SetOnConnect( OnConnect );
    ble
.SetOnUartReceive( OnUartReceive );
}


//Called when 'Connect' button pressed.
function btn_OnTouch( isChecked )
{
  ble
.Select();
}


//Called when user selects BLE device.
function OnSelect( name, address )
{
  ble
.Connect( address, "UART,RedBear" );
}


//Called after device connects.
function OnConnect()
{
  app
.ShowPopup( "Connected!" );
}


//Called when user touches analog button.
function tglAn_OnTouch( isChecked )  
{
   
if( isChecked ) ble.SendUart( "A0,01,00" );
   
else ble.SendUart( "A0,00,00" );
}


//Called when user touches LED button.
function tglLed_OnTouch( isChecked )  
{
   
if( isChecked ) ble.SendUart( "05,01,00" );
   
else ble.SendUart( "05,00,00" );
}


//Called when data arrives from board.
function OnUartReceive( data )
{
  txt
.Log( data );
}


Attached to this post is also a slightly modified version of the 'SimpleControls' sketch which allows you to remotely toggle the Arduino's LED button on and off.

:)




SimpleControls.ino
Reply all
Reply to author
Forward
0 new messages