Last active
September 27, 2020 19:12
-
-
Save smukkejohan/3782a788feb983bd7583449374a1af19 to your computer and use it in GitHub Desktop.
ESP8266 direct serial connection with Teensy 3.5 DMJX 2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
//**** Using a Teensy 3.5 to Connect an ESP8266 to USB Serial for use and testing with AT commands ******* | |
#define SSID "insert_SSID" //name of wireless access point to connect to | |
#define PASS "insert_PASSWORD" //wifi password | |
#define RST_PIN 24 // Pull low to trigger reset | |
#define CH_PD_PIN 25 // Pull high for AT command mode, low for firmware flash mode | |
#define TX_LED_PIN 14 // YELLOW LED - SENDING | |
#define RX_LED_PIN 15 // RED LED - RECEIVING | |
long lastTxTimestamp=0; | |
long lastRxTimestamp=0; | |
void resetESP() { | |
digitalWrite(RST_PIN,LOW); | |
digitalWrite(TX_LED_PIN,HIGH); | |
delay(100); | |
digitalWrite(RST_PIN,HIGH); | |
digitalWrite(TX_LED_PIN,LOW); | |
} | |
void setup() { | |
delay(5000); //allow time for usb to enumerate - can remove this later | |
pinMode(CH_PD_PIN, OUTPUT); | |
digitalWrite(CH_PD_PIN, HIGH); | |
pinMode(TX_LED_PIN, OUTPUT); | |
pinMode(RX_LED_PIN, OUTPUT); | |
pinMode(RST_PIN, OUTPUT); | |
resetESP(); | |
// Setup computer to Teensy serial | |
Serial.begin(115200); | |
// Setup Teensy to ESP8266 serial | |
// Use baud rate 115200 during firmware update | |
Serial1.begin(115200); | |
Serial.println("ESP Demo"); | |
delay(2000); | |
} | |
void loop() { | |
// DIRECT CONTROL | |
// Send bytes from ESP8266 -> Teensy to Computer | |
if ( Serial1.available() ) { | |
digitalWriteFast(TX_LED_PIN, HIGH); // set the LED on | |
lastTxTimestamp = millis(); | |
char ch = Serial1.read(); | |
Serial.write(ch); | |
} | |
// Send bytes from Computer -> Teensy back to ESP8266 | |
if ( Serial.available() ) { | |
digitalWriteFast(RX_LED_PIN, HIGH); // set the LED on | |
lastRxTimestamp = millis(); | |
char ch = Serial.read(); | |
Serial1.write(ch); | |
} | |
if (millis() - lastTxTimestamp > 5) { | |
digitalWriteFast(TX_LED_PIN, LOW); // set the LED off | |
} | |
if (millis() - lastRxTimestamp > 5) { | |
digitalWriteFast(RX_LED_PIN, LOW); // set the LED off | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment