<?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>Thingy91 accessing P6 GPIO of nrf52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81258/thingy91-accessing-p6-gpio-of-nrf52840</link><description>Hello, 
 I am trying to work on a simple GPIO program for the Thingy:91 which involves reading a pin for sensor inputs (this will be 2 sensors eventually). I have tried to look through the documentation in the infocenter and I believe that the way to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 03 Nov 2021 21:02:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81258/thingy91-accessing-p6-gpio-of-nrf52840" /><item><title>RE: Thingy91 accessing P6 GPIO of nrf52840</title><link>https://devzone.nordicsemi.com/thread/337356?ContentTypeID=1</link><pubDate>Wed, 03 Nov 2021 21:02:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8fbcf25-4b04-4d5c-9bea-426abab48d84</guid><dc:creator>JCampa</dc:creator><description>&lt;p&gt;I found out how to read the voltage level on TP32, and logical level on TP33, which is enough for my purposes.&lt;/p&gt;
&lt;p&gt;For anyone wondering how to do it:&lt;/p&gt;
&lt;p&gt;TP32 is AIN0 and TP33 is AIN3 for the Thingy91 (&lt;a href="https://infocenter.nordicsemi.com/topic/ug_thingy91/UG/thingy91/hw_description/pin_maps.html"&gt;https://infocenter.nordicsemi.com/topic/ug_thingy91/UG/thingy91/hw_description/pin_maps.html&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;So using the Analog Digital Converter (ADC) sample code found here:&amp;nbsp;&lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/adc/src/main.c"&gt;fw-nrfconnect-nrf/main.c at nrf9160_samples &amp;middot; Rallare/fw-nrfconnect-nrf (github.com)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Modifying this to make it useable (lot of old libraries that have been moved):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include &amp;lt;net/socket.h&amp;gt;
#include &amp;lt;nrf9160.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;drivers/uart.h&amp;gt;
#include &amp;lt;drivers/adc.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;

//variables needed for ADC channel reading
struct device *adc_dev;
#define BUFFER_SIZE 1
static uint16_t m_sample_buffer[BUFFER_SIZE];

//Setting needed ADC settings
#if defined(CONFIG_BOARD_NRF9160DK_NRF9160_NS)	|| \
	defined(CONFIG_BOARD_THINGY91_NRF9160_NS)
#include &amp;lt;hal/nrf_saadc.h&amp;gt;
#define ADC_DEVICE_NAME DT_ADC_0_NAME
#define ADC_RESOLUTION 10
#define ADC_GAIN ADC_GAIN_1_6
#define ADC_REFERENCE ADC_REF_INTERNAL
#define ADC_ACQUISITION_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10)
#define ADC_1ST_CHANNEL_ID 0
#define ADC_1ST_CHANNEL_INPUT NRF_SAADC_INPUT_AIN0

#endif

static const struct adc_channel_cfg m_1st_channel_cfg = {
	.gain = ADC_GAIN,
	.reference = ADC_REFERENCE,
	.acquisition_time = ADC_ACQUISITION_TIME,
	.channel_id = ADC_1ST_CHANNEL_ID,
#if defined(CONFIG_ADC_CONFIGURABLE_INPUTS)
	.input_positive = ADC_1ST_CHANNEL_INPUT,
#endif
};

static int adc_sample(void)
{
	int ret;

	const struct adc_sequence sequence = {
		.channels = BIT(ADC_1ST_CHANNEL_ID),
		.buffer = m_sample_buffer,
		.buffer_size = sizeof(m_sample_buffer),
		.resolution = ADC_RESOLUTION,
	};

	if (!adc_dev) {
		return -1;
	}

	ret = adc_read(adc_dev, &amp;amp;sequence);
	if (ret &amp;lt; 0) {
		printk(&amp;quot;ADC read err: %d\n&amp;quot;, ret);
		return ret;
	}
	/* Print the AIN0 values */
		float adc_voltage = 0;
		adc_voltage = (float)(((float)m_sample_buffer[0] / 1023.0f) *
				      3600.0f);
		printk(&amp;quot;ADC raw value: %d\n&amp;quot;, m_sample_buffer[0]);
		printf(&amp;quot;Measured voltage: %f mV\n&amp;quot;, adc_voltage);

	return ret;
}

int main(void)
{
	int err;

	printk(&amp;quot;nrf91 saadc sampling AIN0 (P0.13)\n&amp;quot;);
	printk(&amp;quot;Example requires secure_boot to have &amp;quot;);
	printk(&amp;quot;SAADC set to non-secure!\n&amp;quot;);
	printk(&amp;quot;If not; BusFault/UsageFault will be triggered\n&amp;quot;);

	adc_dev = device_get_binding(&amp;quot;ADC_0&amp;quot;);
	if (!adc_dev) {
		printk(&amp;quot;device_get_binding ADC_0 failed\n&amp;quot;);
	}
	err = adc_channel_setup(adc_dev, &amp;amp;m_1st_channel_cfg);
	if (err) {
		printk(&amp;quot;Error in adc setup: %d\n&amp;quot;, err);
	}

	/* Trigger offset calibration
	 * As this generates a _DONE and _RESULT event
	 * the first result will be incorrect. 
	 */
	NRF_SAADC_NS-&amp;gt;TASKS_CALIBRATEOFFSET = 1;
	while (1) {
		//380 - 176 range
		err = adc_sample();
		if (err) {
			printk(&amp;quot;Error in adc sampling: %d\n&amp;quot;, err);
		}
		k_sleep(K_MSEC(500));
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Your project config file should include (at least):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_ADC=y
CONFIG_ADC_ASYNC=y
CONFIG_NRFX_SAADC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_NEWLIB_LIBC=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can flash this to the Thingy:91 (I used the DK and JTAG cable method, don&amp;#39;t know if the MCUBoot one would work or not) and connect whatever input voltage you are trying to read to TP32 which is right above Switch 3 on the PCB.&lt;/p&gt;
&lt;p&gt;Additionally, if all you need is the logical level you can use pins 13 and 16 to connect to Test Points 32 and 33 respectively.&lt;/p&gt;
&lt;p&gt;I hope this helps others like me who are newer to this, as I find having simple examples to build off of is very helpful!&lt;/p&gt;
&lt;p&gt;-Julian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 accessing P6 GPIO of nrf52840</title><link>https://devzone.nordicsemi.com/thread/337118?ContentTypeID=1</link><pubDate>Tue, 02 Nov 2021 14:05:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5ba4620-3cd6-4834-a07f-50886bb5a195</guid><dc:creator>JCampa</dc:creator><description>&lt;p&gt;Hi, thanks for telling us about the modified Connectivity Bridge firmware need, could you explain further what exactly has to be modified, as the CONFIG_GPIO is already set to y and I can&amp;#39;t see anything else that would be relevant?&lt;/p&gt;
&lt;p&gt;Yes it was the SENSE_LED - the Port 0 Pin 1 explanation seems right to me.&lt;/p&gt;
&lt;p&gt;One of the sensors needs power/GND/Analog input, while the other sensor just needs power/Analog input. The power and GND connections will be done with connector P5 (the 3.3V and GND connections).&lt;/p&gt;
&lt;p&gt;Really all I need to do is read the analog voltage on two of the 6 pins on P6 or the test points 32 and 33. I am able to read the logical level on the test points, however I really need the actual voltage on the point. Is there a way to get the actual voltage level from pin reads?&lt;/p&gt;
&lt;p&gt;Those two tickets you linked were helpful, thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Thingy91 accessing P6 GPIO of nrf52840</title><link>https://devzone.nordicsemi.com/thread/336948?ContentTypeID=1</link><pubDate>Mon, 01 Nov 2021 21:48:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a9c5748-df29-46a5-886b-4a5f3b15335e</guid><dc:creator>helsing</dc:creator><description>&lt;p&gt;Hello Julian,&lt;/p&gt;
&lt;p&gt;If you would like to use the pins on P6 you would need to program nRF52840 with a modified version of the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.1/nrf/applications/connectivity_bridge/README.html"&gt;Connectivity Bridge firmware&lt;/a&gt;. Remember to set the switch to nRF52 on the Thingy when programming the 52 device.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h5&gt;Why did you see a green light?&lt;/h5&gt;
&lt;p&gt;NRF_GPIO_PIN_MAP is provided to reference the ports and pins on the IC, not the ports and pins on Thingy:91. Which LED goes green, the SENSE_LED or the lightwell?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/6646.pastedimage1635801615867v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;If it is the SENSE_LED that goes green then I suppose the explanation could be that this result after the use of the macro is port 0, pin 1(P0.01) on nRF9160.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h5&gt;Other solutions&lt;/h5&gt;
[quote user=""](this will be 2 sensors eventually)[/quote]
&lt;p&gt;How many pins/what type of pins are required for the two sensors?&lt;/p&gt;
&lt;p&gt;Here are a few more options for GPIOs on Thingy:91: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/51355/inputs-via-gpio-on-the-thingy-91"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/51355/inputs-via-gpio-on-the-thingy-91&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Another discussion on alternative use of the pins on Thingy:91: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/68213/thingy91-uart-external-communication/279485#279485"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/68213/thingy91-uart-external-communication/279485#279485&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It looks like SPI is available on some test points.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>