Webcontrol pendant software -tie- in - > entry point for external data in the code?

I have a wiimote and a raspberry pi. The raspberry pi is now programmatically taking button inputs in python from the wiimote via the bluetooth that is included on the raspberry pi 3.

The question:

What might be the best approach to integrate this in webcontrol… start a thread that runs the listener code and then insert a message in the queue? A new button or a macro button could be assigned to activate the bluetooth and search for the controller. You then push the buttons on the controller and it will connect to the pi - i have it rumble when it is connected. I haven’t gotten the light totally figured out or the buttons completely sorted, but it will get there.

1 Like

I think a thread that processes the inputs from the controller seems reasonable. Once the input is received, I’d just call self.data.actions.processAction() with a suitably formatted json. The thread should be created in nonvisiblewidgets so it has access to the “data” class. Make sure to sleep the thread so it isn’t blocking.

2 Likes

I’ll see what I can do. I’m using a second pi to test this with the pyinstaller version of webcontrol. Once I think I have it working, who else would be willing to test it?

Status update. I’m not a fan of the shotgun approach that is modern software engineering, but this is my attempt to conform. I have not gotten it to run yet and there are many many parts I don’t fully understand, but have in place simply copying other functions that do work. Thoughts?

setting in settings/settings.py

       {
       "type": "bool",
        "title": "wiimote Pendant installed",
        "desc": "Does the machine have a bluetooth wii remote pendant?",
        "key": "wiiPendantPresent",
        "default": 0,
        },

Flag in DataStructures/data.py (just below manual ZAxisAdjust):

wiiPendantPresent = False

Pointer to the wiiPendant object in DataStructures/data.py (just below boardManager):

wiiPendant = None

import in nonVisibleWidgets.py:

from wiiPendant import WiiPendant

added object instance in NonVisibleWidgets class:

wiiPendant = WiiPendant()

added setupData lines also in nonVisibleWidgets:

data.wiiPendant = self.wiiPendant
.
.
.
self.wiiPendant.setUpData(data)
self.wiiPendant.setup()

wiiPendant.py file has 2 variables:

wiiPendantRequest = “”
wm = None #controller object

wiiPendant.py file has the following open connection routine:

Code:

def openConnection(self):
‘’’
if the wiiPendantFlag in the config is True, then check if the wiiPendant is already connected
if not connected, then set t
‘’’
if self.data.wiiPendantPresent:
if not self.data.wiiPendantConnected:
if self.wm == None:
while not self.wm:
try:
self.wm=cwiid.Wiimote()
self.wm.rumble=True
time.sleep(.3)
self.wm.rumble = False
time.sleep(0.2)
self.wm.rumble=True
time.sleep(.3)
self.wm.rumble = False
x = wiiPendantThread()
x.data = self.data
self.th = threading.Thread(target=x.readbuttons)
self.th.daemon = True
self.th.start()
except RuntimeError:
‘’’
this is a silent fail if the wiimote is not there… should set something to know that it isn’t th$
‘’’
else:
self.data.ui_queue1.put(“Action”, “connectionStatus”,{‘status’: ‘True’})

I don’t know if the init routine of the self.wm=cwiid.Wiimote() line is blocking and I’m wondering if a button should be put in for turning on the pairing rather than having it scheduled for every 5 seconds similar to the serial port. If it fails silently, probably no big deal… if it blocks every 5 seconds, HUGE problem.

It’s hard for me to tell… do you use github? If you forked my repo and made the changes to it, I could readily view it and see what’s going on.

Forked and added. It is the wiiPendant fork. Development version not yet running correctly on the raspberry pi, so I don’t know if the wiiPendantThread is set up correctly yet.

Update: I have this working and have been using it for some time now. Just yesterday based on a discussion with @Arnd earlier this week that I took as a challenge, I added a router spindle relay to the arduino. Since I had the controller apart, I also fixed a broken ground wire for the status LED so now my raspberry pi responds to button presses and displays a tricolor changing LED that is configurable in webcontrol to indicate its status.

Picture:
before cleanup and reinstall:


In operation. LED above display is blue in standby and green flashing when sled is running.

the LED is adjusted or changed in webcontrol->settings->GPIO settings

Because the display takes up most of the GPIO on the rpi, only pins 5, 6, 13, 19, 26, 12, 16, 20, 21 are exposed for buttons and for LED. Currently, there is one pin remaining that could be used with the way the controller is wired.

If anyone wants to try out putting buttons in their controller, it is possible with a little effort. I also have access to the laser to make the acrylic faceplates, and I can get you a custom one at a reasonable cost (message me).

4 Likes

Hi,

so the spindle-relay needs to be connected directly to the Arduino board and not to AUX1 on the motor controller? But you can confirm that the spindle control of Webcontrol works? I could not get it working with my relay. I did try all available spindle options and the cabling had been correct.

the Aux 1 pin is on top of the motor shield which is a pin brought up from the arduino board:


I used this relay instead of what you have:

Your relay will not require 5V to power it, you just need the ground for reference and the Aux1 pin (labelled GPIO on the board) that does the toggle. That is the electrical. Next is the software side. For the software to turn on the relay, you must have an M3 or M4 at the start of your gcode and an M5 at the end to turn it off.

I looked at the source code to understand the actions of the webcontrol button and it stores the value in defaultwebcontrol.json file under the spindleAutomate key (also in Settings.py). This spindleAutomate key is called up when the firmwareSync button is pressed and it sends the value to the arduino. Looking at the arduino firmware starting at line 39, there is a spindleAutomateType that is either Servo, or Active High, or Active Low. Servo is if you have speed control or a servo motor flipping the switch (I am guessing). Active High is if your relay needs a 5V signal to activate, and active Low is if your relay needs a ground signal to activate. It would be best to set this to ACTIVE HIGH, and then connect the aux-gpio pin to your IOT relay and connect the relay ground to the shield ground pin. Then submit the changes in webcontrol and restart webcontrol. It probably would not hurt to restart the arduino, but when the rpi connects, it will reset. I hope this helps and that it works for you.

servo is servo flipping a switch, still only on/off

1 Like

Thank you, i do have the TLE5206 motor control board (coming with the metal maslow kit) and i did try use the connector labeled AUX1 but to no avail. Can anyone confirm that a relay connected to this AUX1 port on the TLE5206 will work?

thanx

you can test it with gcode and an LED.


Connect the LED to aux 1 and a resistor, with the resistor to ground, then when you send the M3 command the LED should turn on. M5 should turn it off. If that doesn’t work, then something is up with your arduino board. All the Maslow firmware has this functionality coded in.

Once you verify the LED works, then hook up your relay to aux 1 and ground. You only need to use the 5V pin if your relay coil needs power like the one I used above.

I should able to determine this with my voltmeter too, right?

yes. Aux 1 pin compared to ground should be 0 V when off and ~5 V when on.

I did measure the AUX1 on the motor controler board (TLE5206) coming with metal maslow today.

The boards AUX1 port works correctly with M3 (start spindle) / M5 (stop spindle) commands. When configuring spindle control for “relay_high” 5V are on after M3 is issued/withdrawn after M5 is issued. When using “relay_low” 5V are “always” on and when “M3” is issued it goes to 0V. After M5 the 5V come back.

The power relay coming with the metal maslow did not work in any combination but my IOT relay works fine with it.

iot-relay

I have a working auto-spindle now :slight_smile:

Software beein used had been WebControl not Groundcontrol but one should see the same results with Groundcontrol.

2 Likes

!!! glad to hear you got it working !!!

Sorry if i am “off-topic”. Anyone knows how long the cable from the aux port to the relay can be? I need at least 1.5m of cable.

That will probably be fine. Try it and see.