Page 1 of 1
MaxRPM reset button
Posted: Mon Sep 17, 2018 3:37 pm
by PS14
Could someone help me with some code to add to the MaxRPM code. i'd like to use a GPIO channel connected to ground or 5v (whichever's easiest) thru a momentary button that will reset the MaxRPM channel back to zero. like the memory button on a tach. heres my best guess below. thanks, Dave.
setTickRate(10)
maxRpmId = addChannel("MaxRPM", 10)
maxRpm = 0
-- Gpio(0) set to input mode
-- momemtary button connected to 5v
function onTick()
local rpm = getTimerRpm(0)
if rpm > maxRpm then
maxRpm = rpm
setChannel(maxRpmId, maxRpm)
if getGpio(0) = 1 then
setChannel(maxRpmId, 0)
end
end
Posted: Fri Sep 21, 2018 3:32 pm
by PS14
Well, that code failed, so i'm gonna try this next. my scripting abilities suck.
maxRpmId = addChannel("MaxRPM", 10)
maxRpm = 0
function rpmReset()
local rpm = getTimerRpm(0)
local clear = getGpio(0)
if rpm > maxRpm then
maxRpm = rpm
setChannel(maxRpmId, maxRpm)
end
if clear == 0 then
maxRpm = 0
setChannel(maxRpmId, maxRpm)
end
end
Posted: Sat Nov 24, 2018 11:07 pm
by brentp
Did this end up working?
Posted: Sun Nov 25, 2018 6:59 pm
by PS14
unfortunately no, i'm having issues reading the gpio state. i have gpio(2) connected to mk2 ground through a pushbutton, channel set to output. but on the dash the channel reads zero even if i push the button. none of the gpio channels seem to read "1" when pushbutton held down.
Posted: Sun Nov 25, 2018 7:06 pm
by brentp
Hi, try wiring a pullup resistor to Vref so that the input sees a 'high' value when the button is not pressed. a 1K-100K resistor should be fine. Power rating not important.
Posted: Sun Nov 25, 2018 8:04 pm
by PS14
that fixed it. now the next problem. when its reset to zero, it wont display a maxrpm until it exceeds that last "maxrpm" value. like it has a memory that needs to be reset. heres the code im using. i have a potentiometer im using to simulate rpm during bench testing.
maxRpmId = addChannel("MaxRPM", 10, 2)
MaxRpm = 0
function rpmReset()
local rpm = getAnalog(6)
if rpm > MaxRpm then
MaxRpm = rpm
setChannel(maxRpmId, MaxRpm)
end
local clear = getGpio(0)
if getGpio(0) == 0 then
setChannel(maxRpmId, 0)
end
end
function onTick()
rpmReset()
end
Posted: Sun Nov 25, 2018 8:11 pm
by brentp
You have a local variable called 'clear' that's not being used.
Try proving that the if block is working by putting a println() statement in there that outputs something to the debug window.
Posted: Sun Nov 25, 2018 8:28 pm
by PS14
my bad, that was from original (see below). works either way, just does't start over when "reset". dont sweat it, i got until April to sort it out.
local clear = getGpio(0)
if clear == 0 then
maxRpm = 0
setChannel(maxRpmId, maxRpm)
end
Posted: Sun Nov 25, 2018 8:30 pm
by brentp
Great, sounds like you're on your way.
This is a cool use of Lua scripting we didn't originally consider, nice job.
Fyi, we just expanded the troubleshooting section here, might be helpful as you go forward:
https://wiki.autosportlabs.com/RaceCapt ... leshooting
Posted: Sun Nov 25, 2018 8:40 pm
by PS14
you got me thinking, so i went back to the original script you asked about. slapped it in and it works exactly as planned. when you push reset button, it zeros and instantly reads current value. i don't know how i did it but it works! small miracles. thanks for the support, you and your team rock. happy holidays. Dave in NY.
ill post a video in a few minutes, as well as the code referencing the timer channel for anyone else whom might like to reset maxrpm during a caution lap.
maxRpmId = addChannel("MaxRPM", 10, 2)
maxRpm = 0
function rpmReset()
local rpm = getAnalog(6)
local clear = getGpio(0)
if rpm > maxRpm then
maxRpm = rpm
setChannel(maxRpmId, maxRpm)
end
if clear == 0 then
maxRpm = 0
setChannel(maxRpmId, maxRpm)
end
end
function onTick()
rpmReset()
end
Posted: Sun Nov 25, 2018 9:06 pm
by PS14
Heres a link to my youtube page with a short video of the Rpm Reset button code in action.
https://youtu.be/ernEa37stWs
Heres the code:
maxRpmId = addChannel("MaxRPM", 10)
maxRpm = 0
function rpmReset()
local rpm = getTimerRpm(0)
local clear = getGpio(0)
if rpm > maxRpm then
maxRpm = rpm
setChannel(maxRpmId, maxRpm)
end
if clear == 0 then
maxRpm = 0
setChannel(maxRpmId, maxRpm)
end
end
function onTick()
rpmReset()
end
notes: i had to add a 100K pulldown resistor across the GPIO(0) and 5v inputs.
Posted: Sun Nov 25, 2018 9:50 pm
by brentp
Hey, that works great, nice job!
Can we add that to the list of sample Lua scripts?
Posted: Mon Nov 26, 2018 12:42 pm
by PS14
absolutely! Thanks.
Posted: Mon Nov 26, 2018 2:46 pm
by brentp