pin hold doesn't work?



  • Dear Pycom-Community,

    I'm not sure, what I'm doing wrong.

    I've placed my GPy on my expansion board and connected Pin 9 of my GPy on the expansion board with Pin 9 of my Arduino Mega 2560.

    When I make Pin 9 of my Arduino a digital input and pin 9 of my GPy an Output and hold that pin via pin.hold, the Arduino still reads 1 (HIGH) after I'm pressing the Reset button on the GPy (Basically jumps between 0 and 1 for a short time).

    Output on Arduino after pressing Reset-Button on the GPy:

    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 1
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 1
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 1
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    Pinstatus: 0
    

    I used this page as a reference: https://docs.pycom.io/firmwareapi/pycom/machine/pin/

    GPy-Code:

    PyPin = Pin("P9", mode=Pin.OUT)
    PyPin.value(0)
    PyPin.hold(True)
    

    Arduino Code:

    int inPin = 9;    // pushbutton connected to digital pin 7
    
    void setup() {
      Serial.begin(9600);
      pinMode(inPin, INPUT);  // (optional) ATmega Arduinos Pins always start as digital Input anyways (Digital Pin 9)
    }
    
    void loop() {
      //val = digitalRead(inPin);   // read the input pin
      Serial.print("Pinstatus: "); Serial.println(digitalRead(inPin));   
    }
    

    I really need to hold this Pin low, even after a reset. I want Pin 9 on the GPy only HIGH, when I successfully send data and get the HTTP Code 200.

    Thanks for any help and suggestions!

    Kind regards,

    SciWax



  • I'm using 100 ms for that genuine HIGH state on the GPy after a successfull Data transmission at the moment and after 1.5 days I can say it works so far. :) Thanks for the help again!



  • @SciWax Yeah it's a bit like press button debounce, you want to see it stay there for a while to be sure it's legit.



  • @kjm
    Hey, thank you for the suggestion. I also had this train of thought, but your suggestion with the genuine ones is even better and it made click! I can just artificially increase the time of the HIGH. For instance with the delay equivalent on the GPy. For instance: Data was send, when HIGH state persists longer than 5 seconds!

    Thank you. I think that approach would be the easiest one actually. I can just realize it with millis. Update millis the first time Arduino realizes that the Pin is held HIGH after a successfull transmit and note the time with millis when the Pin goes LOW again. If the time is bigger than 5 seconds, it was a genuine transmission.



  • I never noticed those reset '1's before with my relay control work, so they must be less than relay actuation time (30ms). Given the unwanted '1's during reset are brief, could you not mod your arduino code to ignore brief '1's so that only longer genuine '1's indicate a successful upload?



  • I found this for the ESP: https://esp32.com/viewtopic.php?t=12960#p51240

    Is there any way to easily change the menuconfig of the GPy? Instead of "Print registers and reboot" I want "Print registers and halt", so the CPU is in the mode halt after a Panic happens. So I could easily fix my problem without changing any code on my Arduino and GPy.

    Basically I want this: https://esp32.com/viewtopic.php?t=12960#p51342



  • @SciWax

    The only thing I can think of to solve this issue is the following right now, when I can do nothing from the side of the GPy. I know, that my values get written into my database after 4 seconds. When the data gets "written to quick" into the database, because the Arduino reads HIGH on Pin 9 way too early (and that's a fishy behaviour), it will just reset the board. After the reset, I send the data again to the GPy.

    if (HighMillis - TransmissionStartMillis < 2000) {
    ResetGPy ();
    }
    


  • @Gijs
    Thank you for the quick reply and the suggestion. I already do that actually and it is a great suggestion, but I have a problem with that.

    Sometimes, after sending a request for transmitting data with the GPY, the GPy immediately receives a GURU meditation error afterwards. After receiving that error, the GPy completely freezes or is initializing a hard reset itself (I guess?). The latter one is a problem for me, because that causes the switch between 0 and 1 on my Pin 9 of the Arduino, which I use for checking successful transmissions of data. This Pin is only supposed to go HIGH, when I receive the HTTP code 200 on the GPy after a successfull request. The GPy puts the Pin 9 HIGH for a short moment after it receives the Code 200. Because of that switch between 0 and 1 of the GPy on its own accord, the Arduino reads HIGH at some point and thinks, that the transmission via the GPy was successfull.

    Can I disable this behaviour, which is shown in the output below? I would rather have the GPy always get stuck after a GURU error, so my Watchdog bites and just resets the GPy via the RST Pin. When it gets stuck, the Pin 9 never can get HIGH and my Arduino recognizes, that there is an error and the data has to be send again. That way, I most likely would manage to never have missing data on my database. The forced reboot, which only sometimes happens after a GURU, is a real problem for me.

    This line in the output below is interesting here:

    Re-entered core dump! Exception happened during core dump!
    Rebooting...
    

    I guess here we get a hard reset and not a soft one? I guess a soft one would let me mantain my pin status?

    Is LTE attached:
    True
    Is LTE connected:
    True
    
    Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
    Core 1 register dump:
    PC      : 0x40096fed  PS      : 0x00060b33  A0      : 0x80095b97  A1      : 0x3ffd3610  
    A2      : 0x3ffd3820  A3      : 0x00000001  A4      : 0x3ffd3818  A5      : 0x00000001  
    A6      : 0x000000fe  A7      : 0x00060023  A8      : 0x6aa84c49  A9      : 0xaa1769b2  
    A10     : 0x544a3344  A11     : 0xffffffff  A12     : 0xb33fffff  A13     : 0x0000abab  
    A14     : 0x00000003  A15     : 0x00060023  SAR     : 0x00000008  EXCCAUSE: 0x0000001d  
    EXCVADDR: 0xaa1769b6  LBEG    : 0x40091e25  LEND    : 0x40091e59  LCOUNT  : 0x00000000  
    
    ELF file SHA256: 0000000000000000000000000000000000000000000000000000000000000000
    
    Backtrace: 0x40096fed:0x3ffd3610 0x40095b94:0x3ffd3630 0x400946ff:0x3ffd3650 0x4008e42b:0x3ffd3690 0x4008e9e5:0x3ffd36d0 0x4016a771:0x3ffd3710 0x40110fcd:0x3ffd3750
    
    Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
    Core 1 register dump:
    PC      : 0x40096ec0  PS      : 0x00060233  A0      : 0x800963ed  A1      : 0x3ffd30f0  
    A2      : 0x3ffd3160  A3      : 0x3ffd3110  A4      : 0x00000040  A5      : 0x3ffc4144  
    A6      : 0x0000003b  A7      : 0x3ffbf370  A8      : 0x00000000  A9      : 0x00000000  
    A10     : 0x3ffd3550  A11     : 0x3ffc414c  A12     : 0x00000000  A13     : 0x40083214  
    A14     : 0x544a3344  A15     : 0xffffffff  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
    EXCVADDR: 0x0000000c  LBEG    : 0x40092524  LEND    : 0x4009252f  LCOUNT  : 0x00000000  
    
    ELF file SHA256: 0000000000000000000000000000000000000000000000000000000000000000
    
    Backtrace: 0x40096ec0:0x3ffd30f0 0x400963ea:0x3ffd3110 0x4008f8fd:0x3ffd3140 0x4008f697:0x3ffd3160 0x4008f81d:0x3ffd34b0 0x4008f64a:0x3ffd34d0 0x4008f242:0x3ffd3510 0x4008f492:0x3ffd3530 0x4008325e:0x3ffd3550 0x40096fea:0x3ffd3610 0x40095b94:0x3ffd3630 0x400946ff:0x3ffd3650 0x4008e42b:0x3ffd3690 0x4008e9e5:0x3ffd36d0 0x4016a771:0x3ffd3710 0x40110fcd:0x3ffd3750
    
    Re-entered core dump! Exception happened during core dump!
    Rebooting...
    ets Jun  8 2016 00:22:57
    
    rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff8020,len:8
    load:0x3fff8028,len:2140
    ho 0 tail 12 room 4
    load:0x4009fa00,len:19740
    entry 0x400a05bc
    Check traĆ¾smit pin status:
    0
    [LTE] object created
    [LTE] initialized
    [LTE] attached
    [LTE] connected
    Arduino RTC was set!
    

  • Global Moderator

    After a reset, all pin states will be lost. You could set the pin low (or from a value saved in nvram) as the first action that you do after a reset, but pin.hold() is mainly meant for usage in sleep modes.



  • @SciWax
    Ah, because the Power completely gets lost I guess and the RTC can't mantain the state of the Pin.... Is there any way around it?


Log in to reply
 

Pycom on Twitter