Esp8266 Wi-Fi UART / TTL преобразователь щит - PullRequest
0 голосов
/ 22 марта 2020

Итак, я пытаюсь отправить mqtt-сообщения моему uno, используя этот щит:

[img] https://forum.arduino.cc/index.php?action=dlattach;topic=672014.0;attach=352169 [/ img]

Я подключен Rx / Tx от UNO (отогнутые контакты щита) к Rx / Tx на отладочном порту моего щита. Я загрузил этот код на свой экран ESP8266, и я отправлял сообщения mqtt и получал их на экране, и я мог видеть журналы для повышения и понижения, как и ожидалось, когда сообщения mqtt были успешно проанализированы моим кодом. Я только что понял, что этот код был в моем ESP8266, а не в моем экране, поэтому напряжение на выводах in1 и in2 в коде все еще было 0. Я просто попробовал V между GPIO3 и GND на чипе ESP:

[ img] https://i1.wp.com/randomnerdtutorials.com/wp-content/uploads/2019/05/ESP8266-ESP-12E-chip-pinout-gpio-pin.png?ssl=1 [/ img]

и я получил 3,3В правильно.

[b] [size = 150] ВОПРОС: [/ size] [/ b] Теперь мне нужно 5 В, так есть ли способ заставить ESP8266 отправить HIGH на выводы Arduino UNO?

#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
//#include <Adafruit_INA219.h>

#define in1 3 //We are not using PWM for this demo.
#define in2 4

// Connect to the WiFi
const char* ssid = "myssid";
const char* password = "mypwd";
IPAddress mqtt_server(192, 168, 1, 113);

WiFiClient espClient;
PubSubClient client(espClient);

const byte ledPin = 0; // Pin with LED on Adafruit Huzzah UNNECESSARY

void callback(char* topic, byte* payload, unsigned int length) {
 Serial.print("Message arrived [");
 Serial.print(topic);
 Serial.print("] ");
 for (int i=0;i<length;i++) {
  char receivedChar = (char)payload[i];
  Serial.print(receivedChar);
  if (receivedChar == '0')
  // ESP8266 Huzzah outputs are "reversed"
  raiseCurtain();
  digitalWrite(ledPin, HIGH);
  if (receivedChar == '1')
  lowerCurtain();
   digitalWrite(ledPin, LOW);
  }
  Serial.println();
}


void reconnect() {
 // Loop until we're reconnected
 while (!client.connected()) {
 Serial.print("Attempting MQTT connection...");
 // Attempt to connect
 if (client.connect("ESP8266 Client")) {
  Serial.println("connected");
  // ... and subscribe to topic
  client.subscribe("curtainStatus");
 } else {
  Serial.print("failed, rc=");
  Serial.print(client.state());
  Serial.println(" try again in 5 seconds");
  // Wait 5 seconds before retrying
  delay(5000);
  }
 }
}

void setup(){
 Serial.begin(9600);

 client.setServer(mqtt_server, 1883);
 client.setCallback(callback);

 pinMode(ledPin, OUTPUT);//UNNECESSARY
 setupMotor();

}

void setupMotor(){
    //set the pins for output
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
 //set the pins low - this will keep the motor from moving.
 digitalWrite(in1, LOW);
 digitalWrite(in2, LOW);
}

void raiseCurtain() {
 Serial.println("raising curtains");
  //set the pins low - this will keep the motor from moving.
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);

  //Spin Motor in one direction UP
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  delay(5000); //let it spin for about 10 seconds
}
void lowerCurtain() {
 Serial.println("lowering curtains");
    //Spin Motor in the other direction DOWN
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  delay(5000); //let it spin for about 10 seconds

  //Stop the motor
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);

}

void loop(){
 if (!client.connected()) {
  reconnect();
 }
 client.loop();
}
...