element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Azure Sphere Starter Kit
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Azure Sphere Starter Kit
  • More
  • Cancel
Azure Sphere Starter Kit
Forum LEDs blinking problem
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Azure Sphere Starter Kit to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 2 replies
  • Subscribers 46 subscribers
  • Views 504 views
  • Users 0 members are here
  • azurespherech
  • azure sphere
  • azure sphere mt3620 starter kit
  • azuresphkt
  • azure sphere module
Related

LEDs blinking problem

dariuszapt
dariuszapt over 6 years ago

Hello,

I have made a simple application based on Blink example in Visual Studio to test functions of high-level application.

Application should work as follows:

 

1. Turn on 1st LED

2. Wait 1 second and turn off 1st LED then wait 1 second.

3. Turn ON 2nd LED

4. Wait 1 second and turn off 2nd LED then wait 1 second.

3. Turn ON 3rd LED

5. Wait 1 second and turn off 3rd LED then wait 1 second.

6. Start from point 1.

 

Im using user RGB LED as indicatior. Problem is LEDs does not turn OFF in right order. 1st LED turns ON then 2nd turns ON then 1st turns OFF i belive. There should be 1 second gap of none of LEDs switched ON but there is still 1 or few ON.

 

My code (Pastebin): https://pastebin.com/n49qdzR3

 

 

#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <time.h>


#include <applibs/log.h>
#include <applibs/gpio.h>


int main(void)
{
    // This minimal Azure Sphere app repeatedly toggles GPIO 9, which is the green channel of RGB
    // LED 1 on the MT3620 RDB.
    // Use this app to test that device and SDK installation succeeded that you can build,
    // deploy, and debug an app with Visual Studio, and that you can deploy an app over the air,
    // per the instructions here: https://docs.microsoft.com/azure-sphere/quickstarts/qs-overview
    //
    // It is NOT recommended to use this as a starting point for developing apps; instead use
    // the extensible samples here: https://github.com/Azure/azure-sphere-samples
    Log_Debug(
        "\nVisit https://github.com/Azure/azure-sphere-samples for extensible samples to use as a "
        "starting point for full applications.\n");


    int fd = GPIO_OpenAsOutput(9, GPIO_OutputMode_PushPull, GPIO_Value_High);
    if (fd < 0) {
        Log_Debug(
            "Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
            strerror(errno), errno);
        return -1;
    }
int fd2 = GPIO_OpenAsOutput(10, GPIO_OutputMode_PushPull, GPIO_Value_High);
if (fd2 < 0) {
Log_Debug(
"Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
strerror(errno), errno);
return -1;
}
int fd3 = GPIO_OpenAsOutput(8, GPIO_OutputMode_PushPull, GPIO_Value_High);
if (fd3 < 0) {
Log_Debug(
"Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
strerror(errno), errno);
return -1;
}
/*
static int buttFd = -1;
GPIO_Value_Type newButtonState;
GPIO_Id GPIO12;
buttFd = GPIO_OpenAsInput(27);
*/
    const struct timespec sleepTime = {1, 0};


typedef enum State {ONE=1,TWO,THREE,FOUR,FIVE,SIX} State;


State Machine = ONE;
    while (true) {
        
//int result = GPIO_GetValue(buttFd, &newButtonState);
        //nanosleep(&sleepTime, NULL);
int res;

switch (Machine)
{
case ONE:
GPIO_SetValue(fd, GPIO_Value_High);
nanosleep(&sleepTime, NULL);
Log_Debug("LED 1 switched ON\n");
Machine = TWO;
break;
case TWO:
GPIO_SetValue(fd, GPIO_Value_Low);
nanosleep(&sleepTime, NULL);
Log_Debug("LED 1 switched OFF\n");
Machine = THREE;
break;
case THREE:
GPIO_SetValue(fd2, GPIO_Value_High);
Log_Debug("LED 2 switched ON\n");
Machine = FOUR;
break;
case FOUR:
GPIO_SetValue(fd2, GPIO_Value_Low);
nanosleep(&sleepTime, NULL);
Log_Debug("LED 2 switched OFF\n");
Machine = FIVE;
break;
case FIVE:
GPIO_SetValue(fd3, GPIO_Value_High);
nanosleep(&sleepTime, NULL);
Log_Debug("LED 3 switched ON\n");
Machine = SIX;
case SIX:
GPIO_SetValue(fd3, GPIO_Value_Low);
nanosleep(&sleepTime, NULL);
Log_Debug("LED 3 switched OFF\n");
Machine = ONE;
}    

    }
}

 

I dont know what is the reason of this problem. Is it because GPIO_SetValue is done asynchronously or nanosleep is non blocking and is done in another thread (OS task)?

 

Best Regards,

Dariusz

  • Sign in to reply
  • Cancel

Top Replies

  • javagoza
    javagoza over 6 years ago +4 verified
    See the schematics, LEDs are in negative logic, LOW - ON and HIGH - OFF https://www.element14.com/community/docs/DOC-92843/l/aes-ms-mt3620-sk-gsch2019-07-03?ICID=azuresphere-kit-datasheet-widget
  • dariuszapt
    dariuszapt over 6 years ago in reply to javagoza +1
    Thank you very much Enrique for pointing this out and for shematics. Now everything is working fine!
Parents
  • javagoza
    0 javagoza over 6 years ago

    See the schematics, LEDs are in negative logic, LOW - ON and HIGH - OFF

     

    https://www.element14.com/community/docs/DOC-92843/l/aes-ms-mt3620-sk-gsch2019-07-03?ICID=azuresphere-kit-datasheet-widget

    image

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • dariuszapt
    0 dariuszapt over 6 years ago in reply to javagoza

    Thank you very much Enrique for pointing this out and for shematics. Now everything is working fine!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • dariuszapt
    0 dariuszapt over 6 years ago in reply to javagoza

    Thank you very much Enrique for pointing this out and for shematics. Now everything is working fine!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube