- Thu Jan 21, 2016 4:06 pm
#39397
I think I've figured it out...Hope this is helpful to someone.
Program the ESP-01 to toggle GPIO2 HIGH by default, but when the correct RSSI parameters are met, toggle GPIO2 LOW, otherwise HIGH again.
Then connect GPIO2 to a input pin on an ATTINY85 chip that has been programmed using an arduino...
The ATTINY85 can listen for the input pin HIGH or LOW, and react by driving a servo motor and an optoisolator.
I have rough drafts of the code now, here you go:
Code: Select all//GPIO-0 HIGH when running code, LOW when uploading program to module.
//GPIO2 to ATTINY input pin
#include <ESP8266WiFi.h>
#include <SPI.h> //Not sure if needed for serial printing.
const char* ssid = "your desired hotspot name SSID";
const char* password = "your password for the hotspot";
void setup(){
Serial.begin(115200);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
Serial.println("OFF");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
}
void loop() {
if (WiFi.status() != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
digitalWrite(2, HIGH);
Serial.println(" OFF");
}
else {
long rssi = WiFi.RSSI();
Serial.print(rssi);
if (rssi > -80 && rssi < 0) {
digitalWrite(2, LOW);
Serial.println(" ON");
}
if (rssi < -80) {
digitalWrite(2, HIGH);
Serial.println(" OFF");
}
}
}
The arduino or ATTINY85 code:
Code: Select all //NOTE: this code has not yet been adapted for the ATTINY CHIPS, only tested on Arduino Nano v3
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int button = 2; // The button will be on Pin 2
void setup()
{
myservo.attach(6); // attaches the servo on pin 9 to the servo object
pinMode(1, OUTPUT);
digitalWrite(1, LOW);
pinMode(button, INPUT);
digitalWrite (button, LOW);
myservo.write(20);
}
void loop()
{
if (digitalRead(button) == LOW) {
// in steps of degree
myservo.write(20);
digitalWrite(1,LOW);
// tell servo to go to position in variable 'pos'
// waits 1s for the servo to reach the position
}
if (digitalRead(button) == HIGH) {
myservo.write(120);
digitalWrite(1, HIGH); // tell servo to go to position in variable 'pos'
delay(50); // waits 50ms for the servo to reach the position
}
}