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

Sending SAADC over BLE?

I am trying to combine both the SAADC and BLE libraries to be able to read a value from my sensor on the analog pin and then send it over Bluetooth LE to a central dongle.

I have experimented with the /examples/peripheral/saadc example as well as the /examples/ble_peripheral/ble_app_uart. It seems that both of these examples do what I need but separately. However, when I try to combine them I experience a lot of issues.

Firstly, copying the saadc code verbatim over to the ble_app_uart code results in the LED flashing very rapidly and the output over serial to be garbage. I have narrowed down this problem being due to the fact that the APP_TIMER and Timer0 are going at the same time.

Next, I looked at the example code in this very helpful thread: devzone.nordicsemi.com/.../

And for testing purposes added the following code to the on_ble_evt handler for the condition BLE_GAP_EVT_CONNECTED:

printf("\n\rSAADC HAL simple example.\r\n");
nrf_saadc_task_trigger(NRF_SAADC_TASK_START  );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP  );

This code resulted in UART showing me the values being captured from SAADC, but all of these values are 0.

I am at a loss here after trying to figure this out for several days now. Could anybody steer me into the right direction for accomplishing this task that seems should be very simple?

TL;DR I am trying to connect a peripheral to a central device with BLE. The peripheral will be using SAADC to read the analog input 0 and will send these values to the central device so that the central device can print it out over UART. I cannot seem to figure out how to combine the two examples given.

Parents
  • Hi Filip

    Below is an example which is a ble_app_uart example combined with the SAADC example. It is based on nRF5 SDK 11.0.0 and I have tested it with softdevice S132 2.0.0 and the PCA10040 development board.

    ble_app_uart__saadc_timer_driven.zip

    The example samples on pin AIN0/P0.02 and outputs the result both on hardware UART and transfers it over BLE via the NUS service. You can adjust the samling rate by adjusting the SAADC_SAMPLE_RATE_DIVIDER constant and you can adjust the size of the SAADC RAM buffer by adjusting the SAADC_SAMPLES_IN_BUFFER constant.

  • Wow Stefan this is wonderful! I downloaded the code and ran it, and it is working perfectly! I am going to read through the code thoroughly to understand how you got it to work versus what I had been attempting.

    However, I do have one question: the analog results that I am getting are very bad. For instance, running your code gives me values between 20 and 30 for the output and when I directly apply 5V to AIN0/P0.02 it goes up to 587. Shouldn't the range be between about 0 and 1023?

    Also, utilizing the circuit diagram here (www.sparkfun.com/.../389) the values don't have a noticeable difference in the example, but when I use an Arduino they do. Is my only option to use larger gains and account for the fact that a lot of noise will always exist?

Reply
  • Wow Stefan this is wonderful! I downloaded the code and ran it, and it is working perfectly! I am going to read through the code thoroughly to understand how you got it to work versus what I had been attempting.

    However, I do have one question: the analog results that I am getting are very bad. For instance, running your code gives me values between 20 and 30 for the output and when I directly apply 5V to AIN0/P0.02 it goes up to 587. Shouldn't the range be between about 0 and 1023?

    Also, utilizing the circuit diagram here (www.sparkfun.com/.../389) the values don't have a noticeable difference in the example, but when I use an Arduino they do. Is my only option to use larger gains and account for the fact that a lot of noise will always exist?

Children
No Data
Related