<?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>Reading and writing to GPIO pins from a sample Zephyr project</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67810/reading-and-writing-to-gpio-pins-from-a-sample-zephyr-project</link><description>I looked at Blinky, but I am still not sure how to access the GPIO pins. In Blinky, there is an led0 alias, but what about other pins? What are there aliases? 
 
 Specifically, this is what I need to do. 
 
 1. I need to read from P0.03, I was told this</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 23 Jul 2021 07:47:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67810/reading-and-writing-to-gpio-pins-from-a-sample-zephyr-project" /><item><title>RE: Reading and writing to GPIO pins from a sample Zephyr project</title><link>https://devzone.nordicsemi.com/thread/321493?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 07:47:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:451e09b5-5652-4937-a2e7-bfb2047a2544</guid><dc:creator>Saleh</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;At the beginning, it seems confusing! but anyway, for working with gpio, zephyr first needs to find a corresponding device:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The parameter passed to this function, should be the &amp;quot;label&amp;quot; property of the device you want to work with. it is described here: &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/dts/howtos.html#get-a-struct-device-from-a-devicetree-node"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/dts/howtos.html#get-a-struct-device-from-a-devicetree-node&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;By searching the devicetree file (.dts), you can see the label of the gpio0 is &amp;quot;GPIO_0&amp;quot;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;		gpio0: gpio@50000000 {
			compatible = &amp;quot;nordic,nrf-gpio&amp;quot;;
			gpio-controller;
			reg = &amp;lt; 0x50000000 0x200 0x50000500 0x300 &amp;gt;;
			#gpio-cells = &amp;lt; 0x2 &amp;gt;;
			label = &amp;quot;GPIO_0&amp;quot;;
			status = &amp;quot;okay&amp;quot;;
			port = &amp;lt; 0x0 &amp;gt;;
			phandle = &amp;lt; 0x4 &amp;gt;;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;so the &amp;quot;dev&amp;quot; in the above code will point to the gpio0 and then you can toggle the pins, using the functions defined to work with gpio.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading and writing to GPIO pins from a sample Zephyr project</title><link>https://devzone.nordicsemi.com/thread/299586?ContentTypeID=1</link><pubDate>Sat, 13 Mar 2021 11:05:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efa81ff9-3485-4916-9b3c-9a05ed434f1c</guid><dc:creator>xproto</dc:creator><description>&lt;p&gt;Hi! I&amp;#39;m I have been getting a hard time accessing the GPIO&amp;#39;s for almost a half day using zephyr via the platformio in VScode and finally with your comment I got it working. &lt;br /&gt;&lt;br /&gt;Can you point me out to the documentation where this GPIO_0 is indicated?&lt;br /&gt;&lt;br /&gt;I&amp;#39;m confused with the device tree model being used by zephyr. I tried reading their API wiki but still confused.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;arduino_header: connector {
		compatible = &amp;quot;arduino-header-r3&amp;quot;;
		#gpio-cells = &amp;lt;2&amp;gt;;
		gpio-map-mask = &amp;lt;0xffffffff 0xffffffc0&amp;gt;;
		gpio-map-pass-thru = &amp;lt;0 0x3f&amp;gt;;
		gpio-map = &amp;lt;0 0 &amp;amp;gpio0 3 0&amp;gt;,	/* A0 */
			   &amp;lt;1 0 &amp;amp;gpio0 4 0&amp;gt;,	/* A1 */
			   &amp;lt;2 0 &amp;amp;gpio0 28 0&amp;gt;,	/* A2 */
			   &amp;lt;3 0 &amp;amp;gpio0 29 0&amp;gt;,	/* A3 */
			   &amp;lt;4 0 &amp;amp;gpio0 30 0&amp;gt;,	/* A4 */
			   &amp;lt;5 0 &amp;amp;gpio0 31 0&amp;gt;,	/* A5 */
			   &amp;lt;6 0 &amp;amp;gpio0 11 0&amp;gt;,	/* D0 */
			   &amp;lt;7 0 &amp;amp;gpio0 12 0&amp;gt;,	/* D1 */
			   &amp;lt;8 0 &amp;amp;gpio0 13 0&amp;gt;,	/* D2 */
			   &amp;lt;9 0 &amp;amp;gpio0 14 0&amp;gt;,	/* D3 */
			   &amp;lt;10 0 &amp;amp;gpio0 15 0&amp;gt;,	/* D4 */
			   &amp;lt;11 0 &amp;amp;gpio0 16 0&amp;gt;,	/* D5 */
			   &amp;lt;12 0 &amp;amp;gpio0 17 0&amp;gt;,	/* D6 */
			   &amp;lt;13 0 &amp;amp;gpio0 18 0&amp;gt;,	/* D7 */
			   &amp;lt;14 0 &amp;amp;gpio0 19 0&amp;gt;,	/* D8 */
			   &amp;lt;15 0 &amp;amp;gpio0 20 0&amp;gt;,	/* D9 */
			   &amp;lt;16 0 &amp;amp;gpio0 22 0&amp;gt;,	/* D10 */
			   &amp;lt;17 0 &amp;amp;gpio0 23 0&amp;gt;,	/* D11 */
			   &amp;lt;18 0 &amp;amp;gpio0 24 0&amp;gt;,	/* D12 */
			   &amp;lt;19 0 &amp;amp;gpio0 25 0&amp;gt;,	/* D13 */
			   &amp;lt;20 0 &amp;amp;gpio0 26 0&amp;gt;,	/* D14 */
			   &amp;lt;21 0 &amp;amp;gpio0 27 0&amp;gt;;	/* D15 */
	};&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading and writing to GPIO pins from a sample Zephyr project</title><link>https://devzone.nordicsemi.com/thread/277910?ContentTypeID=1</link><pubDate>Sat, 31 Oct 2020 12:01:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81298bad-45c0-415b-90ac-b1f1f55518a9</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi, some suggestions for your needs:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;1. I need to read from P0.03, I was told this&amp;nbsp;could handle&amp;nbsp;analog to digital conversion because I have analog output going to this pin.&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;According to the latest&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/pdf/nRF52833_PS_v1.3.pdf" rel="noopener noreferrer" target="_blank"&gt;nRF52833 Product Specification v1.3&lt;/a&gt;, nRF52832 supports 8 ADC channels, P0.03 can be used as AIN1. You are also free to use other ADC channels.&amp;nbsp;&lt;a href="https://medium.com/home-wireless/reading-analog-data-in-zephyr-with-a-nrf52840-e05dae326b9b"&gt;This page&lt;/a&gt; provides a good example of how to read the analog output based on Zephyr.&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;2. I need to write to P0.27 and P0.26&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span&gt;You can use device name alias and of course the real device name. For example,&amp;nbsp; P0.27 come from &amp;quot;GPIO_0&amp;quot; port and with pin number &amp;quot;27&amp;quot;, so some functions look like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
......
gpio_pin_configure(dev, 27, GPIO_OUTPUT); 
......
while (1)
{

	gpio_pin_toggle(dev, 27);
	k_sleep(K_SECONDS(1));
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>