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.
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.
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.
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.
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