-->
Page 1 of 1

troubleshooting help wanted ESP-01 RSSI Servo + LED

PostPosted: Sun Jan 17, 2016 11:38 am
by derek bernsen
I have no idea why this code isn't working... Please help troubleshoot!
Servo is supposed to move and stop when rssi is one way, but otherwise move back and stop.
optoisolator LED is supposed to light up when rssi is one way, then off otherwise.

Code: Select all#include <Servo.h>
#include <ESP8266WiFi.h>
#include <SPI.h> //Not sure if needed for serial printing.
#include <Ticker.h>
#define servopin 2
int rssi = 0;
const char* ssid     = "AI-THINKER_F53A7F";
const char* password = "";
Servo myServo;

void setup(){
     Serial.begin(115200);
     pinMode(0, OUTPUT);
     digitalWrite(0, HIGH);
     Serial.println("OPTO OFF");
     WiFi.mode(WIFI_STA);
     WiFi.begin(ssid, password);
     myServo.attach(2); 
}

 void loop() {     
    long rssi = WiFi.RSSI();
  //Serial.print(rssi);

  if (rssi > -80 && rssi < 0) {
   digitalWrite(0, LOW);
   Serial.println("OPTO ON");
        myServo.write(160);
        delay(5);
     }
    else
    {
       digitalWrite(0, HIGH);
     Serial.println("OPTO OFF");
      myServo.write(20);
    }
  }
 

Re: troubleshooting help wanted ESP-01 RSSI Servo + LED

PostPosted: Thu Jan 21, 2016 4:06 pm
by derek bernsen
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
  }
 
}