View unanswered posts | View active topics It is currently Tue Aug 22, 2017 4:36 pm



Reply to topic  [ 22 posts ]  Go to page Previous  1, 2, 3  Next
BGLib C Library 
Author Message

Joined: Thu Aug 23, 2012 11:41 pm
Posts: 9
I'm taking a "rapid prototyping" approach to the project and using an Arduino like you did.

My wiring is super simple:
    Arduino RX (pin 10, set in SoftwareSerial)-> BLE112 P0_4 (UART channel 1, alternate 1)
    Arduino TX-> 5v-3v3 voltage divider-> BLE112 P0_5
With the hardware configuration file:
Code:
<?xml version="1.0" encoding="UTF-8" ?>

<hardware>
    <sleeposc enable="true" ppm="30" />
    <sleep enable="false" />
    <usb enable="false" />
    <txpower power="15" bias="5" />
    <script enable="false" />
    <usart channel="1" mode="uart" stop="high" start="low" stopbits="2" alternate="1" baud="19200"  endpoint="api" flow="false" />
    <port index="0" tristatemask="0" pull="down" />
    <wakeup_pin enable="true" port="1" pin="0" state="0" />
    <slow_clock enable="false" />
</hardware>


But most of this isn't necessary and can be paired down to this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
-<hardware> <sleeposc ppm="30" enable="true"/> <sleep enable="false"/> <txpower bias="5" power="15"/> <usart endpoint="api" flow="false" baud="19200" alternate="1" channel="1"/> </hardware>

I haven't tested this configuration though.

I can't post all my project here as I've integrated it with some code we're deploying for our client, but over the next week or two I hope to put together an Arduino library for interfacing with the BLE112 module. I'll post here with my ideas for it when I get a chance to think about it a bit more in this context - damn moving is taking all my time!

Phooto:

If you have your hands on the C code that they supply, interfacing is fairly trivial. You need to write two architecture dependent functions and link the write function to their library. Here's some of my code that does this for the Arduino:

Code:
void
BLE_Initialize ( void )
{
    #ifdef ARDUINO
    // Initialize the serial interface
    bleDevice.begin( BLE_UART_BAUD, 2 ); // Changed library to use 1,2,etc stop bits
    bleDevice.listen();
   
    // Clear the read buffer on the Arduino
    while ( bleDevice.available() )
    {
        bleDevice.read();
    }
    #endif // ARDUINO
   
    // Assign a function to bglib_output function pointer
    bglib_output = BLE_OutputData;
}


/** Function linked to bglib_output to send data of the com port.
 *  This function should remain unchanged, architecture specific code should be
 *  placed in WriteBuffer.
 */
void
BLE_OutputData (
    uint8 len1,
    uint8* data1,
    uint16 len2,
    uint8* data2
)
{   
    // Try to write both buffers and exit if failure.
    if ( BLE_WriteBuffer ( len1, data1 ) || BLE_WriteBuffer( len2, data2 ) )
    {
    }
}

/** Architecture-dependant handling of writing values.
 */
uint8
BLE_WriteBuffer (
    uint16 bufferLength,
    uint8* buffer
)
{
    // Error code to return, see ERROR_CODES enum.
    uint8 errorCode = 0;
   
    // Number of bytes written.
    uint16 writeLength = 0;
   
    #ifdef ARDUINO
    // Write to the serial port
    writeLength = bleDevice.write( buffer, bufferLength );
    #endif // ARDUINO
   
    // Compare lengths
    if ( writeLength != bufferLength )
    {
        errorCode = 1;
    }
   
    return errorCode;
}

/** Architecture-dependant handling of reading messages.
 */
int
BLE_ReadMessage ( void )
{
    // Return code, 0 for no error, negative for error
    int errorCode = 0;

    /* Read 4 bytes from the buffer, these four bytes represent:
        0 - type_hilen (message type and the highest bytes ofmessage length)
        1 - lolen (lowest bits of message length, enough for allowing 256 bytes length)
        2 - cls (message class)
        3 - command
    */
    #ifdef ARDUINO
    if ( 4 < bleDevice.available() )
    {
       
        // Holds header information so it can be parsed
        struct ble_header messageHeader;
       
        // Holds information returned by ble_get_msg_hdr
        const struct ble_msg* apiMsg;

        // Assign the header structure to have the values in the incoming message.
        messageHeader.type_hilen = bleDevice.read();
        messageHeader.lolen = bleDevice.read();
        messageHeader.cls = bleDevice.read();
        messageHeader.command = bleDevice.read();
       
        // Holds the data read from the serial port, I'm making this much larger than necessary
        unsigned char dataBuffer[256];
       
        /* If the message header defines a message length greater than 0, we'll
            need to read more data.  The length needed to read is "lolen", hilen
            shouldn't be necessary because messages shouldn't be more than 256
            bytes long.  Read bytes from the serial port into the data buffer until
            lolen is reached.
        */
        if ( 0 < messageHeader.lolen )
        { 
            // When populating the data buffer we need to keep track of the bytes read.
            int bufferPointer = 0;
           
            // While we haven't as many bytes as are available, keep reading.
            while ( bufferPointer < messageHeader.lolen )
            {
           
                // If there is a byte available, read it into the buffer and
                // increment the buffer position pointer.
                if ( 0 < bleDevice.available() )
                {
                    dataBuffer[ bufferPointer ] = bleDevice.read();
                    bufferPointer++;
                }
            }
        }
       
        // Process the header
        apiMsg = ble_get_msg_hdr( messageHeader );
       
        // Check if apiMsg is null and if it is, signal an error
        if ( apiMsg )
        {
            // Process the message and do the task, this is where things happen.
            apiMsg->handler( dataBuffer );   
        }
        // Error occured: apiMsg returned NULL
        else
        {
            errorCode = -1;
        }
    }
   
    #endif // ARDUINO
   
    return errorCode;
}


Hope that shotgun spray of random thoughts can actually help anyone, don't hesitate to ask questions or ridiculous my lack of clarity.

EDIT: I could base this Arduino library around your shield if I had a shield or two... /hint


Fri Aug 31, 2012 10:57 pm
Profile

Joined: Thu Aug 30, 2012 8:56 pm
Posts: 3
I've tried the code that you've included with Arduino and BLE Shield.
I started with very simple code, that just advertise the device: "ble_cmd_gap_set_mode (2,2);"

When it gets to "ble_cmd_gap_set_mode (2,2);" very weird things start to happen (the Arduino become non responsive and when I tried to debug with Serial, it really behaved badly).
I tried both versions that I could find on Blue Giga (Beta and non Beta) and non of them worked.

Can you please include the BGLib source files that you use?
Thanks.


Thu Sep 06, 2012 10:56 pm
Profile
Site Admin

Joined: Thu Aug 02, 2012 11:36 am
Posts: 166
Hi guys,
is this making any progress?
I'd like to move on this soon and create a 3.3v 8MHz Arduino Leonardo equipped with a BLE112 as well.
Maybe we can work on such a board together and design a board, bootloader and the firmware for the BLE112 as well.
What do you guys think?

BTW: I'm off one week for diving and cannot respond to posts during this time. Hope to read any responses to my suggestions when I'm back.

Cheers,
Michael.


Fri Sep 21, 2012 6:26 pm
Profile WWW

Joined: Thu Aug 23, 2012 11:41 pm
Posts: 9
uzi_hs wrote:
I've tried the code that you've included with Arduino and BLE Shield.
I started with very simple code, that just advertise the device: "ble_cmd_gap_set_mode (2,2);"

When it gets to "ble_cmd_gap_set_mode (2,2);" very weird things start to happen (the Arduino become non responsive and when I tried to debug with Serial, it really behaved badly).
I tried both versions that I could find on Blue Giga (Beta and non Beta) and non of them worked.

Can you please include the BGLib source files that you use?
Thanks.


I've gone ahead and put together a test for getting BGLib running for other people. I have the files needed for the Arduino sketch, the BLE112 firmware, and a modification. This will not work out-of-the-box for you (unless you randomly have the same configuration as I do) so you will need to do a few things.

1) In BGLibTest.ino you will need to change the pins of the SoftwareSerial module to be the pins on the shield (I have them as pins 10 and 11)

2) In the same file, change DEBUGGING_PIN to whatever pin you want to go HIGH when the device is working (i.e. when it sees the boot event, sends out a "hello handshake", and sees the handshake returned). For at least the Arduino Mega, setting this pin to 13 will cause an LED on the board to light up which is simple to see.

3) In the hardware.xml file in the BGLib testing firmware directory, change the UART channel and alternative number to be whichever the BLE112 shield uses, or that you are using.

4) Switch your SoftwareSerial library files with mine - all I changed was making it possible to have two stop bits instead of the default one. This should not effect other projects.

5) Compile the Arduino code by placing the folder where your other Arduino sketches are and opening the IDE, and compile the firmware using Bluegiga's bgbuild.exe program.

6) When both device have been flashed, reset the Arduino, wait a second (any time longer than instantly) and then reset the BLE112 module so that the UART doesn't get messed up by the Arduino pulling the BLE112's RX low.

Let me know if you need any more help.


Attachments:
File comment: Arduino sketch
BGLibTest.zip [21.72 KiB]
Downloaded 612 times
File comment: Firmware files for the BLE112
BGLibTestBLEFirmware.zip [91.39 KiB]
Downloaded 645 times
Fri Oct 05, 2012 12:05 am
Profile

Joined: Thu Aug 23, 2012 11:41 pm
Posts: 9
I wasn't able to upload my SoftwareSerial change in the last post, I've attached it now.


Attachments:
File comment: Save a version of your old SoftwareSerial before putting this in, just in case.
SoftwareSerial.zip [8.5 KiB]
Downloaded 629 times
Fri Oct 05, 2012 12:11 am
Profile

Joined: Thu Aug 23, 2012 11:41 pm
Posts: 9
mkroll wrote:
Hi guys,
is this making any progress?
I'd like to move on this soon and create a 3.3v 8MHz Arduino Leonardo equipped with a BLE112 as well.
Maybe we can work on such a board together and design a board, bootloader and the firmware for the BLE112 as well.
What do you guys think?

BTW: I'm off one week for diving and cannot respond to posts during this time. Hope to read any responses to my suggestions when I'm back.

Cheers,
Michael.


I'm willing to help, although you'll need to expand more on what you're thinking exactly.


Fri Oct 05, 2012 12:14 am
Profile
Site Admin

Joined: Thu Aug 02, 2012 11:36 am
Posts: 166
Hi Paul,
this sounds good. I will give it a try over the weekend.

@Uzi have you tried tried it already ?

Cheers,
Michael.


Fri Oct 05, 2012 10:39 am
Profile WWW

Joined: Thu Aug 30, 2012 8:56 pm
Posts: 3
No, I haven't.
I'm currently using the BLE112 in a standalone mode.
Thanks,
Uzi


Fri Oct 05, 2012 2:41 pm
Profile

Joined: Thu Aug 30, 2012 9:21 pm
Posts: 3
PaulBuckley has graciously assisted me with his sample code seen above. I am using Dr. Kroll's ble shield 0.9.2 design.

Unfortunately, I cannot get communication (ble_hello) working with arduino Duemilanove on switch setting 2/3.

My hardware.xml matches PaulBuckley's provided sample.

1. Is the <usart /> entry PaulBuckley provides compatible with the 0.9.2 version of the BLEShield as it is designed? Is version 0.9.2 known to work in this configuration?

2. If so, can I only then determine that this must be a faulty board assembly?

Any suggestions / further guidance would be greatly appreciated.


Fri Oct 05, 2012 6:23 pm
Profile
Site Admin

Joined: Thu Aug 02, 2012 11:36 am
Posts: 166
Hi,

I have not yet tried Paul's code but I will do over the weekend.
Have you been able to run the test Sketch for SoftwareSerial using pin 2/3 successfully?
The sketch is attached to this post.

Please install it on your Arduino and connect even with BLEGUI2 using BLED112 or an iPhone using BLExplr to test.
Enable notify on RX to see if there is data send from the Arduino and open the Serial Monitor with Baudrate 19200 in order to see data which is sent from BLExplr "Write String" to the Shield.

Is this working?
You are using a self soldered BLE-Shield, since I think you are not a member of the BLE Shield beta, right?

Cheers,
Michael.


Attachments:
BLEShieldSS-0_9_2.zip [725 Bytes]
Downloaded 599 times
Fri Oct 05, 2012 8:48 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 22 posts ]  Go to page Previous  1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.