Light Music from BMW
Continuing the theme of the communication network of BMW control units, this article will focus on the light control unit (LCM), and those funny things that I managed to implement on it. But first things first and begin with the explanatory part.
LCM (Light Control Module) is a device that performs the following functions:
Therefore, the LCM is the executor when the required light is turned on. He receives control information from switches in the driver control zone or via the I-bus. As feedback, information is provided on the bus about the switched on devices and their malfunctions. Therefore, the driver will be promptly informed by a message on the dashboard if, for example, the left low beam lamp burns out. Information about the malfunction is determined whether the device is turned on or not.
Lighting fixtures are switched by means of direct current amplifiers on semiconductor devices. This eliminates the problems of burning contacts on the relay and the need to use fuses. However, it complicates the scheme and increases the cost of repairs. Cases when output stages of DC amplifiers fail are not uncommon. In this case, you have to repair the LCM or change to a working one with subsequent encoding.
When installing an abnormal alarm, the master needs to get contact with the wires of the turn signals or the side lights. They are typically twisted to a wiring harness in the area of the LCM. I have seen this. Although the problem could be solved more humanely, connecting to the I-bus through a microcontroller. In this case, an abnormal alarm system will be able to gain access to all lighting devices, not just turn signals. In addition, a central locking system, glass, sunroof and folding mirrors will become available. But the use of the microcontroller and the corresponding software is not an easy task, and the master will better ignore this option.
Using dealer diagnostic and coding tools, you can interact with LCM. Read, clear fault codes, request diagnostic commands, encode the operating mode and parameters. Diagnostic equipment is connected to the D-bus, on which there is no physical connection to the LCM. LCM is an I-bus subscriber and interaction with diagnostic equipment occurs through a gateway in the dashboard. The gateway forwards messages from the D-bus to the I-bus and vice versa. Thus, if you submit diagnostic requests to turn on one or another light fixture and “sniff” the I-bus, you can calculate the logic of action on the LCM registers to turn on the desired fixture. That's exactly what I did. On the BMW DIS, running in a virtual machine, he set the commands: turn on the left front turn signal, dipped right, left brake light, etc. At the same time fixed frames on the I-bus. The diagnostic request for individual switching on of the light device is as follows:

The sender of the message is diagnostics (identifier 3F ), the receiver LCM ( D0 ), message type 0C . In bytes DAT0 - DAT3 the mask is located, where the correspondence of the bit to the external light device is determined. A single value in this mask forces current to be supplied to the corresponding device for 30 seconds, a zero value immediately de-energizes. If the diagnostic message is successfully received, the LCM confirms with a positive acknowledgment: D0 03 3F A0 4C . Thus, using the diagnostic equipment, the lighting fixture is switched on individually upon request, so that it can be evaluated for operability. The table below shows the position of the bit from the DAT0-DAT3, which will turn on the light for 30 seconds.
If it is necessary to turn on not one but several lighting fixtures, then it is enough to combine the value in the DAT0-DAT3 area by logical addition. Thus, you can make any available combination of lights listed in the table glow. For example, by sending a message 3F 0F D0 0C 00 00 00 00 40 00 00 40 00 00 00 00 00 EC to the I-bus, the left low beam headlamp and the front left turn signal light will be switched on. Then, with the message 3F 0F D0 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 EC, pay off everything.
Thanks to the described features of LCM, you can create an application that can turn on any combination of lighting devices in a different sequence, limited only by the inertia of incandescent lamps. Obviously, the eLight module works in this way. German colleagues took into account the capabilities of LCM and created their own project, which includes both hardware and software. The module itself is connected to the car simply, 3 contacts are enough: the case, the power supply of the on-board network, I-bus. Then, using the application on the PC, the operating mode of the module is programmed. For example, when closing a car, the headlights will turn on in such a sequence that they create the effect of running lights. Funny thing turns out. And what if we make light music from external lighting devices, which will be accompanied by sound from the car’s speaker system. It will be even more fun! Moreover, there are all the technical capabilities for this.
In a previous article, I already described the ability to connect to a standard speaker system as a CD changer. That is, with the sound output everything is already clear. But how can you synchronize light accompaniment with music? The obvious solution for me was to use the MIDI protocol. Moreover, there is a ready-made software that will allow you to create a light series in sync with the music. I mean a sequencer.
MIDI is a protocol for the interaction of musical instruments. The protocol is based on the serial transmission of data from the master device to the slave. A MIDI keyboard or sequencer can be used as a master, and various synthesizers can be used as subordinates. MIDI protocol messages are divided into 2 types: channel messages and system messages. We are interested in channel messages, as they transmit sound control commands. Namely, those that contain information about the event with a note: the note is on, the note is off. This message also conveys information about the strength of the effect on the note, but it is not of interest.
If we interpret the system of external lighting devices of the car as a subordinate MIDI device, where each lamp has its own note, then we get a “light synthesizer”. At least connect a sequencer to it, even a keyboard, and play with light bulbs as you like. But for such an implementation, a process is needed that will convert the MIDI input stream to I-bus messages for LCM. In the figure below, this process is indicated by midi4lcm.

midi4lcm is a server that receives data in its network segment from multicast. From the entire stream of received data, midi4lcm filters the 1st channel voice MIDI messages. Depending on which note was affected, it generates a message for LCM. MIDI messages are integrated taking into account a small delay, since it will be too expensive to create a separate I-bus message for each UDP datagram carrying information about the event of a note. To do this, the server combines the received MIDI messages into one I-bus message if the reception interval does not exceed 1 ms.
In order to perform a light row on a car at a time convenient for us, it is necessary to have a saved sequence of MIDI messages, i.e. a MIDI file. You can create it using sequencers. Today, there is a large selection of applications for creating music and saving it in various formats. From the simplest sequencer to fancy music stations. In this option, the main benefit of such applications is the ability to play a MIDI track and export it to a file. Especially if there is the possibility of parallel operation of the audio track, then it becomes possible to create a light series in synchronous sound. For an example of how it looks in practice
.
Thus, the result of creativity for car light music comes down to two files: MIDI and audio.
So, let's say we already have at our disposal the necessary files of the MIDI light series and musical accompaniment, for example, in the WAV format. You can synchronously play them using Gstreamer if you have the necessary plugins. Namely, by executing on the command line:
In this command, Gstreamer broadcasts MIDI messages from the lighting.mid file synchronously according to timestamps. Messages are sent to the ip address 127.0.0.1 and UDP port 21928. It is on this port that the midi4lcm server is configured to receive multicast. This is usually how MIDI devices that work on a local network are configured. In addition to MIDI broadcasting, the gst-launch pipeline transmits the audio stream from the music.wav file to the PulseAudio sound server. If the linear output of the computer on which this command is executed is connected to the car’s speaker system, the desired effect will be achieved — the light music of the lighting fixtures under the sound accompaniment. True, in order for this effect to be “spectacular” outside, you must leave the door open, otherwise it will be too quiet.

This figure shows the working diagram in more detail. The Raspberry Pi mini computer acts as additional equipment for the car, which is integrated into the standard bus of interaction between the I-bus control units and the speaker system. On the other hand, Raspberry has interfaces for connecting to a local network so that you can interact with other computers and receive audio and MIDI streams. In this case, it becomes possible to connect the sequencer to the car and check the operation of the MIDI track, so to speak, “live”.
In the end, I will show how it turned out in practice:
.
Additional information on the topic:
" MIDI Wavy: making controlled color music using Arduino and MIDI
" A series of articles on MIDI from the magazine "Musical Equipment"
»Dealer documentation for electricians of BMW cars" BMW WDS "
LCM (Light Control Module) is a device that performs the following functions:
- switching external and internal lighting devices;
- serviceability of incandescent lamps;
- monitors the position of the switches of lighting devices;
- interaction with other control units.
Therefore, the LCM is the executor when the required light is turned on. He receives control information from switches in the driver control zone or via the I-bus. As feedback, information is provided on the bus about the switched on devices and their malfunctions. Therefore, the driver will be promptly informed by a message on the dashboard if, for example, the left low beam lamp burns out. Information about the malfunction is determined whether the device is turned on or not.
Lighting fixtures are switched by means of direct current amplifiers on semiconductor devices. This eliminates the problems of burning contacts on the relay and the need to use fuses. However, it complicates the scheme and increases the cost of repairs. Cases when output stages of DC amplifiers fail are not uncommon. In this case, you have to repair the LCM or change to a working one with subsequent encoding.
When installing an abnormal alarm, the master needs to get contact with the wires of the turn signals or the side lights. They are typically twisted to a wiring harness in the area of the LCM. I have seen this. Although the problem could be solved more humanely, connecting to the I-bus through a microcontroller. In this case, an abnormal alarm system will be able to gain access to all lighting devices, not just turn signals. In addition, a central locking system, glass, sunroof and folding mirrors will become available. But the use of the microcontroller and the corresponding software is not an easy task, and the master will better ignore this option.
Using dealer diagnostic and coding tools, you can interact with LCM. Read, clear fault codes, request diagnostic commands, encode the operating mode and parameters. Diagnostic equipment is connected to the D-bus, on which there is no physical connection to the LCM. LCM is an I-bus subscriber and interaction with diagnostic equipment occurs through a gateway in the dashboard. The gateway forwards messages from the D-bus to the I-bus and vice versa. Thus, if you submit diagnostic requests to turn on one or another light fixture and “sniff” the I-bus, you can calculate the logic of action on the LCM registers to turn on the desired fixture. That's exactly what I did. On the BMW DIS, running in a virtual machine, he set the commands: turn on the left front turn signal, dipped right, left brake light, etc. At the same time fixed frames on the I-bus. The diagnostic request for individual switching on of the light device is as follows:

The sender of the message is diagnostics (identifier 3F ), the receiver LCM ( D0 ), message type 0C . In bytes DAT0 - DAT3 the mask is located, where the correspondence of the bit to the external light device is determined. A single value in this mask forces current to be supplied to the corresponding device for 30 seconds, a zero value immediately de-energizes. If the diagnostic message is successfully received, the LCM confirms with a positive acknowledgment: D0 03 3F A0 4C . Thus, using the diagnostic equipment, the lighting fixture is switched on individually upon request, so that it can be evaluated for operability. The table below shows the position of the bit from the DAT0-DAT3, which will turn on the light for 30 seconds.
Show table
| Световой прибор | DAT0, bin | DAT1, bin | DAT2, bin | DAT3, bin |
|--------------------------------------------------------------------------------------------|
| Неизвестно | 00000000 | 00000000 | 00000000 | 00000001 |
| Указатель поворота задний правый | 00000000 | 00000000 | 00000000 | 00000010 |
| Задний противотуманный фонарь левый | 00000000 | 00000000 | 00000000 | 00000100 |
| Стояночный огонь задний внутренний правый | 00000000 | 00000000 | 00000000 | 00001000 |
| Стояночный огонь задний правый | 00000000 | 00000000 | 00000000 | 00010000 |
| Неизвестно | 00000000 | 00000000 | 00000000 | 00100000 |
| Указатель поворота передний левый | 00000000 | 00000000 | 00000000 | 01000000 |
| Неизвестно | 00000000 | 00000000 | 00000000 | 10000000 |
| Неизвестно | 00000000 | 00000000 | 00000001 | 00000000 |
| Неизвестно | 00000000 | 00000000 | 00000010 | 00000000 |
| Фонарь подсветки номерного знака правый | 00000000 | 00000000 | 00000100 | 00000000 |
| Стояночный огонь задний левый | 00000000 | 00000000 | 00001000 | 00000000 |
| Стоп-сигнал средний | 00000000 | 00000000 | 00010000 | 00000000 |
| Стояночный огонь передний правый | 00000000 | 00000000 | 00100000 | 00000000 |
| Указатель поворота передний правый | 00000000 | 00000000 | 01000000 | 00000000 |
| Указатель поворота задний левый | 00000000 | 00000000 | 10000000 | 00000000 |
| Стояночный огонь передний левый | 00000000 | 00000001 | 00000000 | 00000000 |
| Стояночный огонь задний внутренний левый | 00000000 | 00000010 | 00000000 | 00000000 |
| Противотуманная фара левая | 00000000 | 00000100 | 00000000 | 00000000 |
| Неизвестно | 00000000 | 00001000 | 00000000 | 00000000 |
| Фара дальнего света левая | 00000000 | 00010000 | 00000000 | 00000000 |
| Фара дальнего света правая | 00000000 | 00100000 | 00000000 | 00000000 |
| Противотуманная фара правая | 00000000 | 01000000 | 00000000 | 00000000 |
| Задний противотуманный фонарь правый | 00000000 | 10000000 | 00000000 | 00000000 |
| Неизвестно | 00000001 | 00000000 | 00000000 | 00000000 |
| Неизвестно | 00000010 | 00000000 | 00000000 | 00000000 |
| Фонарь подсветки номерного знака левый | 00000100 | 00000000 | 00000000 | 00000000 |
| Стоп-сигнал левый | 00001000 | 00000000 | 00000000 | 00000000 |
| Стоп-сигнал правый | 00010000 | 00000000 | 00000000 | 00000000 |
| Фара ближнего света правая | 00100000 | 00000000 | 00000000 | 00000000 |
| Фара ближнего света левая | 01000000 | 00000000 | 00000000 | 00000000 |
| Неизвестно | 10000000 | 00000000 | 00000000 | 00000000 |
If it is necessary to turn on not one but several lighting fixtures, then it is enough to combine the value in the DAT0-DAT3 area by logical addition. Thus, you can make any available combination of lights listed in the table glow. For example, by sending a message 3F 0F D0 0C 00 00 00 00 40 00 00 40 00 00 00 00 00 EC to the I-bus, the left low beam headlamp and the front left turn signal light will be switched on. Then, with the message 3F 0F D0 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 EC, pay off everything.
Thanks to the described features of LCM, you can create an application that can turn on any combination of lighting devices in a different sequence, limited only by the inertia of incandescent lamps. Obviously, the eLight module works in this way. German colleagues took into account the capabilities of LCM and created their own project, which includes both hardware and software. The module itself is connected to the car simply, 3 contacts are enough: the case, the power supply of the on-board network, I-bus. Then, using the application on the PC, the operating mode of the module is programmed. For example, when closing a car, the headlights will turn on in such a sequence that they create the effect of running lights. Funny thing turns out. And what if we make light music from external lighting devices, which will be accompanied by sound from the car’s speaker system. It will be even more fun! Moreover, there are all the technical capabilities for this.
In a previous article, I already described the ability to connect to a standard speaker system as a CD changer. That is, with the sound output everything is already clear. But how can you synchronize light accompaniment with music? The obvious solution for me was to use the MIDI protocol. Moreover, there is a ready-made software that will allow you to create a light series in sync with the music. I mean a sequencer.
MIDI is a protocol for the interaction of musical instruments. The protocol is based on the serial transmission of data from the master device to the slave. A MIDI keyboard or sequencer can be used as a master, and various synthesizers can be used as subordinates. MIDI protocol messages are divided into 2 types: channel messages and system messages. We are interested in channel messages, as they transmit sound control commands. Namely, those that contain information about the event with a note: the note is on, the note is off. This message also conveys information about the strength of the effect on the note, but it is not of interest.
If we interpret the system of external lighting devices of the car as a subordinate MIDI device, where each lamp has its own note, then we get a “light synthesizer”. At least connect a sequencer to it, even a keyboard, and play with light bulbs as you like. But for such an implementation, a process is needed that will convert the MIDI input stream to I-bus messages for LCM. In the figure below, this process is indicated by midi4lcm.

midi4lcm is a server that receives data in its network segment from multicast. From the entire stream of received data, midi4lcm filters the 1st channel voice MIDI messages. Depending on which note was affected, it generates a message for LCM. MIDI messages are integrated taking into account a small delay, since it will be too expensive to create a separate I-bus message for each UDP datagram carrying information about the event of a note. To do this, the server combines the received MIDI messages into one I-bus message if the reception interval does not exceed 1 ms.
In order to perform a light row on a car at a time convenient for us, it is necessary to have a saved sequence of MIDI messages, i.e. a MIDI file. You can create it using sequencers. Today, there is a large selection of applications for creating music and saving it in various formats. From the simplest sequencer to fancy music stations. In this option, the main benefit of such applications is the ability to play a MIDI track and export it to a file. Especially if there is the possibility of parallel operation of the audio track, then it becomes possible to create a light series in synchronous sound. For an example of how it looks in practice

Thus, the result of creativity for car light music comes down to two files: MIDI and audio.
So, let's say we already have at our disposal the necessary files of the MIDI light series and musical accompaniment, for example, in the WAV format. You can synchronously play them using Gstreamer if you have the necessary plugins. Namely, by executing on the command line:
gst-launch-1.0 -v filesrc location=lighting.mid ! midiparse ! udpsink host=127.0.0.1 port=21928 sync=true filesrc location=music.wav ! wavparse ! pulsesink
In this command, Gstreamer broadcasts MIDI messages from the lighting.mid file synchronously according to timestamps. Messages are sent to the ip address 127.0.0.1 and UDP port 21928. It is on this port that the midi4lcm server is configured to receive multicast. This is usually how MIDI devices that work on a local network are configured. In addition to MIDI broadcasting, the gst-launch pipeline transmits the audio stream from the music.wav file to the PulseAudio sound server. If the linear output of the computer on which this command is executed is connected to the car’s speaker system, the desired effect will be achieved — the light music of the lighting fixtures under the sound accompaniment. True, in order for this effect to be “spectacular” outside, you must leave the door open, otherwise it will be too quiet.

This figure shows the working diagram in more detail. The Raspberry Pi mini computer acts as additional equipment for the car, which is integrated into the standard bus of interaction between the I-bus control units and the speaker system. On the other hand, Raspberry has interfaces for connecting to a local network so that you can interact with other computers and receive audio and MIDI streams. In this case, it becomes possible to connect the sequencer to the car and check the operation of the MIDI track, so to speak, “live”.
In the end, I will show how it turned out in practice:
.
Additional information on the topic:
" MIDI Wavy: making controlled color music using Arduino and MIDI
" A series of articles on MIDI from the magazine "Musical Equipment"
»Dealer documentation for electricians of BMW cars" BMW WDS "