So if you have read up to here you have been following my journey in and around my
MY2009 Volvo XC90 car, my Arduino, my (appalling) coding skills, and seen some of the highs I achieved and the lows that I faced.
On the weekend just passed I actually had some great successes in that I had my first Arduino code properly doing what it should.
If you were there you would have heard me whoop for joy, throw my hands up in the air and do a little victory dance behind my car. Lucky the garage door was closed....
My First Volvo App: Lights On Ding
I identified this app as my first app to get something going.
You have to walk before you can run. Start small, grow big.
A concrete goal. Not too complex.
The Goal
Sound the vehicle gong, light the yellow warning triangle on the instrument cluster (the DIM), and ideally also show some text such as LIGHTS! when I have the ignition key out, and the drivers door open, and the lights on to PARK.
Reason: sometimes I set my lamps to PARK in the garage to turn off my headlamps, and then forget they are on, lock the car and go upstairs.
And then my neighbor comes to visit to tell me my lights are on.
And I'd like to use the gong, the text display and the yellow triangle to make my app look as "original Volvo" as possible. Right down to using the same language. My car speaks German :)
The Method
Breaking down the project into component steps I need to:
- Decode the CAN bus data
- Identify the key-in and key-out-of-ignition data
- Identify the door-open data, and identify the driver's door open
- Identify the light-switch-set-to-PARK data
- Intermediate Goal 1: Print all data to the Arduino serial port to verify the logic on the connected laptop
- Add logic to AND all of the conditions together
- Sound a piezo buzzer on my breadboard when all conditions are met, and/or....
- Light an LED on my breadboard when all conditions are met
- Make the light flash/buzzer pulse without using Arduino delays()
- Intermediate Goal 2: have the Arduino sounding the piezo buzzer as a Lamps On warning
If you look at my chosen steps I am deliberately only listening (reading) the CAN bus, I am NOT yet sending any data to the vehicle. It's called playing it safe, learning as you go, gathering experience, walking before you can run, etc etc etc.
So how did I go up to this point?
Basically very well. I had a rainy weekend ahead of me and nothing to hold me back out of the garage, so I decided to throw myself into a weekend of data discovery and practical experience.
Identifying the data was not too hard. I found some using my Excel method, but afterwards I got CanHacker to work and used that to find the other data bytes. And a lot more too!
By the end of the Saturday, I had identified all the data I needed.
Tip: Use a Battery Charger when Playing With Your Car. I have a CTEK intelligent battery charger, only 5A, but enough to offset hopefully a large chunk of the power consumption when the ignition key is out or in PosI. Not enough for PosII, but I don't plan to have the ignition in PosII for too long. Oh, and did I tell you CTEK chargers are also Swedish?
Anyway, back to the normal program. Adding the buzzer and LED to the breadboard was easy enough, 2 different Arduino output pins. I have enough bits and pieces lying around to add around 200 LEDs and a couple of buzzers. Enough for what I needed.
However I quickly disconnected the buzzer, as a bug in my code meant the piezo buzzer was on all the time, and the piezo screech was driving me mad.
Learning moment: LEDs are your friends, they are nice and silent :).
I also learnt that the difficult part of my work was debugging the running code on the live vehicle: it's cold in the garage, and operating the laptop on the vehicle cargo area floor is simple nowhere near as comfortable as my desk in my house. So how could I program and test the code in my house without being in the cold garage all the time? It is Winter after all.
I could go to the wreckers and buy some modules and hook them up on my workbench and run everything here - but that costs time and money, and I was hungry for a result.
So I wrote some auto-vehicle-detect code. Very simple: the Arduino runs and loops using a dummy CAN bus frame until it detects a real CAN bus frame, and then it switches off the dummy data. This allows me to run and debug without being in the car. And I just write what I need in my dummy data to test whatever I am testing.
By late rainy Sunday afternoon I had stable, working code that ran connected to the car, doing what I wanted, albeit at this stage still using the LED and the (now connected) piezo buzzer.
I call that a great success!
Walk before you run, remember?
(PS: look out for part 2, it's coming, it's good...)