Connect your Audi MMI to your Arduino
This is a library for Arduino devices. It allows connecting an Audi Multi Media Interface to your arduino, to read button events and toggle its lights.
Please make sure to read the requirements!
The Audi MMI is sometimes used for custom car projects. This library aims at providing a simple layer to integrate the MMI into any code project.
- Arduino (Should also work on teensy and other arduino compatible platforms!)
- Audi MMI
- arduinoIO, a library for button events
No releases, you have to clone or download From source
- Get your favourite Arduino IDE
- Clone the repository into your library directory
git clone https://github.com/rampage128/arduinoMmi.git
- Start a new sketch and add the library to it
IMPORTANT: First make sure you installed arduinoIO library aswell! Unfortunately the arduino IDE does not resolve library dependencies automatically. So you will have to make sure you installed and included it yourself!
After importing #import <arduinoMmi.h>
, you can create a new MMI:
Mmi mmi(HardwareSerial *serial, uint32_t mode, uint8_t bufferSize, uint8_t buttonCount, uint8_t wheelCount);
serial
: a pointer to the serial port you want to use: for example&Serial
.mode
: the serial mode to use for communication. On most MMIsSERIAL_8N2_RXINV
is used.bufferSize
: the size in bytes of the serial communication buffer.16
Sounds like a good choice.buttonCount
: the number of buttons your MMI has. Most MMIs have17
buttons.wheelCount
: the number of wheels your MMI has. Usually that is2
.
To make the mmi work, you should update the mmi in every loop:
mmi.update(mmiEvent);
The update method takes a callback function which you can define as follows:
void mmiEvent(uint8_t code) {
...
}
This callback function will be called by the MMI whenever there is a system event happening. This includes the following events:
0x35
: Triggered after the MMI was fully activated0x38
: Power button is pressed0xff
: Power is turned on (12v)
To be able to use the MMI properly, you will have to activate it. Since some people might want to
only activate it under certain conditions, the library does not automatically do this.
It can easily be done in the update callback by calling enableKeys()
:
void mmiEvent(uint8_t code) {
if (code == 0xff || code == 0x38) {
mmi.enableKeys();
}
}
If you do not call this, the MMI will not be usable. Also you can not call this whenever you want, the keys can only be enabled within 10-20 seconds after a power on event or a power button event was sent from the MMI.
Now you can use the following features:
You can create buttons by using their IDs:
MmiButton *mmiNavButton = mmi.createButton(0x05);
0x01
: pressing the big wheel0x02
: media button0x03
: name button0x04
: tel button0x05
: nav button0x06
: info button0x07
: car button0x08
: setup button0x0A
: top left button0x0B
: bottom left button0x0C
: previous button0x0D
: top right button0x0E
: bottom right button0x0F
: return button0x10
: next button0x18
: radio button0x38
: pressing the small wheel
The buttons can then be used in the same way as buttons from the arduinoIO library.
Wheels are created in the same way as buttons:
MmiWheel *mmiSmallWheel = mmi.createWheel(0x40);
0x40
: small wheel0x50
: big wheel
You can check interaction with a wheel like this:
if (mmiSmallWheel->wasTurned()) {
if (mmiSmallWheel->getAmount() < 0) {
// turned left
}
else {
// turned right
}
}
Lights work in a similar fashion. But you need to hand in a pointer to your previously created MMI object:
MmiLight mmiMediaLight(0x02, &mmi);
The lights use the same IDs as their corresponding buttons.
Important note: in order to use the lights, you have to set the illumination levels on the MMI first.
You can do that after the MMI was activated:
void mmiEvent(uint8_t code) {
if (code == 0x35) {
mmi.setIllumination(0xFF);
mmi.setHighlightLevel(0x99);
}
setIllumination()
: sets the intensity of the global backlight from0
(off) to255
(full brightness).setHighlightLevel()
: sets the intensity of the button highlights from0
(off) to255
(full brightness).
You do not need to call setIllumination()
for the highlight lights to work. But without calling setHighlightLevel()
they will not work.
You can interact with the lights like this:
setOn()
: switches the light on.setOff()
: switches the light off.set(boolean state)
: switches the light on or off depending on the providedstate
.toggle()
: toggles the light on if it is off and vice versa.isOn()
: returnstrue
if the light is currently on.
For more information, please refer to the source.
Feel free to open an issue or submit a PR
Also, if you like this or other of my projects, please feel free to support me using the Link below.
- arduinoIO to make the buttons work