0

The following code works. I get an output in the console every second of "Hello" and then the analogValue of the photoresistor.

int greenLedPin = D1;
int yellowLedPin = D2;
int redLedPin = D3;

int lightSensorPin = A0;
int analogValue = 0;

void setup() {
  Serial.begin(9600);
//  pinMode(greenLedPin, OUTPUT);
//  pinMode(yellowLedPin, OUTPUT);
//  pinMode(redLedPin, OUTPUT);
}

void loop() {
  analogValue = analogRead(lightSensorPin);
  Serial.println("Hello.");
  Serial.println(analogValue);
  delay(1000);
//  digitalWrite(greenLedPin, HIGH);
//  digitalWrite(yellowLedPin, HIGH);
//  digitalWrite(redLedPin, HIGH);
}

Now as soon as I uncomment the pinMode commands nothing shows up on the console.

int greenLedPin = D1;
int yellowLedPin = D2;
int redLedPin = D3;

int lightSensorPin = A0;
int analogValue = 0;

void setup() {
  Serial.begin(9600);
  pinMode(greenLedPin, OUTPUT);
  pinMode(yellowLedPin, OUTPUT);
  pinMode(redLedPin, OUTPUT);
}

void loop() {
  analogValue = analogRead(lightSensorPin);
  Serial.println("Hello.");
  Serial.println(analogValue);
  delay(1000);
//  digitalWrite(greenLedPin, HIGH);
//  digitalWrite(yellowLedPin, HIGH);
//  digitalWrite(redLedPin, HIGH);
}

Any idea what might be going on?

  • Does it happen when only one of the Dn pins is uncommented? (I'm thinking the definition of Dn might be to the wrong GPIO pin) - I'll test you code when I get home to see if I get the same result. – Code Gorilla Aug 4 '17 at 7:45
1

Move int greenLedPin = D1; and int redLedPin = D3; to another pin, because D1 and D3 is Tx and Rx.

enter image description here

http://esp8266.github.io/Arduino/versions/2.0.0/doc/reference.html

| improve this answer | |
  • Would plugging things into the D1 and D3 pins like LEDs cause this sort of weirdness to happen? My problem eventually became the chip completely ignoring any changes in my sketch. Editing the sketch or even uploading a completely different sketch resulted in the chip simply running the same old code every time. – fuzzybabybunny Aug 5 '17 at 6:43
  • FYI here is an image of the LinkNode D1: m.media-amazon.com/images/S/… D1 is marked as "TX->D1" and D2 is "D2" and D3 is "D15/SCL/D3", so D3 isn't RX0 – fuzzybabybunny Aug 5 '17 at 6:48
  • s3.amazonaws.com/linksprite/Linknode+D1/LinkNode-D1-sch.pdf Shows pin 15, 16 (D1, D3) is connected to the USB/Serial IC. And YES, the old code interrupts the upload of the new code. A solution is to press the reset button before the Arduino IDE shows "Upload code", this will put the ESP-12 into programming mode. – MatsK Aug 5 '17 at 7:04
  • I actually did hit the reset button right after compiling but before the IDE showed Upload Code. Same result. – fuzzybabybunny Aug 5 '17 at 7:18
  • Sorry the correct procedure is: Connect LinkNode D1 to your PC. Press and hold the Reset button, and then Connect D8 (Flash) to ground (GND). Release the Reset button, and then disconnect D8 from ground. And now its in programming mode. – MatsK Aug 5 '17 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.