SOLVED: Getting Started Qt Bluetooth Smartphone<=>µController



  • Hello there,

    i want to share with my Bluetooth getting started project which uses the BT´s serial protocoll profile, which is implemented in the chat example.
    In this first step i made up a connection between an XPeria Z2 and a Mega8 µController.
    By reading general BT docs and specific Qt BT docs i had difficulties to figure out, what i really have to do to get a first flash-and-play demo.

    Specs:

    • Mega8 Controller with external 16Mhz crystal one LED on PORTD 6 and 7, a HC-06 in default configuration/ be aware, that RX of the HC goes to TX of Mega8 and vice versa!!
    • Customized BT Example "Bluetooth Chat"

    The first thing you need to do is pairing the HC-06 with the frontend device. This has nothing to do with Qt in paticular - it´s a norma BT thing.
    The Chat example sets a UUID filter.
    m_discoveryAgent->setUuidFilter(uuid);
    U need to comment out that line in the "remoteselector.cpp" file. This makes the example to show any found BT device in the range.
    If u flash the code below to a mega8 and send a 'U' char via the Chat the LED on PORTD6 should light up and a "On" message should be returned to the chat.
    If u send 'D', LED turns off and "Off" is send to the chat.
    If you want to check, what the HC-06 "sees", a UART<>USB brige and a terminal programm is very handy!!

    Mega8 Code:
    #include <avr/io.h>
    #include <stdint.h>

    int main(void)
    {

    /* Set baud rate for 9600 Baud*/
    UBRRH = (unsigned char)(0);
    UBRRL = (unsigned char)103;
    /* Enable receiver and transmitter /
    UCSRB = (1<<RXEN)|(1<<TXEN);//
    //UCSRB = (1<<RXEN);
    /
    Set frame format: 8data, 2stop bit */
    UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
    DDRD = 0b11000010;
    PORTD = 0b10000000;

    while(1)
    {
    char udrData;

    if(UCSRA & (1<<RXC))
    {
    	udrData = UDR;
    	if(udrData == 'D') 
    	{
    		PORTD &= ~0b01000000;
    		while ( !( UCSRA & (1<<UDRE)) );
    		UDR = 'O';
    		while ( !( UCSRA & (1<<UDRE)) );
    		UDR = 'f';
    		while ( !( UCSRA & (1<<UDRE)) );
    		UDR = 'f';
    		while ( !( UCSRA & (1<<UDRE)) );
    		UDR = '\n';
    	}
    	else if(udrData == 'U') 
    	{
    		PORTD |= 0b01000000;
    		while ( !( UCSRA & (1<<UDRE)) );
    		UDR = 'O';
    		while ( !( UCSRA & (1<<UDRE)) );
    		UDR = 'n';
    		while ( !( UCSRA & (1<<UDRE)) );
    		UDR = '\n';
    	}
    }
    

    }
    }



  • I have made a demo video
    The "interesting" part is from 8:40. The first part is some background reflecting the way to go.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.