Need Help Configuring MCP23017 for Peristaltic Pumps in Mycodo

Hi everyone,

I’m encountering an issue while trying to configure my peristaltic pumps with Mycodo and the MCP23017 16-Channel I/O Expander. Here are the details of the problem:

  1. On the output configuration page in Mycodo, the status always shows as “Unconfigured”.
  2. When I attempt to activate the pumps, I receive the following error message:

Output 9ae3d3de-3aac-4ce2-a66b-bd7f649498c4: ERROR: Could not turn output on: 0.

I’ve verified that the I2C address and connections are correct, as I’m able to control the pumps through the MCP23017 I/O expander using the Output: On/Off: MCP23017 16-Channel I/O Expander without any issues.

System Information:

  • Mycodo Version: 8.15.13
  • Python Version: 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  • Database Version: 16b28ef31b5b

Has anyone successfully configured peristaltic pumps with Mycodo using the MCP23017? Any advice or steps I might be missing would be greatly appreciated.

Thanks in advance for your help!

Best regards,

Yannick

Hi Yannick,
Is there anything unusual in the daemon log?

Hi Kyle,

I’ve been working with Mycodo for about a month, and I come from an electrical engineering background, not programming or software development. Here are the relevant log messages from the daemon log:

File "/var/mycodo-root/mycodo/mycodo_daemon.py", line 782, in output_on
    return self.controller['Output'].output_on_off(
File "/var/mycodo-root/mycodo/controllers/controller_output.py", line 299, in output_on_off
    return self.output[output_id].output_on_off(
File "/var/mycodo-root/mycodo/outputs/base_output.py", line 378, in output_on_off
    ret_value = self.output_switch(
File "/home/admin/Mycodo/mycodo/outputs/pump_mcp23017.py", line 363, in output_switch
    if self.currently_dispensing[output_channel]:
KeyError: 0

I find this project very exciting and have put a lot of work into it. Thanks for your help!

Yannick

1 Like

Thanks. I’ll look into this. It looks like it should be an easy fix. I’ll let you know what I find.

I found what I believe to be the issue and committed a fix on the unreleased master branch:

You can upgrade to amster, or apply the fix manually, to test if the changes fixed your issue.

After uploading your suggested changes, I encountered the same issues with channels 1-15 while trying to configure my peristaltic pumps.

Channel 0 Behavior:

When I press the “On” button for channel 0, I get the following success message:

Output 9ae3d3de-3aac-4ce2-a66b-bd7f649498c4: SUCCESS: Output 9ae3d3de-3aac-4ce2-a66b-bd7f649498c4 CH0 (Name) ON at 2024-06-05 09:37:11.674154. Output returned: None

So everything is working fine for channel 0.

I cannot control other channels besides channel 0. For example, when trying to activate channel 1, I receive the following error message:

Output 9ae3d3de-3aac-4ce2-a66b-bd7f649498c4: ERROR: Could not turn output on: 1.

The corresponding log entry is:

2024-06-05 09:50:05,906 - ERROR - mycodo - Could not turn output on: 1
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/mycodo_daemon.py”, line 782, in output_on
return self.controller[‘Output’].output_on_off(
File “/var/mycodo-root/mycodo/controllers/controller_output.py”, line 299, in output_on_off
return self.output[output_id].output_on_off(
File “/var/mycodo-root/mycodo/outputs/base_output.py”, line 378, in output_on_off
ret_value = self.output_switch(
File “/home/admin/Mycodo/mycodo/outputs/pump_mcp23017.py”, line 364, in output_switch
if self.currently_dispensing[output_channel]:
KeyError: 1

The same issue occurs for all other channels (1-15).

Thanks in advance for your help and the quick assistance!

Try the latest commit and see if that fixes it.

Hi Kyle,

The pumps can now all be controlled, and I am excited to get my system up and running soon.

However, I noticed a minor display error. After initially controlling the pump, the field shows “active” or “inactive.” However, once the backend or the entire system is restarted, the field reverts to “unconfigured.”

Since I appreciate the work on this project so much, I will make a small donation via PayPal.

Thanks. I’m not sure what the issue is. Nothing appears to be wrong with the module and the initial fix I made should have worked. I made some more minor changes, perhaps one fixes that issue.

Have you been chacking the daemon log immediately after saving the output settings, to see if there are any initialization errors?

I was just able to test the changes, and it seems that channel 0 now stays in the “inactive” state. However, for all other channels, the status resets to “unconfigured.” (I’ve disabled all functions that control the pumps, so it seems to be working with channel 0).

Here is what I saw in the log after pressing save:

Traceback (most recent call last):
File “/home/admin/Mycodo/mycodo/outputs/pump_mcp23017.py”, line 199, in initialize
if self.options_channels[‘state_startup’][channel] == 1:
KeyError: ‘state_startup’
2024-06-11 08:04:35,036 - INFO - mycodo.outputs.pump_mcp23017_0a5746ca - Initialized in 333.9 ms

That was what I needed. It should work now.

1 Like

Yes, everything is now working perfectly.
I believe this thread can be closed. Thanks again!

1 Like