This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Read data from nRF51 to MATLAB

Hi all, i'm continuing the exploration of the possibilities offered by BLE. I tried the example ble_app_uart on my nRF51 DK, sending for example the number "1" from my phone to the DK (in future i will send sensor data), which is connected via USB to my pc. On Matlab, i open the serial port COM3 where the board is connected, and i read it, receiving the data. The problem is that if i simply use "app_uart_put" function to send something written by me in the code (an int number for example), i can read it correctly on matlab, but with the data sent from the phone, received by the DK and the sent to the COM port via UART, i get strange result, like:

I send "5" from the phone ----> i receive 53 10 on Matlab; I send "6" from the phone ----> i receive 54 10 on Matlab; I send "7" from the phone ----> i receive 55 10 on Matlab;

So something is actually read correctly, but it looks like there is some coding problem or something similar, due to the transmission from the uart app on the phone, and the receiving nRF board (i guess).

How can i solve this and read correctly the data?

  • 53 10 in hex is 0x45 0x0a. 0x45 is the digit '5' in ASCII and 0x0a linefeed, or an end of line. 54 is 0x46, or the digit '6' and I think you can work out the rest.

    You're receiving ASCII strings, with linefeeds at the end of each character.

  • Perfect thank you, and so how can i receive in Matlab directly the decimal (or float for future application) value? Shall i do some conversion to the data received by the DK board before sending it to the COM port or convert it later on Matlab?

  • Hello,

    I think you can help me. I can't manage to read data from nRF51 DK to Matlab using an nRF51 dongle. In my case, I have stored data in PCA10028, I can open the serial port corresponding to the nRF51 dongle in Matlab. I can also visualize packets on nRF Connect.

    Do I need special functions for reading and writing data in Matlab? Now, I am coding : obj = serial('COM12'); fopen(obj); a=get(obj); record(obj,'on'); UUID = ['2A','00']; dec=hex2dec(UUID); fwrite(obj,char(dec)'); [R,count] = fread(obj);

    and always have in return : Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period..

    ans =

    1×0 empty double row vector

    Thank you in advance,

    BCI

Related