Simulation Rig Control System (1 Viewer)

Bassetts

Well-Known Member
Community Member
Joined
Sep 16, 2016
Messages
399
Reaction score
215
Productive 30 mins this afternoon :)

import time,json,argparse
from MCP23017_I2C import *

#######################################
# Setup Arguments and Parse
#######################################
parser = argparse.ArgumentParser()
parser.add_argument("--R0", help="Set state of Relay 0",choices=['on', 'off'])
parser.add_argument("--R1", help="Set state of Relay 1",choices=['on', 'off'])
parser.add_argument("--R2", help="Set state of Relay 2",choices=['on', 'off'])
parser.add_argument("--R3", help="Set state of Relay 3",choices=['on', 'off'])
args = parser.parse_args()
if args.R0:
print("Set Relay 0 to {}".format(args.R0))
if args.R1:
print("Set Relay 1 to {}".format(args.R1))
if args.R2:
print("Set Relay 2 to {}".format(args.R2))
if args.R3:
print("Set Relay 3 to {}".format(args.R3))

#######################################
# Read JSON File Containing States
#######################################
with open('relay.states','r') as infile:
D = json.load(infile)
globals().update(D)

#######################################
# Set Relay States From Args
#######################################
if args.R0 == 'on':
relay_0_state = 1
if args.R1 == 'on':
relay_1_state = 1
if args.R2 == 'on':
relay_2_state = 1
if args.R3 == 'on':
relay_3_state = 1

if args.R0 == 'off':
relay_0_state = 0
if args.R1 == 'off':
relay_1_state = 0
if args.R2 == 'off':
relay_2_state = 0
if args.R3 == 'off':
relay_3_state = 0

#######################################
# Write JSON File Containing States
#######################################
vars={} # the dictionary we will save.
vars['relay_0_state'] = relay_0_state
vars['relay_1_state'] = relay_1_state
vars['relay_2_state'] = relay_2_state
vars['relay_3_state'] = relay_3_state

with open('relay.states','w') as myfile:
json.dump(vars,myfile,indent=2)

#######################################
# Set Relay States
#######################################
GPIO_CHIP_1 = GPIO_CHIP(0x20, 1) # define chip MCP23017_I2C
GPIO_CHIP_1.output(0, relay_0_state, 'A')
GPIO_CHIP_1.output(1, relay_1_state, 'A')
GPIO_CHIP_1.output(2, relay_2_state, 'A')
GPIO_CHIP_1.output(3, relay_3_state, 'A')
 

Bassetts

Well-Known Member
Community Member
Joined
Sep 16, 2016
Messages
399
Reaction score
215
Well, the project is nearly complete now. The alpha and beta testing has been conducted and i'm just making some updates after some good lessons learned before this gets into release candidate stage, so I thought now would be as good a time as any to update and expand on this project a little. ;)

One of my normal "challenges" many of you will have heard over teamspeak is "Oh **** I've forgotten to turn everything on " after getting into the rig and putting the VR headset on, This then results in having to take everything off, get out of the rig turn items on and then get back in.

So I decided to "Bassetts" a solution (can I trademark that saying ? )

There were 4 key devices that I wanted to be able to control the power to from whilst inside the rig.

1. Audio Amplifier for the tactile transducers.
2. Direct Drive Wheel & controller.
3. Air intake duct - (For bringing in cool air from outside into the room.)
4. Fan - (to keep things under control when in the rift running long sessions)

The idea here was to use an IoT device (Raspberry Pi in this instance) to act as a control interface to allow the power to these devices to be turned on and off via the use of relays.

Below is a bit of an explanation of the key elements of the project and how the project is constructed.

The actual switching of the mains is handled via a commonly used 4 Channel Relay Board, this allows the 4 channels to be turned on and off independently via a control pin on the module, here we can switch up to 10A @ 240V per channel (there is a caveat here, but i'll touch on that later)

To allow this control to be done remotely/programatically the board needs to be connected to some form of processing unit to control the switching of the inputs. Here I turned to the Raspberry PI Zero, these can purchased for less than £10 and are a great way to easily interface with electronics components, also I had a couple lying around from some other projects I was looking at a while ago.

The PI Zero's can now be purchased with Wi-Fi built in, but my units didn't have these onboard and also WiFi is a bit patchy in the garage, so I sourced an SPI Ethernet Module for the Raspberry PI to provide a robust network connection. - Usage Example

Although the Raspberry PI devices come with a set of header pins (GPIO) that can be used to directly control things, I wanted a method of connecting to the control interfaces to the relay board that was scale-able, so instead of using the general GPIO pins on the Raspberry I opted to using the i2c bus which allows multiple port expanders to be used to provide more switching control if needed.

The port expanders here are MCP23017 IC's, these IC's also serve a second purpose as in the default configuration when power is applied to the system the relay channels move to the on position turning everything on by default, where the desired operation is to be off by default and turned on via selection/program. Although we could handle this via the GPO pins and negating the outputs by adding the MCP23017 into the flow, we can change the behaviour so when the power is provided to the system the channels do not activate in a uncontrolled manner and it also saves the need to additional electronics for negating the outputs. - Usage Example

So once all these are connected the Raspberry Pi can be programmed to turn on and off the devices.

Here we use some python code (original post) to handle the control via a small command. We invoke this via remote command (SSH) to operate relays on an individual basis as required. These remote commands can then be mapped to a script or as I have have done via my button box and Digital Race Engineer/VoiceAttack applications to start up the Amp, DD Wheel and fans based on launching the game or via buttons within the button box.

The initial testing worked great, everything switched as expected, however when connecting the actual loads to the relays I hit a small issue. One problem with relays is that when closing them if the current being pulled through them is higher than the rated maximum then the arc caused during process of closing the relay actually cause the contacts inside to weld/fuse closed. This stops the relay from then opening and closing again. Although all the devices were lower than the rated 10A, this rating is based on the normal operating current and not the initial in rush current that the device can hit when it initially turns on.

Devices like motors and amplifiers are prime examples of this and the first time the amp turned on, the relay fused and I was then unable to turn it off via the relay board as it had welded the contacts closed. Unfortunately you can't purchase multi channel boards easily that have a current rating above 10A so here I had to improvise and actually used a larger relay that support up to 250V @ 30A in series to the one on the board to handle the actual switching of the load. Here the relay board uses a small current to active the larger relay which actually activates the power for the device.

All is now working great, but the larger current relays are a little big so I've got to re-locate to a larger project box, so i'll post a final update once that's all in place and it's in it's final state.

Here you can see the 4 Channel relay module that physically switches the mains inputs.

File_007.jpeg


And here we have the interface logic, raspberry pi and Ethernet module.

File_008.jpeg
 
Last edited:

2scoops

RSR Family
Community Member
Joined
Sep 17, 2016
Messages
1,041
Reaction score
286
You are a wizard with electronics, very interesting, though it may as well have been written in Chinese because it just went way over my head. :) You should market it
 

Tom

Moderator
Staff
#TeamRSR
Joined
Sep 16, 2016
Messages
2,332
Reaction score
2,775
Brilliant stuff yet again, funny issue with the relays welding themselves closed there :p This looked like a fun little project. I've been thinking of getting an Arduino or something to play about with, but I'm not sure what to I'd do with it. Maybe a variable fan controller mapped to car speed for open wheel cars, for a bit of wind in the hair.
 

Bassetts

Well-Known Member
Community Member
Joined
Sep 16, 2016
Messages
399
Reaction score
215
I found the raspberry pi alot easier to get into, and you can pick up a Pi Zero with wireless now for £10.

Had to get a bigger box to mount the large relays in (bottom left), just need to tidy the cables and drill some holes for the Ethernet & USB socket, and then I can be closed up.

Already works a treat, no more getting out of the rig :)

File_010.jpeg
 

Users who are viewing this thread

Top