I gather from casual skimming of threads that there are issues to be wary of if I want the same Arduino to participate in both a serial data interchange with another device, and an i2c bus. I'll describe specifically what I'm wanting to do, and maybe someone can steer me away from the dead ends and towards a sensible approach.
I have a fairly complex game controller (first revision) with almost 40 buttons (!). At present it consists of 2 Arduinos, one to monitor sensors in real-time & emulate a joystick, and one to interact with the user via all those buttons (and some knobs, and leds and digital displays and stuff) & emulate a keyboard. The whole thing is glued together with i2c (button pads from Adafruit, sensors, the 2 Arduinos, display backpacks...) and it's been working great, very solid.
I'm thinking that Version 2 would be far more compact and attractive with a multipage touch screen. The obvious first choice for such a touch screen (at least so it seemed to me) was a Nextion, because of its low serial overhead & ease of gui-building.
So I would like to maintain a live serial connection to the Nextion, listening for output from that device, while also participating in the i2c bus that connects all the sensors and micros in my project.
A primitive test sketch for the display is working ok -- I can detect button-release events and send some status data from the screen to the Arduino. However, my test sketch is doing absolutely nothing but listen to the Nextion. So I started googling for "serial and i2c, arduino" (etc) and found rather troubling comments about interrupts conflicting, losing bytes, etc. I'm not technical enough to follow all the details, but the fact that this is even a topic of discussion worries me
Here are my (somewhat naive, sorry) questions (I'm not expert enough to dive into the i2c libs, or the serial lib, and just by reading the code understand what's really going on in there).
-
does the i2c bus master secretly use an ISR deep down in the library, or is its 'read slave' and 'write slave' functionality in the main execution loop where it appears to be? I know the slave sketch uses a visible ISR which I had to customise. The aim of this question is to find out whether the i2c bus master can afford an ISR serving the serial display interface, because there is no other ISR to muck up the timing.
-
is there any other recommended & graceful (non i2c, non-ISR) way of sharing data between 2 arduini? Can 2 arduini share (I'm speculating wildly here) some kind of serial device with two ports and two buffers, each being able only to read one, and only to write the other? So they can "check the mailbox" at their own discretion? Alternatively is there a device I could put between the display and the Arduino, with a large buffer, that would store up the serial output until I feel like reading it, so as to eliminate the risk of dropping bytes while distracted?
Sorry to be so vague. Serial comms is not my thing, as you can tell, and before getting into a lot of painful head-bashing I thought I would ask for some guidance & see what handy gizmos might be out there whose names I don't know and therefore can't google