Plugin to control arducam motorized focus?

I am using an arudcam raspi motorized focus camera. I would really like to set the focus from the octoprint UI. Is there a way to do this with a plugin?

The focus is a trivial I2C interface where you send a value from 0 to 4095 in the first two data bytes to the camera at I2C address 0x0C. Right now I am setting it from a bash script that just runs ...

i2cset -y 0 0x0c 0x01 0x00  # set focus to 100

Is there a plugin that can run this?

This could do it.

You would use that to define your bash script commands as gcode and then this one to add buttons to the UI if you don't want to use the terminal tab to send the command.

1 Like

Cool. I'll try it right away.

The g-code works great. But I couldn't get the custom control editor to work. Is there another option for a menu or button to send a g-code?

You could technically add it without the plugin, just requires some editing in the config.yaml.

That is awesome. I wish I had know about custom controls before. I guess I should ratfm (read all the freaking manuals). I was happy to see I could even easily add a slider control. This would be great for focusing.

But, to add a slider I need a way to send a param with my system (bash) command. I don't see how I can do this with the GCODE Systems Commands plugin. Is there a way I can send a system command without that plugin? Or should I just ratfm. :slight_smile:

If I'm not mistaken I think custom controls can be system commands, but would have to look at the docs again. BTW, the custom control plugin is just a front end to set those in config.yaml.

I take that back, those are system commands that can run external scripts but not custom controls.

@kantlivelong is an active developer so he might know a trick for passing parameters to his gcode system commands plugin.

It looks like there's an active pull request to his plugin too that enables that feature.

1 Like

Passing arguments was intentionally left out for security reasons. That PR does seem to implement the support for arguments but it's not something I want to merge in its current state. I was actually looking at it a little today to brainstorm a way to sanitize arguments. Have some ideas but nothing concrete yet.

1 Like

I don't understand the security risk. No one can get into my plugin setup so how could damage be done?

There are configurations out there that are multi-user where not everyone is an admin. Blindly passing arguments allows someone to easily execute whatever shellcode they want. Could it just be a tick box on the settings? Sure, but that's not really how I like to implement things.

Just made me think of a fairly simple solution though. I could pass the line as an environment variable which would then put the role of checks on the user. The downside is that users that would possibly need to make use of simple built in executable commands would need a wrapper. Not too bad though really.

1 Like

I don't understand that but it's no problem for me since I'm already calling a bash script with my system command.

P.S. If I get my custom focus control working is there any way to make it available as a plugin without all the python stuff?

Not quite sure what you mean. Plugins are mostly python, or at least require some python to at least install load the web/javascrpt stuff within the OctoPrint framework. Doing a quick search there appears to be some pretty easy interfacing for I2C interfaces from python using smbus module. If that truly is the case then adding buttons on the web interface to run commands on the python back-end is fairly trivial.

The other option from python side would be running the i2cset command directly using subprocess module or sarge.

1 Like

Looks like their own python examples utilize the system command method here.