So, I ordered an ESP8266 12e AI-thinker bare chip, and am trying to program it to use for a bike speedometer. I am using a standard USB to TTL programmer.
My problem is that the code is not uploading. In board options, I have it set to NodeMCU 1.0 . I am using the first circuit option in this article (the most basic one). I am getting the following error messages:
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
Executable segment sizes:
ICACHE : 32768 - flash instruction cache
IROM : 248108 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 27497 / 32768 - code in IRAM (IRAM_ATTR, ISRs...)
DATA : 1504 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 948 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 26256 ) - zeroed variables (global, static) in RAM/HEAP
Sketch uses 278057 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28708 bytes (35%) of dynamic memory, leaving 53212 bytes for local variables. Maximum is 81920 bytes.
esptool.py v3.0
Serial port COM9
Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
File "C:\Users\User\Mirror\Documents\ArduinoData\packages\esp8266\hardware\esp8266\3.0.2/tools/upload.py", line 66, in <module>
esptool.main(cmdline)
File "C:/Users/User/Mirror/Documents/ArduinoData/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool\esptool.py", line 3552, in main
esp.connect(args.before, args.connect_attempts)
File "C:/Users/User/Mirror/Documents/ArduinoData/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool\esptool.py", line 529, in connect
_
raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
My code is this:
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int freq = 1000; //Display refresh frequency
const int sensPin = 14; //Sensor pin #
const double pi = 3.14159265359; //Declaration of pi as a constant number
const int mags = 2; //Number of magnets on the bike ***CHANGE***
const double R = 0.34; //Radius of the bike whell ***CHANGE***
double u = 0; //Velocity
double T = 0; //Interval between two reads
long double prevTime = 0; //Previous time
int trig = 0;
int dist1 = 0;
void setup() {
WiFi.mode( WIFI_OFF );
WiFi.forceSleepBegin();
delay(1);
pinMode(sensPin, INPUT);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for (;;);
}
digitalWrite(LED_BUILTIN, HIGH);
display.clearDisplay();
display.setTextSize(1.5);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.display();
}
void loop() {
if (digitalRead(sensPin)) {
T = mags * (millis() - prevTime);
prevTime = millis();
u = ((2 * pi * R) / T) * 3600;
while (digitalRead(sensPin)) disp(u);
}
if (digitalRead(sensPin) == HIGH && trig == 2) {
dist1 += 2 * R * pi;
trig = 0;
} else if (digitalRead(sensPin) == HIGH) {
trig ++;
}
if (millis() - prevTime > 4000 / mags) u = 0;
disp(u);
}
void disp(double U) {
display.clearDisplay();
display.setCursor(0, 10);
display.print("Speed: ");
display.print(U);
display.println(" km/h");
display.print("Distance: ");
display.print(dist1);
display.println(" m");
display.setCursor(0, 10);
display.display();
}
(I have the WiFi turned off as I am not using it)
My programmer is set on the 3.3v level.
Can anyone tell me what I am doing wrong?