<?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>NCS Naming ADC Channels</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/107341/ncs-naming-adc-channels</link><description>Hi, 
 I&amp;#39;m trying to get to know the nRF Connect SDK by starting with a simple project including two different boards. One of those is the nRF 52833DK, the other one is made by our own and has a nRF52832 chip on it. I&amp;#39;ve got GPIO&amp;#39;s and PWM running, and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Jan 2024 14:56:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/107341/ncs-naming-adc-channels" /><item><title>RE: NCS Naming ADC Channels</title><link>https://devzone.nordicsemi.com/thread/464433?ContentTypeID=1</link><pubDate>Tue, 16 Jan 2024 14:56:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f13d253-14b4-4fd8-b626-8eae4c8bf850</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m glad to hear that you got things working!&lt;/p&gt;
&lt;p&gt;As mentioned, aliases can also help you with this scenario so that you do not have to handle it in runtime.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS Naming ADC Channels</title><link>https://devzone.nordicsemi.com/thread/464381?ContentTypeID=1</link><pubDate>Tue, 16 Jan 2024 12:22:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d99722b-20b4-49f6-bd58-8c37e90e3352</guid><dc:creator>tvi</dc:creator><description>&lt;p&gt;That was very helpful. With help strcmp I was able to determine where the adc value belongs to.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; if (strcmp(io_channels_name_str[i], &amp;quot;T100&amp;quot;) == 0) {
    // Do something with the T100 sensor value
 } else if (strcmp(io_channels_name_str[i], &amp;quot;CURRENT_SENSE&amp;quot;) == 0) {
    // Do something with the CURRENT_SENSE sensor value
 } else {
    // Unknown sensor
 }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS Naming ADC Channels</title><link>https://devzone.nordicsemi.com/thread/464150?ContentTypeID=1</link><pubDate>Mon, 15 Jan 2024 11:38:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:393fb200-6149-4dbd-9147-e1166df7bbd8</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]1. Loop trough each ADC-channel that is defined in the .dts file of the connected board periodically.[/quote]
&lt;p&gt;Each channel that you define in io-channels will be populated in this array:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.4.99-ncs1/samples/drivers/adc/src/main.c#L27-L30"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.4.99-ncs1/samples/drivers/adc/src/main.c#L27-L30&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In your case, it would be adc0/1/3/4 that will be populated.&lt;/p&gt;
[quote user=""]2. Based on the name of the ADC channel, convert the read-out voltage to something usefull, for example a temperature or light value.[/quote]
&lt;p&gt;You can pick out the name by using the vscode DT plugin, copy c identifier:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1705317681807v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which will give you this, provided as an array of strings:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;DT_PROP(DT_PATH(zephyr_user), io_channel_names)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can then put this into your c-file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;const char * io_channels_name_str[] = DT_PROP(DT_PATH(zephyr_user), io_channel_names);&lt;/pre&gt;&lt;/p&gt;
[quote user=""]Also including a separate header file in the board with all sensor definitions doens&amp;#39;t seem right, because the header file will be in the project folder and not in the boards directory.[/quote]
&lt;p&gt;It sounds like you want to use the user selected &amp;quot;aliases&amp;quot; in devicetree?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.zephyrproject.org/latest/build/dts/howtos.html#get-a-struct-device-from-a-devicetree-node"&gt;https://docs.zephyrproject.org/latest/build/dts/howtos.html#get-a-struct-device-from-a-devicetree-node&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The aliases section isn&amp;#39;t directly documented, but it is used quite often in the documentation, like here in the node identifiers section:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.1/zephyr/build/dts/api-usage.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.1/zephyr/build/dts/api-usage.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>