0 votes
in Touch Interface by (130 points)

Hello, 

Rookie question :) 

Was playing around with the WeatherStationColor HW and SW, tried to add PIR sensor to the setup. So my question is: which IO pins are available in this setup? I've tried D7, D6, D5 - that worked perfectly fine when I was using simple code like that:

int pirPin = D7;
int val;
 
void setup()
{
Serial.begin(115200);
}
 
void loop()
{
val = digitalRead(pirPin);
//low = no motion, high = motion
if (val == LOW)
{
  Serial.println("No motion");
}
else
{
  Serial.println("Motion detected  ALARM");
}
 
delay(1000);
}

But when I tried to read Pin state inside your code it didn't work, state is always LOW. 

Any suggestions?

2 Answers

+1 vote
by (19.9k points)
Take a look at https://github.com/ThingPulse/esp8266-weather-station-color#wiring The only available pin is D0 i.e. GPIO 16.
by (130 points)
Thanks!
BTW is there a way I can use D8 sacrificing the LED? I wanted to use two PIR sensors, that's why i'm asking these dumb questions :)
by (19.9k points)
We never tried but you may be able to use D4 if you can dispense with the display's touch interface. D4 is bound to the display's touch interrupt.
0 votes
by (3.6k points)
edited by
I think only D0 is spare
by (270 points)
I also want to add a local temperature sensor DS18B20 to the setup, which uses OneWire-protocol.
Reading the Wemos-documentation, D0 doesn't support OneWire. Therefore the only way to add this sensor would be using D4, cutting T_IRQ for the touch display. But D4 uses the build in LED.
I did not find a perfect solution yet.
by (3.6k points)
You could use D4 if you don’t. I don’t the LED flashing when you get a DS18B20 reading. I don’t see any reason why D0 would not work other than the need to add a pull-up resistor.
by (270 points)
The Wemos data-sheet mentions this:
"All of the IO pins have interrupt/pwm/I2C/one-wire support except D0."
I don't know the reason for that, but anyway, I will try what happens.
by (3.6k points)
Why not use of the serial pins (RX), when programming is finished they are free. So D0/GPIO16 doesn't support interrupts but does the one-wire use interrupts, I doubt it, not checked, but worth a try.
Tx = GPIO 1
Rx = GPIO 3
by (270 points)
Using D0 for the sensor didn't work, as it doesn't support One-Wire.
Using the TX/RX-pins is not possible I think, as these signals are connected to the on-board UART.
I think I have to use D4 (GPIO2) as the only remaining option.
by (3.6k points)
I have successfully used the TX pin because it is connected to the UART input and when reconfigured as a one-wire bus it can be configured as an output to send commands to the one-wire device and UART inputs and then switched to an input to receive data from the one-wire device (now an output) when it sends data.

Regarding overriding the UART TXD pin output and using the RXD line (ESP8266 RXD pin), I also have never experienced any reliability issues by using this pin by using the ESP RXD line as an output.
by (270 points)
Using the TX-pin as an input for one-wire sounds great. I will try this. Thank you.
by (270 points)
...but using the RX/TX-pins would require to temporarily disable serial transmission if used for debugging output.
Serial.end();
readDSData(); // Read DS18B20 data
Serial.begin(...)
by (3.6k points)
In theory yes, but we don't know what the compiler does each time it structures/converts a serial.print statement, for example when it converts Serial.begin(xxx) that fore sure will have setup TXD as an output, but I doubt it will keep repeating that requirement and just assume the TXD pin is still an output. Then in this example, that issue could be solved by returning the pin state back to an output just after the one-wire device read, but to be honest, when the programme is running and debugging is finished the TXD/RXD pins are unused/redundant so why not use them.

Welcome to ThingPulse Q&A, where you can ask questions and receive answers from other members of the community.

https://thingpulse.com

...