Sending an interrupt from ESP8266 to Arduino

Hi everyone,

I'm currently making a 4x4x4 LED cube (connected to Arduino UNO) that I want to control using a website.

I want to use the ESP8266-01 to connect to the server and check if there are any changes. If so, it should send an interrupt to the Arduino and send the data that it received from the webserver. If there have been no changes on the website, then the Arduino should its previous animation.

I am wondering whether this is possible with the ESP8266, or whether I should use the NodeMCU ESP8266 that I can program directly through the Arduino IDE.

Kind regards and thank you in advance :slight_smile:

You can program the ESP8266-01 using the Arduino IDE though the NodeMcu is much easier. I think that the NodeMCU is worth the extra expense.

alexoort:
I want to use the ESP8266-01 to connect to the server and check if there are any changes. If so, it should send an interrupt to the Arduino and send the data that it received from the webserver.

I can't think of any reason for an interrupt. Just send the data.

The program on the Arduino can be continuously checking whether a new message has arrived. Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

Hi Robin,

Since I want the Arduino to continuously run an animation on the cube, I thought that using an interrupt would be better.

Else, wouldn't the Arduino have to constantly stop the animation and check if there is new data?

Kind regards,
Alex

alexoort:
Since I want the Arduino to continuously run an animation on the cube,

It should be well able to run the animation and also check if there is anything in the Serial Input Buffer. Presumably the animation is intended to pause if there is a new instruction.

...R

But why not use the ESP to run the cube?

Incidentally, the most sensible way to operate a 4 by 4 by 4 cube, is to use a MAX7129. Larger cubes, generally not but if you only want a 4 by 4 by 4 cube, that is how to do it! :sunglasses:

by interupt, you mean to change one pin, from low to high or high to low.

the sketch on the UNO can check if that pin is high or low on ever scan without every being perceived by humans.
interrupt would not be needed.

An interup is more typically used when a signal can be sent so fast as the signal might be present and gone before the micro completes a full loop of the sketch. There are a lot of devices that send pulses that can be missed if the micro is in the middle of some other part of the sketch.

a water flow meter for instance. the interupt should be as short as possible. say, increment value by 1 for each time the interupt triggers. that way, when the sketch finishes what it is doing, and needs to look at the value, the new value is there.

altering a switch from low to high will be seen by multiple loops through your sketch so would per present when your sketch checked for that condition.

Is there a reason not to use an interrupt? I just thought that the code may be easier when using them.

Paul__B:
But why not use the ESP to run the cube?

I want to use Arduino as I'm more familiar with it and it's easier to use, right?
Kind regards,
Alex

alexoort:
Is there a reason not to use an interrupt? I just thought that the code may be easier when using them.

I doubt very much that the code will be easier. When code for an interrupt is wrong it can be very difficult to debug. Also, you can't do things like getting Serial data inside an Interrupt Service Routine (ISR) because Serial is slow and it also need interrupts to be enabled and interrupts are off during an ISR.

Interrupts are needed to detect things that happen at very frequent intervals where the Arduino cannot repeat loop() fast enough to keep up or to detect things that only exist for a very brief period - perhaps a few microseconds.

...R

alexoort:
Is there a reason not to use an interrupt? I just thought that the code may be easier when using them.

That is not what interrupts are for!

As a beginner, it is incredibly unlikely that interrupts will be useful to you.

A common "newbie" misunderstanding is that an interrupt is a mechanism for altering the flow of a program - to execute an alternate function. Nothing could be further from the truth! :astonished:

An interrupt is a mechanism for performing an action which can be executed in "no time at all" with an urgency that it must be performed immediately or else data - information - will be lost or some harm will occur. It then returns to the main task without disturbing that task in any way though the main task may well check at the appropriate point for a "flag" set by the interrupt.

Now these criteria are in a microprocessor time scale - microseconds. This must not be confused with a human time scale of tens or hundreds of milliseconds or indeed, a couple of seconds. A switch operation is in this latter category and even a mechanical operation perhaps several milliseconds; the period of a 6000 RPM shaft rotation is ten milliseconds. Sending messages to a video terminal is clearly in no way urgent,

Unless it is a very complex procedure, you would expect the loop() to cycle many times per millisecond. If it does not, there is most likely an error in code planning; while the delay() function is provided for testing purposes, its action goes strictly against effective programming methods. The loop() will be successively testing a number of contingencies as to whether each requires action, only one of which may be whether a particular timing criteria has expired. Unless an action must be executed in the order of microseconds, it will be handled in the loop().

So what sort of actions do require such immediate attention? Well, generally those which result from the computer hardware itself, such as high speed transfer of data in UARTs(, USARTs) or disk controllers.

An alternate use of interrupts, for context switching in RTOSs, is rarely relevant to this category of microprocessors as it is more efficient to write cooperative code as described above.

alexoort:
I want to use Arduino as I'm more familiar with it and it's easier to use, right?

No.

If you can program the ESP - admittedly the ESP-01 is limited in its I/O but in fact, even the ESP-01 can run a MAX7219 (or a string of them as that is exactly for what I use them) - as you presumably do already, then you can run your cube program on one and integrate the WiFi functionality.

Come to think of it, that was exactly my intention in using one - an ESP-01 - for my "Times Square" door sign as it should then be able to update the message from my secretary's smartphone.


And of course you program the ESP-01 from the Arduino IDE - using the adapter.

Nodemcu can be programmed with the arduino ide.

There is no reason you. Can't use an interupt if you want.

However if you asked what is the easiest way for a beginner to make an internet controlled LED. Cube.

We would say hands down. Nodemcu something like the MAX7129