Stuurbediening voor een aftermarket radio op een BMW K1100LT

Toon hier Uw afgeronde projecten aan anderen.
Berichten: 77
Geregistreerd: 06 Okt 2012, 10:57

Stuurbediening voor een aftermarket radio op een BMW K1100LT

Berichtdoor Beamer » 12 Aug 2015, 10:42

Recent heb ik weer een BMW K serie gekocht. Deze was destijds uitgerust met een radio-cassette van BMW.Met bediening op het stuur. De radio zat niet meer in de motor, maar ja, cassette is ook niet meer van deze tijd. Ik heb een radio gekocht met USB en SD aansluiting en IR remote. Dat laatste gaf mij de mogelijkheid om iets met een afstandsbediening te gaan doen.
Ik heb van de bijgeleverde afstandsbediening de codes uitgezien met de Arduino.
Helaas zitten er maar 4 toestel op het stuur en dat is erg weinig om een radio mee te bedienen.
Voor de Arduino een propje gemaakt met een State machine. Deze kent 3 modes. 1 toets gebruik ik om de modes te wisselen en de andere drie kan ik vrij gebruiken.
De code heb ik bijgevoegd en is voorzien van comments. Heb je vragen kom dan gerust op de lijn.

[code]code2=cpp
/* Gebruik van de standaard stuurcontrole van BMW K1100 LT op een aftermarket radio via IR.
* Door middel van een state machine worden de toetsen voor meerdere functies gebruikt.
* De vier toetsen worden alsvolg gebruikt:
* Vol up voor plus functie
* Vol down voor min functie
* Channel up voor diverse functies
* Channel down voor het schakelen tussen de modes
* De standaard aanwezig lED knippert het nummer van de mode.
* Tuseen twee zendopfrachten minmaal 150 milliseconden wachten. Proefondervindelijk vastgesteld.
*/

#include <Bounce2.h> // debounce lib
#include <IRremote.h> // IR lib
#include <EEPROM.h> // bewaar Band en Station in EEPROM

#define Vol_up 6 // pin voor Volume up button
#define Vol_down 7 // pin voor Volume down button
#define Channel_up 8 // pin voor Channel up button
#define Channel_down 9 // pin voor Channel down button
#define Singnal_led 13 // LED op stuur (indicatie Mode)
#define Vertraging 500 // vertraging voor druktoetsen

byte Mode = 0; // initial Mode
long millisBegin = millis(); // millis voor timing
long currentMillis; //
long KeyMillis; //
byte Band; // FM band
byte Station; // FM station
int StationButton[] = {0, 0x30CF, 0x18E7, 0x7A85, 0x10EF, 0x38C7, 0x5AA5}; // IR codes voor stations 1 t/m 6 voorafgegaan door een 0 dummy

// Initiate a Bounce objects

Bounce debouncerVU = Bounce(); // Volume up
Bounce debouncerVD = Bounce(); // Volume down
Bounce debouncerCU = Bounce(); // Channel up
Bounce debouncerCD = Bounce(); // Channel down

IRsend irsend; // IR object

//***********************************************************************************************************************

void setup() {

// Buttons met interne pull-up :

pinMode(Vol_up, INPUT_PULLUP); // Gebruik interne pull up
pinMode(Vol_down, INPUT_PULLUP); //
pinMode(Channel_up, INPUT_PULLUP); //
pinMode(Channel_down, INPUT_PULLUP);//

// Koppel de buttons aan bounce en geef de delay aan :

debouncerVU.attach(Vol_up);
debouncerVD.attach(Vol_down);
debouncerCU.attach(Channel_up);
debouncerCD.attach(Channel_down);
debouncerVU.interval(5); // interval in ms
debouncerVD.interval(5);
debouncerCU.interval(5);
debouncerCD.interval(5);

//Setup the LED :

pinMode(Singnal_led, OUTPUT);
digitalWrite(Singnal_led, HIGH); // Laat weten dat we er klaar voor zijn

// Haal Band en Station uit EEPORM
Band = EEPROM.read(0); // Haal Band uit EEPORM
Station = EEPROM.read(1); // Haal Station uit EEPORM
}

//************************************************************************************************************************

void loop() {
// Vraag buttons af :

currentMillis = millis();
debouncerVU.update(); // Toetsen afvragen
debouncerVD.update(); //
debouncerCU.update(); //
debouncerCD.update(); //

// Haal buttonwaardes op :

int valueVU = debouncerVU.read(); // Waardes ophalen
int valueVD = debouncerVD.read(); //
int valueCU = debouncerCU.read(); //
int valueCD = debouncerCD.read(); //

//*********************************************************

// Channel down fungeert als Mode knop

if (valueCD == LOW && currentMillis - millisBegin > 1000) { // vertraging voorkomt te snel wisselen
Mode++;
if (Mode == 3) Mode = 0; // max Mode bereikt, terug naar 0
blink(Mode + 1); // geef op de LED aan welke Mode we hebben, een extra want wij tellen vanaf 1
millisBegin = currentMillis;
}
if (currentMillis - millisBegin > 10000 && Mode > 0) { // na 10 seconden geen toets automatisch terug naar Mode 0
Mode = 0;
blink(Mode + 1);
}

//*********************************************************

// Maak een keuze in welke Mode we zitten

switch (Mode) {
case 0: // Mode 0

if ( valueVU == LOW && currentMillis - KeyMillis > Vertraging) { // Volume up button
irsend.sendNEC(0x02FD, 32); // Send NEC Volume up, 32 bits
KeyMillis = currentMillis; // timing voor buttons
millisBegin = currentMillis; // timing voor Mode ( 10 seconden timing)
}

if ( valueVD == LOW && currentMillis - KeyMillis > Vertraging) { // Volume down button
irsend.sendNEC(0x9867, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if ( valueCU == LOW && currentMillis - KeyMillis > Vertraging) { // Functie Radio, USB, SD
irsend.sendNEC(0x629D, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}
break;
//----------------------------------------------
case 1: // Mode = 1

if ( valueVU == LOW && currentMillis - KeyMillis > Vertraging) { // Zoek omhoog / volgende track
irsend.sendNEC(0x906F, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if ( valueVD == LOW && currentMillis - KeyMillis > Vertraging) { // Zoek omlaag / vorige track
irsend.sendNEC(0xE01F, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if ( valueCU == LOW && currentMillis - KeyMillis > Vertraging) { // Mute
irsend.sendNEC(0xE21D, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}
break;
//-----------------------------------------------
case 2: // Mode = 2

if ( valueVU == LOW && currentMillis - KeyMillis > Vertraging) { // Station omhoog
StUp(); // macro voor Station ophogen, loopt door naar de volgende Band
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if ( valueVD == LOW && currentMillis - KeyMillis > Vertraging) { // Station omlaag
StDown(); // macro voor Station ver;agen, loopt terug naar vorige Band
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if ( valueCU == LOW && currentMillis - KeyMillis > Vertraging) { // Equalizer
irsend.sendNEC(0x6897, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}
updateEEPROM();
break;
}
}

//**************************************************************

void blink(byte times) { //LED blink routine. Led staat altijd aan, dus blink knippert uit
for (byte x = 0 ; x < times ; x++) {
digitalWrite(Singnal_led, LOW); // Led uit
delay(100); // wacht 1/10 seconde
digitalWrite(Singnal_led, HIGH); // Led aan
delay(100); // wacht 1/10 seconde
}
}

//**************************************************************

void StUp() { // Station ophogen, desnoods naar volgende band
Station ++;
if (Station > 6) {
Station = 1;
Band ++;

if (Band > 3) Band = 1;
irsend.sendNEC(0x22DD, 32); // Band ophogen
delay(150); // altijd delay na send
}
irsend.sendNEC(StationButton[Station], 32); // Station ophogen
}

//**************************************************************

void StDown() { // Station verlagen, desnoods Band terug
Station --;
if (Station < 1) {
Station = 6;
Band --;
if (Band < 1 ) Band = 3;
irsend.sendNEC(0x22DD, 32); // Band verlagen (omlaag is twee keer omhoog bij 3 banden!!)
delay (150); // delay anders kan de radio het niet bijbenen.
irsend.sendNEC(0x22DD, 32);
delay (150); // ook hier weer een delay
}
irsend.sendNEC(StationButton[Station], 32); //Station verlagen
}

//--------------------------------------------------------------

void updateEEPROM() {
EEPROM.write (0, Band);
EEPROM.write (1, Station);
}
[/ code2]

Advertisement

Berichten: 32
Geregistreerd: 22 Apr 2015, 16:17

Re: Stuurbediening voor een aftermarket radio op een BMW K11

Berichtdoor dizzl » 12 Aug 2015, 17:48

Super dat je deelt, Beamer.
Heb je ook een foto van je project?

Berichten: 77
Geregistreerd: 06 Okt 2012, 10:57

Re: Stuurbediening voor een aftermarket radio op een BMW K11

Berichtdoor Beamer » 13 Aug 2015, 17:07

Nee, valt ook niet veel aan te zien. De toetsen zitten standaard al op het stuur. Ontwikkeld heb ik een en ander op een Uno. Daarna alles op een Pro Mini gezet. Pro Mini aangesloten met een 7805 voor de 5 volt. De interne regelaar van de Mini zei "poef" op 13,8 Volt.
Toen alles in krimpfolie en onder de radio gemonteerd.
Het visuele aspect is derhalve 0,0.
Gistermiddag getest en het werkt zoals ik het bedacht had.
Uiteraard had ik het thuis al getest in een kleine opstelling.

Krijg alles helaas niet onder cpp code2 :|

Gebruikers-avatar
Berichten: 188
Geregistreerd: 23 Dec 2011, 00:12

Re: Stuurbediening voor een aftermarket radio op een BMW K11

Berichtdoor Duality » 14 Aug 2015, 03:03

die spatie in je sluitings tag moet weg dus /code2 niet / code2

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Stuurbediening voor een aftermarket radio op een BMW K11

Berichtdoor nicoverduin » 14 Aug 2015, 05:58

Duality schreef:die spatie in je sluitings tag moet weg dus /code2 niet / code2
De start tag is ook verkeerd. anders had het er zo uigezien:
cpp code
/* Gebruik van de standaard stuurcontrole van BMW K1100 LT op een aftermarket radio via IR.
* Door middel van een state machine worden de toetsen voor meerdere functies gebruikt.
* De vier toetsen worden alsvolg gebruikt:
* Vol up voor plus functie
* Vol down voor min functie
* Channel up voor diverse functies
* Channel down voor het schakelen tussen de modes
* De standaard aanwezig lED knippert het nummer van de mode.
* Tuseen twee zendopfrachten minmaal 150 milliseconden wachten. Proefondervindelijk vastgesteld.
*/

#include <Bounce2.h> // debounce lib
#include <IRremote.h> // IR lib
#include <EEPROM.h> // bewaar Band en Station in EEPROM

#define Vol_up 6 // pin voor Volume up button
#define Vol_down 7 // pin voor Volume down button
#define Channel_up 8 // pin voor Channel up button
#define Channel_down 9 // pin voor Channel down button
#define Singnal_led 13 // LED op stuur (indicatie Mode)
#define Vertraging 500 // vertraging voor druktoetsen

byte Mode = 0; // initial Mode
long millisBegin = millis(); // millis voor timing
long currentMillis; //
long KeyMillis; //
byte Band; // FM band
byte Station; // FM station
int StationButton[] = { 0, 0x30CF, 0x18E7, 0x7A85, 0x10EF, 0x38C7, 0x5AA5 }; // IR codes voor stations 1 t/m 6 voorafgegaan door een 0 dummy

// Initiate a Bounce objects

Bounce debouncerVU = Bounce(); // Volume up
Bounce debouncerVD = Bounce(); // Volume down
Bounce debouncerCU = Bounce(); // Channel up
Bounce debouncerCD = Bounce(); // Channel down

IRsend irsend; // IR object

//***********************************************************************************************************************

void setup() {

// Buttons met interne pull-up :

pinMode(Vol_up, INPUT_PULLUP); // Gebruik interne pull up
pinMode(Vol_down, INPUT_PULLUP); //
pinMode(Channel_up, INPUT_PULLUP); //
pinMode(Channel_down, INPUT_PULLUP); //

// Koppel de buttons aan bounce en geef de delay aan :

debouncerVU.attach(Vol_up);
debouncerVD.attach(Vol_down);
debouncerCU.attach(Channel_up);
debouncerCD.attach(Channel_down);
debouncerVU.interval(5); // interval in ms
debouncerVD.interval(5);
debouncerCU.interval(5);
debouncerCD.interval(5);

//Setup the LED :

pinMode(Singnal_led, OUTPUT);
digitalWrite(Singnal_led, HIGH); // Laat weten dat we er klaar voor zijn

// Haal Band en Station uit EEPORM
Band = EEPROM.read(0); // Haal Band uit EEPORM
Station = EEPROM.read(1); // Haal Station uit EEPORM
}

//************************************************************************************************************************

void loop() {
// Vraag buttons af :

currentMillis = millis();
debouncerVU.update(); // Toetsen afvragen
debouncerVD.update(); //
debouncerCU.update(); //
debouncerCD.update(); //

// Haal buttonwaardes op :

int valueVU = debouncerVU.read(); // Waardes ophalen
int valueVD = debouncerVD.read(); //
int valueCU = debouncerCU.read(); //
int valueCD = debouncerCD.read(); //

//*********************************************************

// Channel down fungeert als Mode knop

if (valueCD == LOW && currentMillis - millisBegin > 1000) { // vertraging voorkomt te snel wisselen
Mode++;
if (Mode == 3)
Mode = 0; // max Mode bereikt, terug naar 0
blink(Mode + 1); // geef op de LED aan welke Mode we hebben, een extra want wij tellen vanaf 1
millisBegin = currentMillis;
}
if (currentMillis - millisBegin > 10000 && Mode > 0) { // na 10 seconden geen toets automatisch terug naar Mode 0
Mode = 0;
blink(Mode + 1);
}

//*********************************************************

// Maak een keuze in welke Mode we zitten

switch (Mode) {
case 0: // Mode 0

if (valueVU == LOW && currentMillis - KeyMillis > Vertraging) { // Volume up button
irsend.sendNEC(0x02FD, 32); // Send NEC Volume up, 32 bits
KeyMillis = currentMillis; // timing voor buttons
millisBegin = currentMillis; // timing voor Mode ( 10 seconden timing)
}

if (valueVD == LOW && currentMillis - KeyMillis > Vertraging) { // Volume down button
irsend.sendNEC(0x9867, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if (valueCU == LOW && currentMillis - KeyMillis > Vertraging) { // Functie Radio, USB, SD
irsend.sendNEC(0x629D, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}
break;
//----------------------------------------------
case 1: // Mode = 1

if (valueVU == LOW && currentMillis - KeyMillis > Vertraging) { // Zoek omhoog / volgende track
irsend.sendNEC(0x906F, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if (valueVD == LOW && currentMillis - KeyMillis > Vertraging) { // Zoek omlaag / vorige track
irsend.sendNEC(0xE01F, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if (valueCU == LOW && currentMillis - KeyMillis > Vertraging) { // Mute
irsend.sendNEC(0xE21D, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}
break;
//-----------------------------------------------
case 2: // Mode = 2

if (valueVU == LOW && currentMillis - KeyMillis > Vertraging) { // Station omhoog
StUp(); // macro voor Station ophogen, loopt door naar de volgende Band
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if (valueVD == LOW && currentMillis - KeyMillis > Vertraging) { // Station omlaag
StDown(); // macro voor Station ver;agen, loopt terug naar vorige Band
KeyMillis = currentMillis;
millisBegin = currentMillis;
}

if (valueCU == LOW && currentMillis - KeyMillis > Vertraging) { // Equalizer
irsend.sendNEC(0x6897, 32);
KeyMillis = currentMillis;
millisBegin = currentMillis;
}
updateEEPROM();
break;
}
}

//**************************************************************

void blink(byte times) { //LED blink routine. Led staat altijd aan, dus blink knippert uit
for (byte x = 0; x < times; x++) {
digitalWrite(Singnal_led, LOW); // Led uit
delay(100); // wacht 1/10 seconde
digitalWrite(Singnal_led, HIGH); // Led aan
delay(100); // wacht 1/10 seconde
}
}

//**************************************************************

void StUp() { // Station ophogen, desnoods naar volgende band
Station++;
if (Station > 6) {
Station = 1;
Band++;

if (Band > 3)
Band = 1;
irsend.sendNEC(0x22DD, 32); // Band ophogen
delay(150); // altijd delay na send
}
irsend.sendNEC(StationButton[Station], 32); // Station ophogen
}

//**************************************************************

void StDown() { // Station verlagen, desnoods Band terug
Station--;
if (Station < 1) {
Station = 6;
Band--;
if (Band < 1)
Band = 3;
irsend.sendNEC(0x22DD, 32); // Band verlagen (omlaag is twee keer omhoog bij 3 banden!!)
delay(150); // delay anders kan de radio het niet bijbenen.
irsend.sendNEC(0x22DD, 32);
delay(150); // ook hier weer een delay
}
irsend.sendNEC(StationButton[Station], 32); //Station verlagen
}

//--------------------------------------------------------------

void updateEEPROM() {
EEPROM.write(0, Band);
EEPROM.write(1, Station);
}
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 77
Geregistreerd: 06 Okt 2012, 10:57

Re: Stuurbediening voor een aftermarket radio op een BMW K11

Berichtdoor Beamer » 14 Aug 2015, 16:54

Nico bedankt.
Ik kon het niet vinden.

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Stuurbediening voor een aftermarket radio op een BMW K11

Berichtdoor nicoverduin » 14 Aug 2015, 22:39

Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Terug naar Afgeronde projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 5 gasten