Mercedes AMG Power Wheeler: Difference between revisions
Jump to navigation
Jump to search
m →Code |
m →Code |
||
| Line 20: | Line 20: | ||
=== Code === | === Code === | ||
relay1 = 0 | -- relay 1 input | ||
relay2 = 0 | gpio.mode(6, gpio.INPUT, gpio.PULLUP ) | ||
-- relay 2 input | |||
function toggle_output_pwm() | gpio.mode(7, gpio.INPUT, gpio.PULLUP ) | ||
-- power switch control output | |||
gpio.mode(1, gpio.OUTPUT ) | |||
gpio.write(1, gpio.LOW) | -- relay 1 ouput | ||
end | gpio.mode(2, gpio.OUTPUT ) | ||
-- relay 2 ouput | |||
function | gpio.mode(5, gpio.OUTPUT ) | ||
relay1 = 0 | |||
relay2 = 0 | |||
function toggle_output_pwm() | |||
gpio.write(1, gpio.HIGH) | |||
tmr.delay(10000) | |||
gpio.write(1, gpio.LOW) | |||
end | |||
function deactivate_pwm_output() | |||
val = adc.read(0) | |||
if val > 10 then | |||
print("Output is active:", val) | |||
toggle_output_pwm() | |||
val = adc.read(0) | |||
print("Output is deactivated:", val) | |||
end | |||
end | |||
function activate_pwm_output() | |||
val = adc.read(0) | |||
if val < 10 then | |||
print("Output is deactivated:", val) | |||
toggle_output_pwm() | |||
val = adc.read(0) | |||
print("Output is activated:", val) | |||
end | |||
end | |||
function on_success_callback() | |||
val = adc.read(0) | |||
if val < 10 then | |||
print("System voltage low (mV):", val) | |||
else | |||
print("System voltage high (mv):", val) | |||
end | |||
end | |||
function check_relay1_input() | |||
relay1_input = gpio.read(6) -- gpio12 | |||
relay2_input = gpio.read(7) -- gpio13 | |||
print("Status relay 1:", relay1_input) | |||
print("Status relay 2:", relay2_input) | |||
if relay1_input == 0 then | |||
-- trigger output low | |||
if relay1 == 0 then | |||
deactivate_pwm_output() | |||
end | |||
-- activate relay 1 | |||
relay1 = 1 | |||
gpio.write(2, gpio.HIGH) | |||
activate_pwm_output() | |||
elseif relay2_input == 0 then | |||
-- trigger output low | |||
if relay2 == 0 then | |||
deactivate_pwm_output() | |||
end | |||
-- activate relay 1 | |||
relay2 = 1 | |||
gpio.write(5, gpio.HIGH) | |||
activate_pwm_output() | |||
else | |||
-- trigger output low | |||
deactivate_pwm_output() | |||
-- activate relay 1 | |||
relay1 = 0 | |||
relay2 = 0 | |||
gpio.write(2, gpio.LOW) | |||
gpio.write(5, gpio.LOW) | |||
end | |||
end | |||
function check_relay2_input() | |||
end | |||
-- if the output is active deactivate it | |||
val = adc.read(0) | val = adc.read(0) | ||
if val > 10 then | if val > 10 then | ||
| Line 49: | Line 116: | ||
print("Output is deactivated:", val) | print("Output is deactivated:", val) | ||
end | end | ||
mytimer = tmr.create() | |||
mytimer:register(10000, tmr.ALARM_AUTO, on_success_callback) | |||
mytimer:interval(500) -- actually, 500 mseconds is better! | |||
mytimer:start() | |||
mytimer1 = tmr.create() | |||
mytimer1:register(10000, tmr.ALARM_AUTO, check_relay1_input) | |||
mytimer1:interval(500) -- actually, 500 mseconds is better! | |||
mytimer1:start() | |||
mytimer2 = tmr.create() | |||
mytimer2:register(10000, tmr.ALARM_AUTO, check_relay2_input) | |||
mytimer2:interval(500) -- actually, 500 mseconds is better! | |||
mytimer2:start() | |||
{| class="wikitable" | {| class="wikitable" | ||
Revision as of 19:07, 1 June 2021
| Mercedes AMG Power Wheeler |
|
| https://bogza.ro/index.php/Mercedes_AMG_Power_Wheeler | |



Power upgrade =

- Current consumtion nominal: 2A
Controller upgrade
Tachometer install
- red - 12V
- green signal wire 3000rpm = 6.23Hz 10V offset 5V duty 20% range = 3.9Hz - 6.7hz
- black - gnd
- yellow - 12v

Code
-- relay 1 input
gpio.mode(6, gpio.INPUT, gpio.PULLUP )
-- relay 2 input
gpio.mode(7, gpio.INPUT, gpio.PULLUP )
-- power switch control output
gpio.mode(1, gpio.OUTPUT )
-- relay 1 ouput
gpio.mode(2, gpio.OUTPUT )
-- relay 2 ouput
gpio.mode(5, gpio.OUTPUT )
relay1 = 0
relay2 = 0
function toggle_output_pwm()
gpio.write(1, gpio.HIGH)
tmr.delay(10000)
gpio.write(1, gpio.LOW)
end
function deactivate_pwm_output()
val = adc.read(0)
if val > 10 then
print("Output is active:", val)
toggle_output_pwm()
val = adc.read(0)
print("Output is deactivated:", val)
end
end
function activate_pwm_output()
val = adc.read(0)
if val < 10 then
print("Output is deactivated:", val)
toggle_output_pwm()
val = adc.read(0)
print("Output is activated:", val)
end
end
function on_success_callback()
val = adc.read(0)
if val < 10 then
print("System voltage low (mV):", val)
else
print("System voltage high (mv):", val)
end
end
function check_relay1_input()
relay1_input = gpio.read(6) -- gpio12
relay2_input = gpio.read(7) -- gpio13
print("Status relay 1:", relay1_input)
print("Status relay 2:", relay2_input)
if relay1_input == 0 then
-- trigger output low
if relay1 == 0 then
deactivate_pwm_output()
end
-- activate relay 1
relay1 = 1
gpio.write(2, gpio.HIGH)
activate_pwm_output()
elseif relay2_input == 0 then
-- trigger output low
if relay2 == 0 then
deactivate_pwm_output()
end
-- activate relay 1
relay2 = 1
gpio.write(5, gpio.HIGH)
activate_pwm_output()
else
-- trigger output low
deactivate_pwm_output()
-- activate relay 1
relay1 = 0
relay2 = 0
gpio.write(2, gpio.LOW)
gpio.write(5, gpio.LOW)
end
end
function check_relay2_input()
end
-- if the output is active deactivate it
val = adc.read(0)
if val > 10 then
print("Output is active:", val)
toggle_output_pwm()
val = adc.read(0)
print("Output is deactivated:", val)
end
mytimer = tmr.create()
mytimer:register(10000, tmr.ALARM_AUTO, on_success_callback)
mytimer:interval(500) -- actually, 500 mseconds is better!
mytimer:start()
mytimer1 = tmr.create()
mytimer1:register(10000, tmr.ALARM_AUTO, check_relay1_input)
mytimer1:interval(500) -- actually, 500 mseconds is better!
mytimer1:start()
mytimer2 = tmr.create()
mytimer2:register(10000, tmr.ALARM_AUTO, check_relay2_input)
mytimer2:interval(500) -- actually, 500 mseconds is better!
mytimer2:start()

