This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

can i control pin 24(or any other) on nrf51 dk(nrf51422) using iot sdk?

I have set up raspberry pi 3 as a border router and programmed the the nrf51422 using the iot_ipv6_coap_server_pca10028 and could successfully switch on and off led3 and led4 using copper coap,can i control pin24 on nrf51dk if yes what are the changes i need to do in the main.c ?

  • Hi,

    Yes, you can control any other pins using the same example. LEDs are also just controlled by setting the output of the pin it is connected to.

    You have to add the new pin as a CoAP endpoint, using the coap_endpoints_init() function. Your new endpoint need a callback handler, like led3_callback() and led4_callback(), where you need to handle the CoAP messages in a similar way as done in handle_led_request(). The GPIO is controlled using the GPIO abstraction functions.

    Best regards,

    Jørgen

  • I am a beginner can you provide example code for controlling gpio usig coap

  • I have not tested this, as I don't have the test environment for IoT/CoAP up at the moment, but I hope it works. Anyway, you should be able to get the point by comparing the changes to the LED-only example: coap_gpio.zip.

  • Sir I tried your code but since led3 and led4 are internally connected to pin 24 and pin 23 I changed the gpio pin to 12 (pin 12) and changed 24 to 12 in main.c wherever required and I could build Hex file without errors but once I dump the Hex file on board all the onboard LEDs come on indicating error.could you please help me resolve the problem.

  • I forgot to change line 894 in main.c. This should have been:

    err_code = coap_resource_child_add(&gpio, &pin24);
    
1 2 3