Error Uploading code to ESP Module

Hi,

While trying to upload my code to my ESP module, I am getting these errors:

Archiving built core (caching) in: C:\Users\RyanB96\AppData\Local\Temp\arduino_cache_254861\core\core_esp8266_esp8266_nodemcu_CpuFrequency_80,UploadSpeed_115200,FlashSize_4M3M_d3b6212c6c4266333fad19039a8b346d.a
Sketch uses 248857 bytes (23%) of program storage space. Maximum is 1044464 bytes.
Global variables use 33848 bytes (41%) of dynamic memory, leaving 48072 bytes for local variables. Maximum is 81920 bytes.
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 36 bytes
error: failed sending 0xC0
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed

Does anyone have any ideas?
Here is my code:

//----------------------------------------------
//
//        Sketch Generated by Visuino
//              www.visuino.com
//          Version  7.8.2.228
//
//------------------ Source --------------------
//
// ESP Modules Setup.owarduino
//
//----------------------------------------------

#define VISUINO_ESP8266

#include <OpenWire.h>
#include <Mitov.h>
#include <ESP8266WiFi.h>
#include <Mitov_ESP8266_WiFi.h>
#include <Ethernet.h>
#include <SPI.h>
#include <Mitov_FormattedSerial.h>
#include <Mitov_GPS.h>
#include <Mitov_Text.h>
#include <Mitov_Timing.h>

// Arduino Board Declarations

namespace BoardDeclarations
{
Mitov::TypedSerialPort<Mitov::SerialPort<SERIAL_TYPE, Serial>, SERIAL_TYPE, Serial> SerialPort0;
Mitov::ArduinoSerialOutput<Mitov::TypedSerialPort<Mitov::SerialPort<SERIAL_TYPE, Serial>, SERIAL_TYPE, Serial>, SerialPort0> SerialOutput0;
} // BoardDeclarations

// Declarations

namespace Declarations
{
Mitov::ESP8266WiFiModule TArduinoESP8266WiFiModule1;
Mitov::ESP8266ModuleRemoteAccessPoint TArduinoESP8266WiFiModuleRemoteAccessPoint1( Declarations::TArduinoESP8266WiFiModule1 );
Mitov::TCPServerSocket<Mitov::ESP8266WiFiModule, Declarations::TArduinoESP8266WiFiModule1, WiFiServer, WiFiClient> TArduinoWiFiTCPServerSocket1;
Mitov::EthernetSocketStringInput<Mitov::TCPServerSocket<Mitov::ESP8266WiFiModule, Declarations::TArduinoESP8266WiFiModule1, WiFiServer, WiFiClient>, Declarations::TArduinoWiFiTCPServerSocket1> TArduinoWiFiTCPServerSocket1_SerialInputString_1;
Mitov::MitovSerialGPS GPS1;
Mitov::FormattedText_Fixed FormattedText1;
Mitov::FormattedTextElementAnalog TArduinoFormattedTextElementAnalog1( Declarations::FormattedText1 );
Mitov::FormattedTextElementAnalog TArduinoFormattedTextElementAnalog2( Declarations::FormattedText1 );
Mitov::Delay Delay1;
} // Declarations

// Type Converters

namespace TypeConverters
{
Mitov::Convert_BinaryToClock Converter0;
} // TypeConverters

// Pin Call Declarations

namespace PinCalls
{
void PinCallerReceive1( void *_Data );
void PinCallerReceive2( void *_Data );
void PinCallerReceive3( void *_Data );
void PinCallerReceive4( void *_Data );
void PinCallerReceive5( void *_Data );
void PinCallerReceive6( void *_Data );
void PinCallerReceive7( void *_Data );
} // PinCalls

// Pin Call Implementations

namespace PinCalls
{
void PinCallerReceive2( void *_Data )
{
  TypeConverters::Converter0.Convert( _Data, PinCallerReceive1 );
}

void PinCallerReceive1( void *_Data )
{
  Declarations::FormattedText1.ClockInputPin_o_Receive( _Data );
}
void PinCallerReceive3( void *_Data )
{
  Declarations::GPS1._DirectPinReceive( _Data );
}

void PinCallerReceive4( void *_Data )
{
  Declarations::TArduinoFormattedTextElementAnalog1.InputPin_o_Receive( _Data );
}

void PinCallerReceive5( void *_Data )
{
  Declarations::TArduinoFormattedTextElementAnalog2.InputPin_o_Receive( _Data );
}

void PinCallerReceive6( void *_Data )
{
  Declarations::TArduinoWiFiTCPServerSocket1_SerialInputString_1.InputPin_o_Receive( _Data );
  Declarations::Delay1.StartInputPin_o_Receive( _Data );
}

void PinCallerReceive7( void *_Data )
{
  Declarations::TArduinoWiFiTCPServerSocket1.DisconnectInputPin_o_Receive( _Data );
}

} // PinCalls

namespace ComponentsHardware
{
void SystemUpdateHardware()
{
}
} // ComponentsHardware

//The setup function is called once at startup of the sketch
void setup()
{
  Declarations::FormattedText1.ClockInputPin_o_IsConnected = true;
  Declarations::TArduinoESP8266WiFiModule1.AccessPoint.SSID = "ryan's iphone";
  Declarations::TArduinoESP8266WiFiModule1.AccessPoint.Password = "ryanwifi";
  Declarations::TArduinoESP8266WiFiModule1.HostName = "gpsserver";
  Declarations::TArduinoWiFiTCPServerSocket1.ConnectedOutputPin.SetCallback( PinCalls::PinCallerReceive2 );
  BoardDeclarations::SerialOutput0.OutputPin.SetCallback( PinCalls::PinCallerReceive3 );
  Declarations::GPS1.LocationOutputPins[ 0 ].SetCallback( PinCalls::PinCallerReceive4 );
  Declarations::GPS1.LocationOutputPins[ 1 ].SetCallback( PinCalls::PinCallerReceive5 );
  Declarations::FormattedText1.OutputPin.SetCallback( PinCalls::PinCallerReceive6 );
  Declarations::FormattedText1.AddReadyElement( (char *)"HTTP/1.1.200 OK \r\nContent-Type: text/html\r\nConnection: close\r\nRefresh: 5\r\n\r\n<!DOCTYPE html>\r\n<html> \r\n<head> \r\n<script type = \"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=false\">\r\n</script>\r\n</head>\r\n<body> \r\n<div id=\"map\" style = \"width:800px;height 600px\"></div>\r\n\r\n<script type=\"text/javascript\">\r\nvar myLatLng = {lat: ", 0 );
  Declarations::FormattedText1.AddReadyElement( (char *)", lng: ", 1 );
  Declarations::FormattedText1.AddNullElement( "};\r\nvar myOptions = {\r\nzoom : 19,\r\ncenter: myLatLng,\r\nmapTypeId: google.maps.MapTypeId.HYBRID\r\n};\r\n\r\nvar map = new google.maps.Map(document.getElementId(\"map\"),myOptions);\r\nvar marker = new google.maps.Marker ({\r\nposition: myLatLng,\r\nmap: map, \r\ntitle: \"My ESP8266 GPS\"\r\n});\r\n\r\n</script>\r\n</body>\r\n</html> " );
  Declarations::Delay1.OutputPin.SetCallback( PinCalls::PinCallerReceive7 );

  Declarations::TArduinoESP8266WiFiModule1.SystemInit();
  Declarations::TArduinoWiFiTCPServerSocket1.SystemInit();
  BoardDeclarations::SerialPort0.SystemInit();

  Declarations::FormattedText1.SystemStart();
  Declarations::TArduinoFormattedTextElementAnalog1.SystemStart();
  Declarations::TArduinoFormattedTextElementAnalog2.SystemStart();
}

// The loop function is called in an endless loop
void loop()
{
  unsigned long A_Current_Microseconds = micros();

  BoardDeclarations::SerialOutput0.SystemLoopBegin( A_Current_Microseconds );
  Declarations::TArduinoWiFiTCPServerSocket1.SystemLoopBegin( A_Current_Microseconds );
  BoardDeclarations::SerialPort0.SystemLoopBegin( A_Current_Microseconds );
  Declarations::Delay1.SystemLoopBegin( A_Current_Microseconds );

  Declarations::FormattedText1.SystemLoopEnd( A_Current_Microseconds );
}

Sketch uses 248857 bytes (23%) of program storage space. Maximum is 1044464 bytes. Global variables use 33848 bytes (41%) of dynamic memory, leaving 48072 bytes for local variables. Maximum is 81920

That usually indicates that the sketch compiled correctly. The problem seems to be in communication between the PC an ESP. Are you able to put the ESP into programming mode (GPIO 0 held low while the ESP is reset)? Which ESP module are you using?

Apologies - I am very new to using the arduino

How would I go about putting it into programming mode?

Pull GPIO0 low when starting up the module to get it in program mode. For normal bootup, pull it high.

GPIO15 must also be pulled low externally.

GPIO2 must be pulled high but that's normally done by the internal pull-up, no external pull-up needed for this pin.

CH_PD also has to be pulled high.

Just a note - I am using the NodeMCU (ESP-12) module / board I believe

The ESP8266 beginners guide may have information of interest.

Then you have a very convenient Flash button. Hold that while powering up (or resetting) to set the board in boot mode.

The NodeMCU development board indeed comes with an ESP-12 module.

I do indeed have a little button labelled FLASH.

To use the board its connected via microUSB to my laptop. So when you mention holding the flash button while restarting, do you mean holding it while I plug it into my laptop?

Im currently researching how to put it into programming mode

Either hold the flash button down as you plug the USB in (power up the ESP) or while the ESP is powered, hold the flash button down, press and release the reset button and then release the flash button.

Okay, so when doing that, I lose the longer list of errors - but I still get this:

Sketch uses 222217 bytes (21%) of program storage space. Maximum is 1044464 bytes. Global variables use 31592 bytes (38%) of dynamic memory, leaving 50328 bytes for local variables. Maximum is 81920 bytes. error: Failed to open COM4 error: espcomm_open failed error: espcomm_upload_mem failed error: espcomm_upload_mem failed

error: Failed to open COM4

In the Tools menu under the boards submenu, which port is specified?

esp tools menu.jpg

Okay so I think the microUSB may be slightly dodgy.

The port was greyed out - but after replugging in, it came back as COM4 and now the error has gone. These are the errors I need to solve:

warning: espcomm_sync failed error: espcomm_open failed error: espcomm_upload_mem failed error: espcomm_upload_mem failed

If the cable is “dodgy” replace it. Just because the port shows up does not mean that the cable can transfer the sketch data, reliably, at 115200 baud.

Wow! Changing the cable actually fixed it and its now uploaded!! Thank you very much!