loading

I need help with coding a car cruisecontrol and Arduino Leonardo (HID)?

Hi all, I have a challenge I cant solve, I need your help!

I have a car cruise control lever I want to connect to an Arduino Leonardo and have it act like a keyboard (HID).

It has only two wires, 3 push buttons and one toggle switch. I do know the input voltage is 5 volt and every button has its own resistor causing different voltages to come out when used. This way the car computer knows what has been pressed.

I have 3 switches:

1: Acc (Cruise Control Accelerate speed)
2: Ret (Cruise Control Retrieve speed)
3: Res (Cruise Control Resume from last speed)

I have one toggle Switch:

Cruisecontrol ON/OFF

I want the ON/OFF to toggle a keyboard character "C" when used.
I want button 1 to send a "7"
I want button 2 to send an "8"
I want button 3 to send a "9"

The code should pause after each change (no loop). The 10k Restistor is a pull-up resistor for debounce.

Anyone?

Project: https://hackaday.io/project/8448-real-dashboard-truck-simulator

Picture of I need help with coding a car cruisecontrol and Arduino Leonardo (HID)?
Board1.png
Board2.png
sort by: active | newest | oldest

You need to use an analog input then. "Debouncing" doesn't happen by adding a resistor at random.

Your Cruise switch has only two output wires ? Correct ? You will need to feed it FROM a resistor to the 5V supply, connecting the other to ground. Measure the voltage between the end of the resistor and the ground line. It should vary as the buttons are pressed.

Steve

Jeroenv26 (author)  steveastrouk1 year ago

Thanks for your help! You mean, like this:

Board3.pngBoard4.png

Close ;-) Try this.

Cruise controller.jpg
Jeroenv26 (author)  steveastrouk1 year ago

Like this:

Board5.pngBoard6.png

Yes.

Jeroenv26 (author)  steveastrouk1 year ago

Ok, and do you also know code to get my stuff going?

PS. Start with a minimal program that reads the A/D and prints a value to the screen 2 times a second.

Jeroenv26 (author)  steveastrouk1 year ago

Here is a start I made. It is a mix of the Arduino Ohm Meter Tutorial and my own Scania Retarder code. tinyurl.com/ho2me6w

I guess it needs booleaans and if/eleses and stuf to get keyboardprints and no-loop.

Get the naked button press values, and post them.

acc= ?

res=?

etc, don't bother with the combinations.

There is a trick you can do to read the results easier.

Jeroenv26 (author)  steveastrouk1 year ago

here they are:

Vout:

OFF =
4.30v

ON =
4.68v

ON RET =
4.83v

ON RES =
4.92v

ON ACC = 4.97v

Val
= volts x 1023 / 5 = :

OFF =
880

ON =
958

ON RET =
988

ON RES =
1007

ON ACC = 1017

Average
VAL:

OFF (880-0)
/ 2 + 0 = 440

ON (958-880)
/ 2 + 880 = 919

ON RET
(988-958) / 2 + 958 = 973

ON RES (1007-988) / 2 + 988 = 998

ON ACC (1017
– 1007) / 2 + 1007 = 1012

Check your PMs and ignore my last comment about doing On+RES etc ;-)

When you say "on average", are they fluctuating much ?

Yes, but I don't generally write other people's code for them. Start out with a standard Leonardo keyboard program. Instead of keypresses, read the A/D converter. Measure the output and record that for each switch position, then when a key is pressed, and the A/D output changes, convert the level into the appropriate keypress for the rest of the keyboard program.

You shouldn't have to write much code.


Steve

I would say post it as an Instructable here instead of asking for advise on project you publish elsewhere ;)

Jeroenv26 (author)  Downunder35m1 year ago

I didn't wanted to spam the indestructibles website with an unfinished project. I will post all of my individual steps once finished on this website ;)