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

Read measurements from nRF52840, and do very complicated processing on PC terminal using CPU resources of PC.

I have successfully run the SAADC example, and make it a multi-channel example. I see the function saadc_callback(nrf_drv_saadc_evt_t const * p_event)  which performs the printing tasks on PC.

I can place the data processing algorithm (very very complicated like deep reinforcement learning) in the saadc_callback function, but worried that it will consuming the CPU and memory resources of the chip. Therefore, I want to place the algorithm on the PC terminal to use CPU resources of the PC. 

How shall I achieve this?

Thanks very much.

  • Hello,

    Yes. It is possible to do the sampling on the nRF, and just pass the data to a computer via a serial connection, such as UART or a USB connection. What sort of HW do you use? I see that it is an nRF52840, but is it a DK or a Dongle? Or is it a custom board?

    The saadc example does already pass the readings to the logging module. If you want to remove the wrappings, you can use NRF_LOG_RAW_INFO(); instead of NRF_LOG_INFO();

    Or do you want to transfer the data over BLE?

    Best regards,

    Edvin

  • Hi Edvin,

    Thanks very much for your reply. I'm using nRF52840 DK, and want to transfer the data over BLE to PC, read the data from PC side, and do processing in real time.

    I'm a newbie to nRF, and has very basic programming experience. Currently, I only play with the SAADC example, haven't touched the UART example yet.

    I know how to read measurements with the DK, but don't understand how the measurements is transmitted out through BLE.

    Best regards,

    Lichun

  • Hello Lichun,

    I understand.

    Most PCs, at least newer laptops support BLE today, but without a custom application it is quite limited. It will by default only look for Bluetooth or BLE devices that it knows it can interact with, such as Bluetooth Headsets, BLE mice or keyboards, and other computer equipment. (By the way, pretending to be a keyboard is not the way you want to go).

    What you want to do is to have a BLE service where you can transfer custom data from one end to the other end of the BLE link. There are a couple of ways to do this.

    1: You can write a custom computer application, and use the bluetooth radio on the PC, if it has one, to interpret the data. I have seen some BLE applications for PCs. Not something easy and intuitive, and I don't know if it is open source, but you can check out e.g. Bluetooth LE Explorer.

    2: I recommend this one, if you want to set it up without getting too deep in the BLE protocol, and how it works.

    If you have one nRF device on each end, you can program them with an application where one device is the peripheral device, which does the ADC measurements, and sends them over BLE to the other device, which is connected to your computer. The device connected to your computer can transmit the received messages through UART to your computer.

    If you have tested the SAADC example, you have probably used the UART already to see the readings, is that correct? You have if you have used a UART terminal, such as Putty or Termite to see the readings in realtime.

    We do have a set of examples that does what I described in option 2. look at the examples ble_app_uart and ble_app_uart_c from the SDK. Basically, when they are both turned on, they will connect to each other, and whatever is received on the UART on one of the devices will be transmitted to the other device over BLE and will be sent out on the UART on the other device, and vice versa.

    What you would have to do is to import the SAADC part from the saadc example into the ble_app_uart example, and send the measurements over the ble link instead of the incoming UART messages. Look for the ble_nus_data_send() function call in main.c in the ble_app_uart example.

    Best regards,

    Edvin

Related