Hello,
I am building a machine which will need several sensors (Inputs) and pneumatic solenoids (Outputs). In search for low cost IO cards/expanders I found MCP23017 could do the job. I built the electronics with 8 MCP23017s with addresses from 0 till 7. Each MCP23017 has Port A defined as outputs and Port B as Inputs. All Inputs are pulled up.
All MCPs were connected to the Arduino Uno with I2C. Arduino was programmed using Adafruit_MCP23017.h library, to receive Input Data and Send Output data. For receiving and sending, my GUI was made in VB.net which sends a character “I” each 1ms (using timer) to the Arduino (serial comm). Each time Arduino gets this character, it checks and sends the sensor status to VB.net. For Outputs, whenever required, Vb.net sends a 65 character string with first 64 containing output status (0 or 1) and a specific 65th character “O” for Arduino to decipher end of line. When the output data is sent, VB.net stops the 1ms timer sending “I” and sends the Output data instead, and then restarts the 1ms timer.
So far so good. All works perfectly and I see the status of all sensors nearly real-time (1ms) and am able to send output data as and when required.
The question is - is it ok to keep checking for sensor data (Inputs) each 1ms? Or should I instead use interrupts? Honestly the Rx/Tx LEDs constantly blinking on the Uno somewhat scare me as if it’ll limit the reliability/longevity of the Uno.
Hence I started working on the interrupts. I configured the MCPs for Active Low interrupts using Since Uno had only 2 pins for interrupts, I joined all interrupts and connected them to Pin D2. Nothing works. If I connect only one MCP23017 interrupt (any 1 out of 8), it works seamlessly. I finally noticed that tying together up to 3 interrupts together works fine (could be any 3 out of 8). But the moment the 4th one is connected, Arduino stops accepting interrupts, OR MCPs stop giving out interrupts.
I then thought of combining these 8 interrupts using CD4068 - 8-input Nand gate. I fed all interrupts to the 8-inputs and connected the output to Arduino D2. As soon as any interrupt is received, the CD4068 goes high, but remains high and doesn’t come back to 0. I tried pulling down this output but it still doesn’t work.
This is where I am stuck right now.
Can you please help answering:
a) whether my decision to use interrupts is valid? Or should I continue working with 1ms timer to check inputs? Please keep in mind that the machine will be running 20 hrs a day and 300 days a year!
b) what am I doing wrong in combining the interrupts to get a single interrupt.
Hope you can help me out!!
Regards
Vinit