<?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>Controlling GPIO via UART on BLE</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20280/controlling-gpio-via-uart-on-ble</link><description>Hello 
 I am looking to make a program on nrf52 in which i send various values from nrf UART app on a mobile, and each value controls a LED on a GPIO. For example, sending 1 turns on the LED, 2 turns off, 3 blinks.
Can you please provide me of a reference</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 08 Mar 2017 15:25:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20280/controlling-gpio-via-uart-on-ble" /><item><title>RE: Controlling GPIO via UART on BLE</title><link>https://devzone.nordicsemi.com/thread/78994?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 15:25:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85ce7c70-e7c6-4019-a867-fe54e572cc5f</guid><dc:creator>manymany</dc:creator><description>&lt;p&gt;Just an idea for your second question&amp;gt; you could work with  12bit PWM and use a logarithmic table for converting your 0-255 to 12bits.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Controlling GPIO via UART on BLE</title><link>https://devzone.nordicsemi.com/thread/78993?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 15:20:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a88b0487-28fd-4e2f-94cc-f3e426a60177</guid><dc:creator>manymany</dc:creator><description>&lt;p&gt;If it works you could vote for my answer and accept the answer ?
Yes it is a correct approach. My example is extremely simple, you should do something more sophisticated for your application. For instance I use microrl (&lt;a href="https://github.com/Helius/microrl"&gt;https://github.com/Helius/microrl&lt;/a&gt;) for interpreting the command I send by BLE or UART, works well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Controlling GPIO via UART on BLE</title><link>https://devzone.nordicsemi.com/thread/78992?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 15:05:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c45bb15b-7a2a-4e0f-90d6-e32552cd1cc4</guid><dc:creator>akshaey</dc:creator><description>&lt;p&gt;thanks for your reply&lt;/p&gt;
&lt;p&gt;the program works!!&lt;/p&gt;
&lt;p&gt;But I have some questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;pre&gt;&lt;code&gt;p_data[i]==&amp;#39;1&amp;#39;  accepts only single digit value, what to do if i want more options than just 0-9? 
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;pre&gt;&lt;code&gt;In my project, i want to use some of the 0-255 values sent from a mobile app, to choose and change the intensity of 3 leds of different colors. how to do that? I guess, i have to use PWM function from the examples and embedd it in this program of BLE UART? Please let me know if it is the correct approach or any other thing should be done instead of UART.?
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;thanks again for your help&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Controlling GPIO via UART on BLE</title><link>https://devzone.nordicsemi.com/thread/78991?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 10:25:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25d3e7fa-ea71-48ac-9c88-e8540ce99daa</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Why don&amp;#39;t you just send the pinmap as binary as a single character then access the hardware directly&lt;/p&gt;
&lt;p&gt;Hint, look at the source code for nrf_gpio_pin_set() and see how it writes to the GPIO hardware reg&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Controlling GPIO via UART on BLE</title><link>https://devzone.nordicsemi.com/thread/78990?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 10:22:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49d870d8-276b-4c3e-8363-476fb7ef8495</guid><dc:creator>manymany</dc:creator><description>&lt;p&gt;I&amp;#39;ve just tested the example in my updated answer, it works, then you can rewrite to have something clean. In Android I use nRF UART 2.0 from nordicsemi.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Controlling GPIO via UART on BLE</title><link>https://devzone.nordicsemi.com/thread/78989?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 10:18:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0b7de13-3464-4f60-b09e-365ffb4b8fd4</guid><dc:creator>akshaey</dc:creator><description>&lt;p&gt;this is a general led blink program, i want to link it with BLE-UART, which is quite complicated. Do you know how to link it with value received from UART via BLE?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Controlling GPIO via UART on BLE</title><link>https://devzone.nordicsemi.com/thread/78988?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 10:05:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32bea8ec-064a-4325-8f07-eb19738cfe5f</guid><dc:creator>manymany</dc:creator><description>&lt;p&gt;For turning LED ON/OFF you can use something like that:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;...   
  #define LED1 17
  #define LED2 18

  int main(void)
  {

      nrf_gpio_cfg_output(LED1);
      nrf_gpio_cfg_output(LED2);

      while (true)
      {
         nrf_gpio_pin_clear(LED1); //LED ON
         nrf_gpio_pin_set(LED2);    //LED OFF
         nrf_delay_ms(500);
         nrf_gpio_pin_set(LED1);     //LED ON
         nrf_gpio_pin_clear(LED2);   //LED OFF
         nrf_delay_ms(500);
      }
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For blinking LED with BLE UART: use example ...\SDK12.2_full\examples\ble_peripheral\ble_app_uart\&lt;/p&gt;
&lt;p&gt;And modify this function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
    #define LED1 17
    for (uint32_t i = 0; i &amp;lt; length; i++)
    {
        if (p_data[i]==&amp;#39;1&amp;#39;)
        {
           nrf_gpio_cfg_output(LED1);
           nrf_gpio_pin_clear(LED1);
        }
        if (p_data[i]==&amp;#39;0&amp;#39;)
        {
           nrf_gpio_cfg_output(LED1);
           nrf_gpio_pin_set(LED1);
        }
        while (app_uart_put(p_data[i]) != NRF_SUCCESS);
    }
    while (app_uart_put(&amp;#39;\r&amp;#39;) != NRF_SUCCESS);
    while (app_uart_put(&amp;#39;\n&amp;#39;) != NRF_SUCCESS);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then when you send 1 the LED turn ON and when you send 0 the LED turn OFF&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>