What do I misunderstand about rgbled()?



  • @Paul-Holthuizen in this case (which is different from your original code which had a sleep), if your socket is set to non-blocking then when you press the button, it will set to white, send data, then immediately set to green so you won’t see the white at all.

    But in the original case with the sleep it should have stayed white at least for the duration of the sleep.

    If your socket is set to blocking then things will depend on the data rate and amount of data. In the best cases it could take only a few ms or tens of ms so you won’t see a thing. In the worst cases it could take seconds.



  • @Gijs

    The problem has probably something to do with my understanding of the if statement

    If I run :

    while(True):  
        if(switch() == 0):
            rgbled(white)
            retdata=loraSendReceive(senddata)
            print("Data verzonden: ", senddata)
            if(len(retdata) != 0):
                print("Data ontvangen: ", retdata)
            rgbled(green)
    

    the led comes on white when I press the switch. A couple of seconds later the "Data verzonden" message is printed and the led goes green. As excpected.

    However, if I run:

    while(True):  
        if(switch() == 0):
            rgbled(white)
            retdata=loraSendReceive(senddata)
            print("Data verzonden: ", senddata)
            if(len(retdata) != 0):
                print("Data ontvangen: ", retdata)
        rgbled(green)
    

    the led comes on green. When I press the switch the led stays green, but the "Data verzonden" message is printed.

    The only thing I can imagine is that running "rgbled(green)" many times (as happens whenever the switch is not activated) breaks something. Maybe the calls to rgbled() are buffered?

    There are many ways I can solve this but I would like to understand why I am not allowed to do it like this.



  • Right, so the heartbeat setting is correct then, as you are able to change the LED color, so it seems there is an error in your code.
    In the firmware source, in modpycom.c, we have the rgbled function: https://github.com/pycom/pycom-micropython-sigfox/blob/Dev/esp32/mods/modpycom.c#L159

    I believe your function rgbled(red+green+blue) should work and am a bit puzzled here as well..



  • @Gijs

    I tried both suggestions (temporary and permanent disable) and both do not seem to work; Still the LED turns only green after pressing the button.

    To make sure that the heartbeat led was indeed disabled during runtime I printed its status with

    print("Heartbeat: ", pycom.heartbeat())
    

    and that output looks good: Heartbeat: False.

    Where can I find what code runs if the rgbled() statement is executed?
    Coming from Microchip and C I would like to see what machine code is generated from the statements I enter, to prevent me from flying totally blind when stuff like this happens. And also to prevent me bugging people on this forum.



  • Indeed, using

    import pycom
    pycom.heartbeat(False) #use this everytime
    # or
    pycom.heartbeat_on_boot(False) #always disable the heartbeat
    

    You will disable the heartbeat functionality and be able to control the rgb led yourself



  • @Paul-Holthuizen you may need to disable the pycom hearbeat function first.


Log in to reply
 

Pycom on Twitter