Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Questions about Github example, ble_app_uart_saadc_timer_driven_scan_mode

Hi, I am trying to figure out the adc example posted by Nordic Semiconductor on Github.

https://github.com/NordicPlayground/nRF52-ADC-examples

There was two examples, and I am struggling with the first one, ble_app_uart_saadc_timer_driven_scan_mode.

When I run the example, there is no error and it works well. It sends four sample values through the uart and ble, but I have no idea what these values are.

Im not sure whether these values are actual input values from my NRF52DK input pins or are from any time source. My final goal is to get voltage input from any input pin and send it to any monitor, like app, through ble.

Hope you let me know how and where can I fix the code, so I can get real input values.

Parents
  • Hi,

    The example sends samples from the analog inputs, but the values are sent as binary numbers, and not strings. If you want to see the samples as strings, you can use sprintf() function to convert the sample values into a string/char array.

    Best regards,
    Jørgen

  • Hi Jorgen,

    Thank you for clear answer. Following the link you tagged, I found this, which seems to be a part of sending data via ble.

    But the yellow boxed line is like sending as string and I have no idea where can I use sprintf() there.

    Or you mean I should add another line above that yellow boxed line, like value = sprintf(value)?

    And one more question is I want to figure out the meaning of the numbers, I can check with uart terminal. There are 4 samples at every event, but the number is very random in the range from about 10 to 1000. I didn't give any voltage inputs yet, so I think the value should be about 0. at least some constant value. Could u help me with this too?

    Thank you for reply again. 

    Best regards,

    Kyubeen

  • How to properly post code - not as an image!

    the yellow boxed line is like sending as string

    The function name is misleading - it sends raw bytes - not a "string" in the 'C' sense.

    I have no idea where can I use sprintf()

    That's a standard 'C' programming question - nothing specifically to do with Nordic!

    sprintf() is part of the Standard 'C' library:

    http://www.cplusplus.com/reference/cstdio/sprintf/

    You use it to create a string in a buffer that you provide.

    You could then transmit that buffer using ble_nus_string_send().

  • You can do something like this (given that you keep the SAMPLES_IN_BUFFER at 4):

    uint8_t nus_string[20];
    int n = sprintf(nus_string, "%d\r\n%d\r\n%d\r\n%d\r\n", p_event->data.done.p_buffer[0], p_event->data.done.p_buffer[1], p_event->data.done.p_buffer[2], p_event->data.done.p_buffer[3]);
    
    if(n <= 20) 
    {
    	bytes_to_send = n;
    }
    else 
    {
    	bytes_to_send = 20;
    }
    err_code = ble_nus_string_send(&m_nus, nus_string, bytes_to_send);
    if (err_code != NRF_ERROR_INVALID_STATE) 
    {
    	APP_ERROR_CHECK(err_code);
    }

    If you have not connected the inputs, they are floating and you will get varying values in the full range of the SAADC resolution (configured at 10 bit - 0 to 1023 in the example).

Reply
  • You can do something like this (given that you keep the SAMPLES_IN_BUFFER at 4):

    uint8_t nus_string[20];
    int n = sprintf(nus_string, "%d\r\n%d\r\n%d\r\n%d\r\n", p_event->data.done.p_buffer[0], p_event->data.done.p_buffer[1], p_event->data.done.p_buffer[2], p_event->data.done.p_buffer[3]);
    
    if(n <= 20) 
    {
    	bytes_to_send = n;
    }
    else 
    {
    	bytes_to_send = 20;
    }
    err_code = ble_nus_string_send(&m_nus, nus_string, bytes_to_send);
    if (err_code != NRF_ERROR_INVALID_STATE) 
    {
    	APP_ERROR_CHECK(err_code);
    }

    If you have not connected the inputs, they are floating and you will get varying values in the full range of the SAADC resolution (configured at 10 bit - 0 to 1023 in the example).

Children
Related