sparkfun / SparkFun_ESP8266_AT_Arduino_Library

WiFi and TCP drivers for an ESP8266 running AT firmware.
MIT License
75 stars 47 forks source link

Don't call Serial.begin() #2

Open matthijskooijman opened 9 years ago

matthijskooijman commented 9 years ago

I noticed that right now, the begin() method accepts an enumeration to switch between the primary serial port and softwareserial, and begin() also calls the begin() method on the chosen serial object. This approach is very inflexible, since:

Instead, it would be better to just let begin() accept a Stream& reference, and expect the sketch to call begin() on that and specify the baudrate. For example, the xbee-arduino library also uses this approach: https://github.com/andrewrapp/xbee-arduino/blob/master/XBee.cpp#L786-L788 https://github.com/andrewrapp/xbee-arduino/blob/master/examples/AtCommand/AtCommand.pde#L54-L55

With this library still being new, hopefully you'll consider this change now, before it would break too many existing sketches.

Apollon77 commented 9 years ago

I would support this idea because I want to use an Mega2560 and so my idea is to connect the PINs 0 and 1 not to the board, but to other available HW-Serial-PIns (like Serial1).ö I would also do this change and send oull-request if you are interested in!

santaimpersonator commented 5 years ago

I am not sure if I understood your question correctly. However, it seems like you might be referring to the examples that require both the hardware serial ports and the software serial pins to interact with the shield. The hardware pins allow your computer to talk to the microcontroller and software serial pins allow your microcontroller to interact with the ESP8266 shield on a separate serial port. Without which, it would create collisions between the two on the UART hardware pins.

Otherwise, you should be able to exclude the software serial library and communicate from the microcontroller to the ESP8266 using the hardware pins. You just need to specify which port to use in the begin statement as written in the source code.

esp8266.begin(9600, ESP8266_HARDWARE_SERIAL);

WARNING: If you try to program your microcontroller and the shield switch is in the hardware position, you can brick the ESP8266. The stream of data that is meant for programming the microcontroller on the hardware pins can create random AT commands and lock up or break the ESP8266. This is why it is usually a best practice to use separate serial ports.

santaimpersonator commented 5 years ago

You may want to look at this pull reques too: https://github.com/sparkfun/SparkFun_ESP8266_AT_Arduino_Library/pull/10