WebControl and Pi 4 GPIO pins

Hello, I just recently put together my Maslow CNC and am new to the forums. To date I have the machine up and running, working out a few kinks, but recently used a PI 4 to setup WebControl. I used the non-docker RPI image and have been trying to get the GPIO pins functioning for external buttons. I have verified through the file system that the GPIO buttons are registering values when I press buttons, but nothing happens when these buttons are mapped in WebControl.

I went as far as to view Orob’s github repo and saw he has provided MaslowButton services for Systemd but they fail to start for me as I do not have a GPIO folder in webcontrol?

At any rate, has anyone gotten the GPIO pins with buttons to function? I am missing something? Any help is appreciated!

I have them working. In order for the button service to work, you have to run the webcontrol main.py that receives the socket information from the button service. Can’t have one without the other. The problem with the buttons has to do with gevent and the threads started in gpiozero that manage the button functions. They don’t play nice, so the buttons don’t work. If instead of threads, you use a separate process, like a service and send the button information over the socket to the webcontrol program, then it works just fine… mostly. Sometimes starting and stopping the service is more of an issue, but most of the time it does fine.

The github repo branch to use is wii3, though it also has information to use a wii controller as a pendant. That one has the Services folder with the sh files to start and stop the services and the updated main.py. I have been working on a newer branch that doesn’t use a service. It spawns the process and kills it from within webcontrol and doesn’t have the bluetooth connection to the wii controller. It is the external button and LED branch and that one is mostly working as well. I was hung up on some of the web interface for configuring the LED and I think it works, but have not fully tested it. I just got my extra buttons and LED put on my spare rpi for this while it also hosts octoprint for my 3d printer.


Thanks for the quick reply Orob. So, I could just make another service that runs a shell script calling main.py and than the button service should be able to start after?

I should grab the main.py for the same build as the wii3?

Thanks again

Exactly. Have the service call python3 main.py from the folder. The only part that was time consuming to set up was the development dependencies so everything would work since you won’t be running from the bundled distribution. It is easiest to git clone the branch. The maslowbutton.py file needs to be placed in /use/etc. There should be a note in the services folder on that. You should have a few extra options pop up in maslow settings. Make sure the cli and pendant options stay off, but you need to enable the button service one or it won’t work as it should.

Thanks, got it going. Bit of a learning curve with flask and the virtual environment.

Two follow on questions. Did you happen to find LED buttons that are 3V? Or did you have to rig up something more complicated?

You mention leaving CLI and Pendant off? Any reason? I was thinking of hooking up my wii remote as well and know what would need the pendant service.

The cli is a command line interface display that I have on my system I didn’t think anyone else would have.

LED buttons: My buttons are not backlit. The LED’s I’m using are separate and used only as indication for system state. I’ve attached a simple schematic of my LED and button setup. The LED is a single tri-color LED with 300k resistors on each of the color lines. The RPI provides the power and ground. The circuits are very simple and in the drawing below I did not include the resistors, but they would be on the red/blue/green lines.

The Pendant: In my case, the pendant is ONLY activated from a button press. Press the pendant button, then press the wii remote buttons and it will pair. Pressing the A and B buttons together will turn off the remote and is supposed to kill the pendant thread. Press the pendant button again and turn on the remote again by pressing any button. If you turn off the wii controller with the power button, the pendant thread will stay live on he raspberry pi. If you do that too much, you can have memory issues with too many threads running, so just be aware. Note: this is not a polished release, so you will find that the SET HOME function does not work, but the zero Z function does.

Here is a quick listing of button combinations for the wii control pendant.

All directions assume you are holding the control like a classic NES controller (sideways q/buttons on the right)
1 and up (move up)
1 and down (move down)
1 and left (move left)
1 and right (move right)
home - move home
1 and home - set home (DOES NOT WORK… saves coordinates off screen)

2 and up (z axis retract)
2 and down (z axis plunge)
2 and home (z axis set zero)

B (trigger on back side)
B and up (play - start loaded cut)
B and left (pause)
B and down (stop cut / cancel)
B and A (turn off remote and stop pendant service)

after getting the pendant to work, I now only use it to move the sled out of the way when I’m on my phone. Usually I use the phone more than the pendant, so with the buttons for emergency pause or stop on the rpi and the display (I need to add a current gcode line number to the display) I find the pendant was a nice show and tell piece, but not really needed. I was working on a pull request for the webcontrol code that would start stop a separate process without the services and with only buttons so everyone could use it. My script fu is expanding, but I’m not confident it is ready for prime time yet. Please provide any comments or suggestions on improvement. I think it would be great if you get some use out of the time spent getting it to work.

1 Like

Hey Orob, just wanted to say thanks. I ended up getting it all working. LED Buttons, Wii remote with bluetooth pendant button.

Working on adding a smoke detector that will trigger a GPIO to shutdown the system, or maybe have a shell script polling the detector to text me.

That is great!! You are very welcome. I’m happy you were able to follow the breadcrumbs I left behind. Was getting the pi set up for development very difficult? I found that to be the frustrating part, but once all the dependencies are set up, it just works and is fairly easy to customize.

As far as the smoke detector shutdown option, you can use GPIO 6 or 5 and the code already in there if you select “shutdown” in the GPIO setup menu to assign the button. Have your smoke detector make the contact between the GPIO pin and ground and the pi will shut down. I just use a regular button, though you could put a regular button and the smoke detector in parallel so either would trigger it for normal or emergency shutdown.

1 Like

Have you tried to home the sled with the wii remote? That is a bug that needs to be addressed if you feel so inclined. I think the sled movement distances need to changed as well. instead of .1, 1, 10, 100, it should be 300, 100, 10, 5 so it is closer to roughly 1/4, 1/2, 4 and 12 inches. Did the z axis zero work for you?

Sorry for the long delay in response, i’ve been preoccupied with work and yet another side project. As you mentioned, I was thinking of hooking up the smoke detector as you suggested, but decided to have a shell/python scripts run in the background to poll the GPIO status and email/text me before initiating a shutdown. Should be a quick script but I have yet to get around to it.

As a small suggestion, it would be nice if you could assign GPIO buttons to run scripts. For example, poll a folder for .py or .sh scripts and allow you to pick them from the drop down when mapping to GPIO. Would make it easier for the non programmer. -of course, we are all crunched for time.

I didn’t try the home function with the wii remote, as you mentioned, the performance takes a hit when I run the pendant service, so I don’t run it often. I use it mostly to show folks, or for the Z axis, though I just started doing the z probe mod for auto-homing. That said, when I show it to folks, the Wii remote causes their heads to explode :slight_smile:

When I get sometime I will jump back in and update you. Trying to learn docker at the moment.

1 Like

I’m shipping smoke detectors with a 5v signal with every kit till we run out. Also got a device with IR sensor a while ago. I figured before there would be smoke the router bit would heat up and it would be a better pre warning indicator than a smoke alarm. send me a pm with address and I can mail you them if you are interested.

1 Like

running scripts from buttons is totally possible. It would go into the MaslowButton.py file which then populates the gpio list in the webcontrol page. Long story short, I had an update from a different branch that had a ton more options minus some functionality that I decided would be good to put back in the branch you are using and so I started merging them and it isn’t quite finished and then the beta makerverse just came out so I’m trying to test that and build a second system and try out a new motor shield and my new metal sled and so yeah it is a time thing. The wii remote is a cool show and tell piece. The latest add with the start/stop/pause function on it makes it so I used it all the time now. When cutting, I have the wiimote connected and in my pocket so I can grab it and stop it easily with out walking over next to it as long as I’m in bluetooth range the wiimote does not go to sleep when it is connected. The required 2 button press to activate makes it so nothing gets accidentally changed. It was nice for me to find out that the makerverse communicates over the socket similarly to webcontrol so with some minor mods, the maslowbutton pendant file may be portable to the new system to some degree, so that will be cool and with the latest makerverse update, it works (in a limited manner for me so far) with all maslows systems now including the ones with the mega that most of us have.