Interrupt and Serial at the same time

Hello everyone! My name is Michael and I am new on this forum, as I am trying to understand some of the features of ATMega382P.

What I am trying to build is a drone controlled by Arduino Nano, using an MPU 6050 as gyro+acc reader and Esp8266 01 as receiver (wifi).

What I've achieved so far is making each individual component work independently:

  • The MPU reads Gyro and Acc and outputs real angle using Euler's formula
  • The ESP8266 can be connected to a wifi and sent data, which is then parsed into X,Y,Z,W values
  • The 30A esc's are controllable via PWM pins 6,9,10,11.

My issue now is to integrate everything. I struggle with putting everything together because there is not much I can find on google regarding to using ESP8266 01 as an input for a complex time-critical project.

What I would like to know first is, is it possible to use SoftwareSerial and Pin Interrupt at the same time?

For example: My ESP8266 is connected to pins 4 and 5 and I want to pause the normal execution of the program, read the data, and then resume where I left off.

Thank you for your responses. I will update this with source code soon.

mylast:
What I would like to know first is, is it possible to use SoftwareSerial and Pin Interrupt at the same time?

Yes.

For example: My ESP8266 is connected to pins 4 and 5 and I want to pause the normal execution of the program, read the data, and then resume where I left off.

I don't really get what you try do do here.

You won't get an interrupt to handle upon receipt of data (it'll be buffered) - you will have to check often for new data and act on it.

Ok. This is the issue I was worried about.

I think there might be another alternative:

What if I program the esp8266 to do the following:

Wait for data to arrive via UDP and, when it arrives, send it through software serial and pull one of the GPIOs high and then pull it back low.

On the arduino, just execute the normal routine and, when the interrupt pin is pulled high (GPIO pulled it), then read from serial?

Would this be possible?

What I am trying to achieve is to read data from this wifi module and use it in my routine.

My code looks like this so far: [code]/* *  _                      _             ____  ____   * | |__   _ - Pastebin.com

Note that I have input only for throttle right now, as I am interested to just hover the drone.

mylast:
For example: My ESP8266 is connected to pins 4 and 5 and I want to pause the normal execution of the program, read the data, and then resume where I left off.

That is nearly, but not quite, the correct way to think about the problem.

Your program should consist of series of small activities that each get called in turn. One of those activities will read the serial data if any is available. Don't think about one part of the program as "normal" compared to any other part. Everything is part of the "normal" program.

Have a look at the examples in Serial Input Basics - simple reliable, non-blocking ways to receive data.

Have a look at Planning and Implementing a Program. Note how each function runs very briefly and returns to loop() so the next one can be called. And there may be dozens of calls to a function before it is actually time for it to do anything.

...R

mylast:
What if I program the esp8266 to do the following:

Wait for data to arrive via UDP and, when it arrives, send it through software serial and pull one of the GPIOs high and then pull it back low.

This overlapped with my Reply #3.

There is no need to use an interrupt to let the 328 know that data has arrived because serial data arrives very slowly by Arduino standards - even at 500,000 baud - and polling will be sufficiently responsive.

...R

Hi. Thank you very much for your response. Reading your guide led me to understand it makes complete sense to just let go and relay on your chip.

My concerns were that the chip would not wait for the serial to finish.

I can now receive data easily and use my controller to control the motors.

However, now I found out that my MPU6050 readings and computation is not so bright. I get wrong angles from the readings and my drone fails to take off.

mylast:
However, now I found out that my MPU6050 readings and computation is not so bright. I get wrong angles from the readings and my drone fails to take off.

I presume all that stuff is calculated on the drone and does not depend on data from the Atmega 328.

...R

My post might be confusing. Sorry.

So my only components are ESP8266 01 (Wifi receiver), MPU6050 (Gyro+acc) and Arduino Nano which binds everything and calculates angles and sends to escs

mylast:
My post might be confusing. Sorry.

My mistake. Apologies. I was confusing you with another Thread and thought you were getting the serial data via Bluetooth.

If you need more advice then post the latest version of your program and tell us what it actually does and what you want it to do that is different.

...R