Esp8266 library not found

This came out of my library headache from a few weeks ago. Once I got the library clash solved, I tried connecting to my esp8266 chip but it wouldn't connect, I tried all the usual fixes (checking physical connections, ports and drivers). I then discovered that the board selected was incorrect, A generic esp8266 board was selected but I'm using an arduino mega which the esp8266 chip is connected to. I selected the correct board and it's now saying it can't find the library. What am I doing wrong? Any help would be greatly appreciated.

Which library I are you trying to use and exactly which Arduino board do you have ? Is it a stand alone Mega or combined with the ESP8266 ?

It's a stand alone mega with an ESP8266 chip (not the board) connected. The library is still ESP8266WiFi.h

In order to program the ESP8266 you need to select that board and its associated COM port in the IDE.

In order to program the Mega you need to select that board and its associated COM port in the IDE.

I've just realised I've made a mistake, it's an esp01 on an arduino mega

To clear up any confusion, please post a link to the board that you have

Sorry about the confusion: https://www.amazon.co.uk/ARDUINO-MEGA-2560-REV3-A000067/dp/B0046AMGW0

OK. That is a standalone Mega with no ESP8266 on board, so what I said previously applies

Ok sorry about the confusion, I've got the board set correctly but it says it can't find the library despite the fact it found the library when I had the wrong board selected

If you have the Mega selected then no wonder that it cannot find a library written and used exclusively by the ESP8266

You cannot upload code for the ESP8266 to the Mega

What exactly are you trying to do with the two boards and how are they connected ?

I'm trying to build a burglar alarm which will connect to a phone app via WiFi. The relevant parts are the Arduino Mega at the top and the ESP-01 bottom left

Presumably the Mega does most of the work such as reading sensors and then passes a message of some kind to the ESP8266 that passes a message of some kind to the 'phone app

How much of this have you got working ?

As you are trying to use an ESP8266 library I assume that you are trying to program the ESP8266. Are you following instructions from somewhere or are you just trying to go it alone ?

I have decided to buy an ESP8266 board rather than try to use the chip. I hadn't managed to get any communication between the Arduino Mega and the chip. I think the confusion has come because the chip was sold to me as an ESP8266 when that term seems to usually refer to a board. I am going it alone but if you know of any useful instructions please let me know.

A full ESP8266 board will certainly be easier to upload code to it than the ESP-01.

I have managed to upload code to it using a Uno in the past as well as a USB to serial converter but it seems to be a bit of a black art. Certain pins have to be in the correct state for it to work and it needs to be reset at the right time in order for the upload to work

Depending in what you are doing, it may well be that you don't need the Mega at all and that a single sketch on the ESP8266 will do what you want, thus making it even simpler

Good luck going forward

Further to what @UKHeliBob said, you need to program both the ESP-01 and the Arduino Mega separately.

Since the Mega uses it's RX and TX pins to talk to a UART, which are also needed to program the ESP-01, you probably have a conflict. You probably have to remove the ESP-01 and program it with something like a USB-TTL adapter (and then reconnect it after programming).