10 years ago.

Problem using p9 and p10 while use the rn 42 bluetooth module

Hi,

My computer is connected through bluetooth with the r42 module. I use Tera Term as a terminal. The program I am testing should do the following: - when I press 'z' led1 should light up - when I press 'q' led2 should light up - when I press 's' led3 should light up - when I press 'd' led4 should light up

I am using mbed NXP LPC1768.

Edit: after testing the "readable", it turns out it always returns false. How can I change this?

Here is my code:

#include "mbed.h"
 
//Serial pc(USBTX, USBRX); // tx, rx
Serial device(p9, p10);  // tx, rx
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
 
int main() 
{
        device.baud(115200);
        
        myled1 = 1;
        myled2 = 0;
        myled3 = 0;
        myled4 = 0;
        wait(0.3);
        myled1 = 0;
        myled2 = 1;
        myled3 = 0;
        myled4 = 0;
        wait(0.3);
        myled1 = 0;
        myled2 = 0;
        myled3 = 1;
        myled4 = 0;
        wait(0.3);
        myled1 = 0;
        myled2 = 0;
        myled3 = 0;
        myled4 = 1;
        wait(0.3);
        myled1 = 0;
        myled2 = 0;
        myled3 = 0;
        myled4 = 0;
    
    while(1) 
    {
        if(device.readable()) 
        {
            int c = device.getc();
            switch(c)
            {
                case 'z':
                    //up code
                    myled1 = 1;
                    myled3 = 0;
                    myled2 = 0;
                    myled4 = 0;
                    wait(1);
                    break;
                    
                case 'q':
                    //left code
                     myled1 = 0;
                     myled2 = 1;
                     myled3 = 0;
                     myled4 = 0;
                     wait(1);
                    break;
                    
                case 's':
                    //down code
                     myled1 = 0;
                     myled2 = 0;
                     myled3 = 1;
                     myled4 = 0;
                     wait(1);
                    break;
                    
                case 'd':
                    //right code
                    myled1 = 0;
                    myled2 = 0;
                    myled3 = 0;
                    myled4 = 1;
                    wait(1);
                    break;
                
                default:
                    break;
            }
        }
        
    }
}

What did I do wrong?

1 Answer

10 years ago.

Above you write that the LED on the controller blinks when you press a key. Is that the single LED near the USB connector? In that case you probably still send teraterm data through USB instead of via Bluetooth and the mbed never receives anything on p9/ p10. Check the com port in teraterm. BTW you can use serial USB for debugging at the same time as p9/p10. Is the r42 connected correctly: power, gnd, tx to mbed rx, rx to mbed tx.

Accepted Answer

I have indeed selected the wrong port in teraterm but even after I changed it, the readable still returns false and none of the leds light up.

posted by Jil Van Wetter 05 May 2014

Is the wiring correct. Is baudrate correct, mbed default is 9600. Are you sure BT devices are paired. You could test by connecting r42 tx to its rx and create an echo loop for teraterm. The r42 may need some configuration first. You can do that by using a simple mbed program that forwards all characters between USB and r42 in both directions and run a second teraterm

posted by Wim Huiskamp 05 May 2014

The problem was indeed the baudrate. Thank you for the help.

posted by Jil Van Wetter 09 May 2014