RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
MaxRPM reset button
Author Message
Reply with quote
Post MaxRPM reset button 
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

View user's profile Send private message
Reply with quote
Post  
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

View user's profile Send private message
Reply with quote
Post  
Did this end up working?


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
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.

View user's profile Send private message
Reply with quote
Post  
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.


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
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

View user's profile Send private message
Reply with quote
Post  
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.


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
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

View user's profile Send private message
Reply with quote
Post  
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/RaceCapturePro_Lua_Scripting#Troubleshooting


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
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

View user's profile Send private message
Reply with quote
Post  
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.

View user's profile Send private message
Reply with quote
Post  
Hey, that works great, nice job!

Can we add that to the list of sample Lua scripts?

View user's profile Send private message Send e-mail
Reply with quote
Post  
absolutely! Thanks.

View user's profile Send private message
Reply with quote
Post  
Thanks, added to the wiki and also shared here: https://www.facebook.com/groups/1288770887817789/permalink/2386022761425924/


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum