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

Unable to get ADC results using accelerometer

hi, i am working on ble_app_uart_simple_adc example which is referred from the link github.com/.../nrf51-ADC-examples i flashed the code successfully. and detecting the device using NRFTool box application. during the circuit setup i connected accelerometer(ADXL335) Z- output to the p0.01 of the nrf51 development kit and connected ground. after connecting to the device through nrftool box UART application. the log file showing unknown values(strange symbols). how to get accelerometer z output values using this ble_app_uart_simple_adc example code.

  • Hi

    The nRFtoolbox UART app is probably receiving the correct ADC values, but it displays the values as ascii characters. If you would instead send readable ascii characters, then the nrftoolbox UART app would be able to display it correctly. E.g. if you would write the adc_event_handler as follows:

    static void adc_event_handler(nrf_drv_adc_evt_t const * p_event)
    {
    	uint8_t adc_result_temp[] = {'c','a','f','e'};
    	
    	if (p_event->type == NRF_DRV_ADC_EVT_DONE)
    	{
    		ble_nus_string_send(&m_nus, &adc_result_temp[0], 4);
    	}
    }
    

    it would write "cafe" in nRFtoolbox. If you want to see the real ADC values however, it is better to connect with nRF Connect app, then you see the raw hexadecimal values instead of ascii characters.

  • i replaced adc_event_handler function with your function it is displaying cafe continuously. where as with existing ble_app_uart_simple_adc examples adc_event_handler function it is first displaying alphabets and after symbols like this "?????"

  • even i am disconnected accelerometer at p0.01. it is displaying symbols like this only "????","))-(" this is the existing adc_event_handler function static void adc_event_handler(nrf_drv_adc_evt_t const * p_event) { uint8_t adc_result[ADC_BUFFER_SIZE*2];

    if (p_event->type == NRF_DRV_ADC_EVT_DONE)
    {
        adc_event_counter++;
        printf("    ADC event counter: %d\r\n", adc_event_counter);			
        uint32_t i;
        for (i = 0; i < p_event->data.done.size; i++)
        {
            printf("Sample value %d: %d\r\n", i+1, p_event->data.done.p_buffer[i]);   //Print ADC result on hardware UART
            adc_result[(i*2)] = p_event->data.done.p_buffer[i] >> 8;
            adc_result[(i*2)+1] = p_event->data.done.p_buffer[i];					
        }
        if(ADC_BUFFER_SIZE <= 10)
        {
            ble_nus_string_send(&m_nus, &adc_result[0], ADC_BUFFER_SIZE*2);           //Send ADC result over BLE via NUS service
        }		
        LEDS_INVERT(BSP_LED_3_MASK);				                                          //Indicate sampling complete on LED 4
    }
    

    } how i can display exact adc valuse in nrftool box application.

  • Yeah, the nRFtoolbox displays the characters in a strange way. Try to use the nRF Connect app instead in order to see the real ADC output in hexadecimal format. You can not see the real values on nRFToolbox UART app.

    What the code is doing in the adc_event_handler is to split every 10-bit ADC output value into two 8-bit values before sending it over BLE. Since the ADC buffer size is 4, the adc_event_handler is called every 4 samples. This will result in 4 samples to be sent every time over BLE, i.e. 8 bytes. You can see the values of those 8 bytes if you connect with nRF Connect app. You can also see the ADC output values if you connect to the UART output as described in the documentation for the example.

    When you disconnect the accelerometer from the ADC input pin the input pin will be floating, so the input voltage to the ADC input pin P0.01 can be whatever, and you will see whatever value on the ADC output. To test, you can try to get zero ADC output by shorting P0.01 to GND or get a positive ADC output by shorting P0.01 to VDD on the nRF51-DK board.

  • hi, if i use nrf connect application getting information like this "???(*" recieved value:(0x)00-02-00-02-00-02-00-02 (if i connect ground to p0.01) where as i left p0.01 openthis value is like this value: (0x)01-ff-01-ff-01-ff-01-ff if i am connected accelerometer analog input to the p0.01 values are changing. but how i can measure this alues in to voltages.

Related