<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>using more than 2 Analog pins in nrf52840DK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68067/using-more-than-2-analog-pins-in-nrf52840dk</link><description>How to read values from 5 Analog pins at the same time 
 I know how to read from one Analog Pin, but i don&amp;#39;t know how to access 5 analog pins at the same time and display the values in the putty terminal 
 Below i have written the code for displaying</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 17 Nov 2020 13:05:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68067/using-more-than-2-analog-pins-in-nrf52840dk" /><item><title>RE: using more than 2 Analog pins in nrf52840DK</title><link>https://devzone.nordicsemi.com/thread/280361?ContentTypeID=1</link><pubDate>Tue, 17 Nov 2020 13:05:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df3d8fa0-e2af-48f6-aaf9-0d69be196fe7</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello saver,&lt;br /&gt;&lt;br /&gt;Edvin is currently out of office, and I will be proceeding with this case in his absence.&lt;/p&gt;
[quote user="saver"]&lt;p&gt;if i insert the code in the main code,then these errors are comming&lt;/p&gt;
&lt;p&gt;Building ‘saadc_pca10056’ from solution ‘saadc_pca10056’ in configuration ‘Release’&lt;br /&gt; Compiling ‘main.c’&lt;br /&gt; redefinition of &amp;#39;channel_config&amp;#39;&lt;br /&gt; previous definition of &amp;#39;channel_config&amp;#39; was here&lt;br /&gt;Build failed&lt;/p&gt;[/quote]
&lt;p&gt;In line 49 of the code posted in your previous comment you are redefining your &lt;em&gt;channel_config&lt;/em&gt; variable from line 48.&lt;br /&gt;Please change the name of your second channel configuration, so that they do not match exactly.&lt;br /&gt;&lt;br /&gt;Try this, and let me know if it resolves your issue.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using more than 2 Analog pins in nrf52840DK</title><link>https://devzone.nordicsemi.com/thread/280022?ContentTypeID=1</link><pubDate>Sun, 15 Nov 2020 17:17:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ad06558-8eb8-429e-a627-8aea83aa0794</guid><dc:creator>saver</dc:creator><description>&lt;p&gt;Sorry for late reply, i was busy during these days.&lt;/p&gt;
&lt;p&gt;if i insert the code in the main code,then these errors are comming&lt;/p&gt;
&lt;p&gt;Building &amp;lsquo;saadc_pca10056&amp;rsquo; from solution &amp;lsquo;saadc_pca10056&amp;rsquo; in configuration &amp;lsquo;Release&amp;rsquo;&lt;br /&gt; Compiling &amp;lsquo;main.c&amp;rsquo;&lt;br /&gt; redefinition of &amp;#39;channel_config&amp;#39;&lt;br /&gt; previous definition of &amp;#39;channel_config&amp;#39; was here&lt;br /&gt;Build failed&lt;/p&gt;
&lt;p&gt;My code(modified with the one you said):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**

 */

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_drv_saadc.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;


/* Create an empty handler and pass this handler in the saadc initialization function
  &amp;gt; Normally this handler deals with the adc events but we are using blocking mode
  &amp;gt; In blocking mode the functions are called and the processor waits for the adc to finish taking samples from the respective channels
  &amp;gt; Event handler will not be called in this method
*/

void saadc_callback_handler(nrf_drv_saadc_evt_t const * p_event)
{
 // Empty handler function
}




// Create a function which configures the adc input pins and channels as well as the mode of operation of adc

void saadc_init(void)
{
	// A variable to hold the error code
  ret_code_t err_code;

  // Create a config struct and assign it default values along with the Pin number for ADC Input
  // Configure the input as Single Ended(One Pin Reading)
  // Make sure you allocate the right pin.
  nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
  nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);

  // Initialize the saadc 
  // first parameter is for configuring the adc resolution and other features, we will see in future tutorial
  //on how to work with it. right now just pass a simple null value
  err_code = nrf_drv_saadc_init(NULL, saadc_callback_handler);
  APP_ERROR_CHECK(err_code);
  err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_config);
  APP_ERROR_CHECK(err_code);
// Initialize the Channel which will be connected to that specific pin.
  err_code = nrfx_saadc_channel_init(0, &amp;amp;channel_config);
  APP_ERROR_CHECK(err_code);

  

}



// A function which will initialize the Log module for us
void log_init(void)
{
	// check if any error occurred during its initialization
  APP_ERROR_CHECK(NRF_LOG_INIT(NULL));

	// Initialize the log backends module
  NRF_LOG_DEFAULT_BACKENDS_INIT();

}

/**
 * @brief Function for main application entry.
 */
int main(void)
{
	
	// call the log initialization function
  log_init();

// call the saadc initialization function created above
  saadc_init();

// a struct to hold 16-bit value, create a variable of this type because our input resolution may vary from 8 bit to 14 bits depending on our configurations
// this variable holds the adc sample value
  nrf_saadc_value_t adc_val;


// Print a simple msg that everything started without any error
  NRF_LOG_INFO(&amp;quot;Application Started!!!&amp;quot;);


   
// Inifinite loop
    while (1)
    {
    const float VCC = 3.6; 
    const float R_DIV = 47500.0;
    
		// a blocking function which will be called and the processor waits until the value is read
		// the sample value read is in 2&amp;#39;s complement and is automatically converted once retrieved
		// first parameter is for the adc input channel 
		// second parameter is to pass the address of the variable in which we store our adc sample value
      nrfx_saadc_sample_convert(0, &amp;amp;adc_val);

		// print this value using nrf log : here %d represents the integer value 
      NRF_LOG_INFO(&amp;quot;Sample value Read: %d&amp;quot;, adc_val);

      float flexV = adc_val * VCC / 1023.0;
      float flexR = R_DIV * (VCC / adc_val - 1.0);

      NRF_LOG_INFO(&amp;quot;resistance of sensor:&amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot;\r\n&amp;quot;, NRF_LOG_FLOAT(flexR))
		
		// use nrf log and float marker to show the floating point values on the log
		// calculate the voltage by this: input_sample * 3.6 / 2^n (where n = 8 or 10 or 12 or 14 depending on our configuration for resolution in bits)
     
       
	   // give 500ms delay 
       nrf_delay_ms(500);
     
    }
}


/** @} */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The original code, i got is from this video.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=5slaFFj2SI4"&gt;https://www.youtube.com/watch?v=5slaFFj2SI4&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;can you please watch the video, and tell me where to add the code for other flex sensors, correctly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using more than 2 Analog pins in nrf52840DK</title><link>https://devzone.nordicsemi.com/thread/278786?ContentTypeID=1</link><pubDate>Fri, 06 Nov 2020 13:17:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8081c3eb-6a8a-4ce1-89bd-b47b3e2ba27d</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I suggest that you take a look at the saadc example from the SDK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It will by default only read one pin as well, but try to add another channel. I fail to see where you trigger the sampling in your project snippet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, from the saadc example, try adding a new channel by duplicating these lines:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    nrf_saadc_channel_config_t channel_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);

    err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_config);
    APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Once you have two channels working, try to add 3 more.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>