How To Communicate Between ATMega328 & NodeMCU

I have a working project where 2 Arduino Nanos communicate via i2c. One sends 2 bytes, and one receives two byes. It works well.

I'd like to do the same thing, using one Arduino and one NodeMCU 12e (Amica). Some of my primary questions are:

  • Will differing logic voltages be OK? Or should I use a 3.3v Arduino?
  • Will the NodeMCU handle the i2c interrupts appropriately? It seems like there's something about wifi & interrupts - perhaps the incompatibilities are with hardware interrupts rather than i2c? (is the i2c receive event even an interrupt?)

Any other tips would be much appreciated.

Will differing logic voltages be OK?

No.

Or should I use a 3.3v Arduino?

Or a level shifter.

Will the NodeMCU handle the i2c interrupts appropriately?

No idea. Don't assume every one knows what one of these is, when you read How to use this forum you will see it asks you to post links to hardware.

is the i2c receive event even an interrupt?

Yes. There are many levels of interrupt priorities.

I'd like to do the same thing, using one Arduino and one NodeMCU 12e (Amica).

You do not state "why" you are using two I2C connected Arduinos in a simplex manner. But you need to be aware that if you intend on programming the ESP8266 using the ArduinoIDE that the software architecture requires that the Arduino sketch release its timeslice every 30mS (some references say as long as 50mS.) Failure to release your time slice may result in the RF protocol stacks becoming starved, may result in numerous bad happenings, including the WDT shutting down the uC with a stack dump.

Considering the above, you absolutely cannot use any code that blocks. The Arduino core for the ESP8266 is specially written to avoid blocking, but 3rd party libs are always a concern. Other concerns is that libs that embed any AVR-centric assembler will not work unless the author has rewritten to accomodate the ESP. And not to be overlooked is that "int" is 32-bit wide where 8-bit AVR code defines an "int" as 16-bits.

But, I love the ESP8266 ... at $4 for a NodeMCU, it may be the best fun per buck in the Arduino field.

Ray

You do not state “why”

Good point.

Here’s a current 2-Arduino I2C setup I have working:

  • GPS speed alerter. It beeps and flashes neopixels depending on how fast over the set speed limit I’m going.
  • Arduino 1: GPS and interface control. I2C Master. It gets the speed, controls the OLED, and handles rotary encoder interaction. So, I click the encoder, and can set a new speed.
  • Arduino 2: Beep and NeoPixel controller. I2C Receiver. Receives 2 bytes (speed and limit), then beeps and/or animates NeoPixels depending on how fast over. Say I have the limit set to 60. If I go 61-65, the pixels flash orange. If 66+, the pixels flash a random sequence of police-light imitations. It’s pretty sweet.

Why
I did this to eliminate some problems. First, NeoPixels don’t play nice with hardware interrupts. So, while the encoder click worked any time you’d click, the pixels would mess up. But, running without interrupt, the pixels would be animating and the encoder click would be ignored. Perhaps I could change things up and convert all my animations to async, but that seemed overly complex, when I could just use two arduinos to split the processing.

Why I’d like to swap one of them with a ESP12e:
Configuration and unit testing. I’d like to make the ESP12e a server on its own access point in order to do some fine tuning and trigger test procedures. Like, “play animation 1” or “set incremental mode to 5’s instead of singles” or “turn buzzer off” or tap into other GPS values, etc.

Does this make more sense?