Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

digital out sketch not behaving as expected
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

digital out sketch not behaving as expected

by paultravers on Tue Feb 09, 2016 5:55 am

I have been working through the digital out sketch in the adafruit mqtt library, using the blue led on the huzzah esp8266 to report the status of the GPIO#2 pin. Other than putting in my own wifi and adafruit.io details I haven't modified the sketch. While the sketch works in the sense that the board connects and receives either a "1" or a "0", the LED lights only momentarily. I had expected that it would light continuously while the lamp feed was set to "1", ie that on receiving a "1" pin 2 would be set to HIGH and that it would remain HIGH until a "0" was received. Have I misunderstood how it is supposed to work, or do I have a problem?

Paul

paultravers
 
Posts: 25
Joined: Fri Jun 28, 2013 8:48 am

Re: digital out sketch not behaving as expected

by adafruit2 on Tue Feb 09, 2016 4:01 pm

it should stay lit, but note that you have to set the pin LOW to keep the LED on

adafruit2
Site Admin
 
Posts: 19221
Joined: Fri Mar 11, 2005 7:36 pm

Re: digital out sketch not behaving as expected

by paultravers on Thu Feb 11, 2016 7:06 am

I have tried manually setting the pin high or low, ie I added a line to the sketch
if (current == 1) digitalWrite(LAMP, HIGH);
I also tried setting it low .. and in neither case did the LED light other than momentarily .. I tried switching the pin to 12 and driving a piezo buzzer rather than a LED and all that does is click when receiving a "1". I tried a different ESP board and got the same result, just a momentary click on toggling the lamp feed.

I connected the buzzer to gnd and the 3v3 pin, and the buzzer does work.

The code I have now is
Code: Select all | TOGGLE FULL SIZE
   if (subscription == &lamp) {
 
      // convert mqtt ascii payload to int
      char *value = (char *)lamp.lastread;
      Serial.print(F("Received: "));
      Serial.println(value);
      int current = atoi(value);
      Serial.print(current);Serial.print(">");
      // write the current state to the power switch tail
      digitalWrite(LAMP, current == 1 ? HIGH : LOW);
      Serial.println(current);
      if (current==1) {
        digitalWrite(LAMP,LOW);
        delay(500);
        digitalWrite(LAMP,HIGH);
        delay(500);
      }
    }


Any suggestions? At a bit of a loss here.

Paul

paultravers
 
Posts: 25
Joined: Fri Jun 28, 2013 8:48 am

Re: digital out sketch not behaving as expected

by adafruit2 on Thu Feb 11, 2016 10:14 pm

sounds like you're getting data from IO, you just need to work out your project code...debugging and time will help you get it working!

adafruit2
Site Admin
 
Posts: 19221
Joined: Fri Mar 11, 2005 7:36 pm

Please be positive and constructive with your questions and comments.