Serial NodeMCU and Arduino

Serial NodeMCU and Arduino

This page is to Setup and Config Serial NodeMCU and Arduino

Hardware and Software

Hardware

Serial NodeMCU and Arduino

Software

Arduino IDE and ESPLORER

Sanki Notes

Connect :

NodeMCU RX <--> Arduino Pin 11

NodeMCU TX <--> Arduino Pin 10

Both Are 115200

Examples

This example is for Arduino Write a Signal mySerial(10, 11) RX and TX tp NODEMCU

Examples

This example is for NodeMCU (lua) Receive data from Arduino on Serial RX/TX and Send back a DATA

--Others Example for Send data from NodeMCU to Arduino

uart.setup(0, 115200, 8, 0, 1, 0)

--uart.on(1)

--uart.write(0, "page 3")

val = 65

while 1 do

uart.write(0, string.char(val), "\r\n")

val = val + 1

if val > 90 then

val = 65

end

tmr.delay(1000000)

end

            1. /*

            2. Software serial multple serial test

            3. Receives from the hardware serial, sends to software serial.

            4. Receives from software serial, sends to hardware serial.

            5. The circuit:

            6. * RX is digital pin 10 (connect to TX of other device)

            7. * TX is digital pin 11 (connect to RX of other device)

            8. Note:

            9. Not all pins on the Mega and Mega 2560 support change interrupts,

            10. so only the following can be used for RX:

            11. 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

            12. Not all pins on the Leonardo support change interrupts,

            13. so only the following can be used for RX:

            14. 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

            15. created back in the mists of time

            16. modified 25 May 2012

            17. by Tom Igoe

            18. based on Mikal Hart's example

            19. This example code is in the public domain.

            20. */

            21. #include <SoftwareSerial.h>

            22. SoftwareSerial mySerial(10, 11); // RX, TX

            23. ledOn = 0

            24. void setup() {

            25. pin=4

            26. // Open serial communications and wait for port to open:

            27. gpio.mode(pin,gpio.OUTPUT)

            28. Serial.begin(115200);

            29. --uart.alt(1)

            30. while (!Serial) {

            31. uart.on("data", 3,

            32. ; // wait for serial port to connect. Needed for native USB port only

            33. function(data)

            34. }

            35. print("Received from NodeMCU By SANKI:", data)

            36. if data=="HI!" then

            37. if ledOn==0 then

            38. Serial.println("Goodnight moon!");

            39. ledOn = 1

            40. gpio.write(pin,gpio.HIGH)

            41. // set the data rate for the SoftwareSerial port

            42. print("LED On SANKI")

            43. mySerial.begin(115200);

            44. else

            45. mySerial.println("HI!");

            46. ledOn = 0

            47. }

            48. gpio.write(pin,gpio.LOW)

            49. print("LED Off SANKI")

            50. void loop() { // run over and over

            51. end

            52. if (mySerial.available()) {

            53. else

            54. Serial.write(mySerial.read());

            55. print("Input data ")

            56. }

            57. print(data)

            58. if (Serial.available()) {

            59. end

            60. mySerial.write(Serial.read());

            61. end, 0)

            62. }

            63. }