Current version of the OpenAuto Pro is 9.0
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guide for steering wheel remote control
#11
My Arduino Pro Micro arrived today, so I could test all. But I have a few issues.
First the analog input A0 seems to be defective on my Pro Micro so I have to change to A1.
Second my remote controls are not only different in how they look the values that comes from the two wires are different too...

So I have to modify the code from marcb4.

Here is my code:
Code:
#include <Keyboard.h>

char F8Key = KEY_F8;
char F7Key = KEY_F7;
int pressed = 0;


void setup() {
    Keyboard.begin();
  //Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A1); //Kabel grau  | Wire grey
  int sensorValue2 = analogRead(A2); //Kabel weiß | Wire white
  /*
  Serial.print ("A1 = ");
  Serial.print (sensorValue);
  Serial.print ("  |  ");
  Serial.print ("A2 = ");
  Serial.print (sensorValue2);
  Serial.print ("  |  ");
  Serial.print ("Pressed = ");
  Serial.println (pressed);
  */
  delay(50);
if (sensorValue < 800 || sensorValue2 < 800) {

  delay(100);

// Fernbedienung 1 | Remute control 1

  // GPS

  if (sensorValue2 >  180 && sensorValue2 < 240 && pressed == 0) {
    Keyboard.print('f');
    pressed = 1;
  }
  // Telefon annehmen | Phone take
  if (sensorValue > 240 && sensorValue < 300 && pressed == 0) {
    Keyboard.print('p');
    pressed = 1;
  }
  //
  // Telefon auflegen | Phone hang up
  if (sensorValue2 > 130 && sensorValue2 < 180 && pressed == 0) {
    Keyboard.print('o');
    pressed = 1;
  }
  // Sprechen | Speak
  if (sensorValue2 > 300 && sensorValue2 < 360 && pressed == 0) {
    Keyboard.print('M');
    pressed = 1;
  }
  // Mode
  if (sensorValue2 > 60 && sensorValue2 < 120 && pressed == 0) {
    //Toggle active application
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press(KEY_F3);
    delay(50);
    Keyboard.release(KEY_LEFT_CTRL);
    Keyboard.release(KEY_F3);
    pressed = 1;
  }


// Fernbedienung 2 | Remote control 2

  // +
  if (sensorValue > 470 && sensorValue < 530 && pressed == 0) {
    Keyboard.press(F8Key);
    delay(100);
    Keyboard.releaseAll();
    pressed = 1;
  }

  // -
  if (sensorValue > 580 && sensorValue < 640 && pressed == 0) {
    Keyboard.press(F7Key);
    delay(100);
    Keyboard.releaseAll();
    pressed = 1;
  }

  // <
  if (sensorValue2 > 530 && sensorValue2 < 590 && pressed == 0) {
    Keyboard.print('v');
    pressed = 1;
  }
  // >
  if (sensorValue > 410 && sensorValue < 470 && pressed == 0) {
    Keyboard.print('n');
    pressed = 1;
  }
  // Mutej
  if (sensorValue > 350 && sensorValue < 410 && pressed == 0) {
    Keyboard.print('b');
    pressed = 1;
  }
}
  if (sensorValue > 800 && sensorValue2 > 800) {
    pressed = 0;
  }

}
Reply
#12
I have inserted the Arduino Pro Micro into the cover from the RF receiver.

First I marked the needed space for the USB plug:
   

Then I removed the interfering parts:
   

After that I soldered the Arduino Pro Micro with short wires directly on the plug:
   

Here is the underside of the board (for reference, you can also see that mine board is really fresh produced 2020/02/26):
   

I need to add some spacers (Ice Cream stick glued on):
   

Now I put the Arduino Pro Micro into a shrink tube and secured it with cable ties:
   

Put the assemble into the case:
   

Than it looks like this:
   

And all in my car:
   
Reply
#13
Awesome idea!! Maybe I'll do that too Smile

How do the remote controls work for you? Sometimes I need to press the button two times or hold the button longer so that the arduino gets the info which key to press/send
Reply
#14
I have the same issue. But I don't know if it is a problem with the hardware or the code for the Arduino.
Also I don't like that I can't hold the volume button and the volume would increase/decrease constantly. Now I have to push the button several times.
I think this is also code based.
Reply
#15
I made mine with a timer set to 65ms. That way the analog voltage had to be stable for 65ms before it was considered a valid button press, and I also keep track of which button. After the button press is determined to be valid, I then take the appropriate action. I have a mix of keyboard commands and i2c outputs.

Then there is code that determines if the button is held down. Holding "Volume Down" causes "Mute", and holding "Mode" causes "Listen" (A function of the front end software I am using, this is on a Windows PC.) 

I also use an old Sony head unit in the trunk as the volume control, so I use an i2c port expander to activate opto-isolators that simulate pressing buttons on a Sony wired remote control. Well, not actually a real Sony wired remote. I took one apart, got the resistor values, and made a little circuit with the resistors and optos and the i2c chip. There is also a pair of i2c buffer chips, one in the front of the car, and one in the back. I had to do that as i2c signals do not travel that far, and the Arduino would lock up due to the i2c channel locking up. 

The pictures show the circuit board I designed for the i2c expander chip. The chip has more outputs than I used, hence the unpopulated parts. And I also left the ability to put the i2c buffer chip on this board, but I didn't need it as I had it on another board in the same enclosure in the back of the car.

   

   

Code:
    WheelValue = analogRead(WHEEL); // Grab the Wheel Analog Value

      if ((WheelValue > 40) & (WheelValue < 160)) // Volume Down 72
      {
        if (!WheelVolDnPressed)
        {
          ButtonPressedMillis = millis();
          WheelVolDnPressed = true;
          WheelVolUpPressed = false;
          WheelChDnPressed = false;
          WheelChUpPressed = false;
          WheelModePressed = false;
          NoButtonsPressed = false;
        }
      }

      if ((WheelValue > 180) & (WheelValue < 300)) // Volume Up 221
      {
        if (!WheelVolUpPressed)
        {
          ButtonPressedMillis = millis();
          WheelVolDnPressed = false;
          WheelVolUpPressed = true;
          WheelChDnPressed = false;
          WheelChUpPressed = false;
          WheelModePressed = false;
          NoButtonsPressed = false;
        }
      }

      if ((WheelValue > 320) & (WheelValue < 485)) // Channel Down 368
      {
        if (!WheelChDnPressed)
        {
          ButtonPressedMillis = millis();
          WheelVolDnPressed = false;
          WheelVolUpPressed = false;
          WheelChDnPressed = true;
          WheelChUpPressed = false;
          WheelModePressed = false;
          NoButtonsPressed = false;
        }
      }

      if ((WheelValue > 500) & (WheelValue < 600)) // Channel Up 538
      {
        if (!WheelChUpPressed)
        {
          ButtonPressedMillis = millis();
          WheelVolDnPressed = false;
          WheelVolUpPressed = false;
          WheelChDnPressed = false;
          WheelChUpPressed = true;
          WheelModePressed = false;
          NoButtonsPressed = false;
        }
      }

      if ((WheelValue > 625) & (WheelValue < 750)) // Mode 686
      {
        if (!WheelModePressed)
        {
          ButtonPressedMillis = millis();
          WheelVolDnPressed = false;
          WheelVolUpPressed = false;
          WheelChDnPressed = false;
          WheelChUpPressed = false;
          WheelModePressed = true;
          NoButtonsPressed = false;
        }
      }

      if (WheelValue > 780) // No Buttons Pressed 803
      {
        if (!NoButtonsPressed)
        {
          ButtonPressedMillis = millis();
          WheelVolDnPressed = false;
          WheelVolUpPressed = false;
          WheelChDnPressed = false;
          WheelChUpPressed = false;
          WheelModePressed = false;
          NoButtonsPressed = true;
        }
      }

      if (millis() - ButtonPressedMillis > WheelValidPress) // The Analog value has been stable long enough
      { // to be considered a valid button press.
        ValidButtonPress = true;                            // Even No Buttons pressed is a valid Button
      }
   

    if (ValidButtonPress)
    {
      ValidButtonPress = false;
      if (!WhlBtnLocked)
      {
        if (WheelVolDnPressed)
        {
          currentVolDnMillis = millis();
          if (currentVolDnMillis - VolDnRepeat > VolDnCooldown)
          {
            VolDnCount = VolDnCount + 1;
            if (VolDnCount < 4)
            {
              WheelVolDn = true;
              VolDnRepeat = currentVolDnMillis;

              #if USESERIAL==true
                Serial.println(WheelValue);
                Serial.println("Wheel Volume Down");
              #endif

            }
            else
            {
              WheelVolDn = false;
              action = CMD_MUTE; // If Volume Down is held for 2 seconds, MUTE
              WhlBtnLocked = true; // Lock the steering wheel buttons

              #if USESERIAL==true
                Serial.println(WheelValue);
                Serial.println("Wheel Mute");
              #endif

            }
          }
        }

        if (WheelVolUpPressed)
        {
          currentVolUpMillis = millis();
          if (currentVolUpMillis - VolUpRepeat > VolUpCooldown)
          {
            WheelVolUp = true;
            VolUpRepeat = currentVolUpMillis;

            #if USESERIAL==true
              Serial.println(WheelValue);
              Serial.println("Wheel Volume Up");
            #endif

          }
        }

        if (WheelChDnPressed)
        {
          currentChDnMillis = millis();
          if (currentChDnMillis - ChDnRepeat > ChDnCooldown)
          {
            WheelCHDn = true;
            ChDnRepeat = currentChDnMillis;

            #if USESERIAL==true
              Serial.println(WheelValue);
              Serial.println("Wheel Channel Down");
            #endif

            Keyboard.press(KEY_LEFT_CTRL);    // Send CTRL - LEFT ARROW
            Keyboard.press(KEY_LEFT_ARROW);
       
            delay(100);
            Keyboard.releaseAll();
            delay(200);

          }
        }

        if (WheelChUpPressed)
        {
          currentChUpMillis = millis();
          if (currentChUpMillis - ChUpRepeat > ChUpCooldown)
          {
            WheelCHUp = true;
            ChUpRepeat = currentChUpMillis;

            #if USESERIAL==true
              Serial.println(WheelValue);
              Serial.println("Wheel Channel Up");
            #endif

            Keyboard.press(KEY_LEFT_CTRL);    // Send CTRL - RIGHT ARROW
            Keyboard.press(KEY_RIGHT_ARROW);
       
            delay(100);
            Keyboard.releaseAll();
            delay(200);

          }
        }

        if (WheelModePressed)
        {
          currentModeMillis = millis();
          if (currentModeMillis - ModeRepeat > ModeCooldown)
          {
            ModeCount = ModeCount + 1;
            if (ModeCount < 4)
            {
              WheelMode = true;
              ModeRepeat = currentModeMillis;

              #if USESERIAL==true
                Serial.println(WheelValue);
                Serial.println("Wheel Mode");
              #endif

            }
            else
            {
              WheelMode = false;
              WheelListen = true;
              WhlBtnLocked = true;

              #if USESERIAL==true
                Serial.println(WheelValue);
                Serial.println("Wheel Listen");
              #endif

            }
          }
        }
      }

      if (NoButtonsPressed)
      {
        WheelVolDnPressed = false;
        WheelVolUpPressed = false;
        WheelChDnPressed = false;
        WheelChUpPressed = false;
        WheelModePressed = false;
        VolDnCount = 0;
        ModeCount = 0;
        WhlBtnLocked = false;

        if (WheelMode)
        {
          Keyboard.press(KEY_LEFT_CTRL);    // Send Mode Change to Computer
          Keyboard.press(KEY_LEFT_ALT);
          Keyboard.press('s');

          #if USESERIAL==true
            Serial.println("Mode Change Sent");
            Serial.println(millis());
          #endif

          delay(100);
          Keyboard.releaseAll();
          delay(200);
          WheelMode = false;
        }

        if (WheelListen)
        {
          Keyboard.press(KEY_LEFT_CTRL);    // Send Listen to Computer
          Keyboard.press(KEY_LEFT_ALT);
          Keyboard.press('l');

          #if USESERIAL==true
            Serial.println("Listen Mode Sent");
            Serial.println(millis());
          #endif

          delay(100);
          Keyboard.releaseAll();
          delay(200);
          WheelListen = false;
        }
      }
    }

    if (WheelVolUp)
    {
      action = CMD_VOLUP;
    }
    else if (WheelVolDn)
    {
      action = CMD_VOLDW;
    }

    switch (action)     // Adjust Volume Up or Down or Mute
    {
      case CMD_VOLUP:
        if (CMDVolume < 40)
        {
          CMDVolume = CMDVolume + 1;

          #if USESERIAL==true
            Serial.print(F("VOL+"));
            Serial.print(F(" -"));
            Serial.print(CMDVolume);
          #endif

        }
        WheelVolUp = false;
        break;

      case CMD_VOLDW:
        if (CMDVolume > 0)
        {
          CMDVolume = CMDVolume - 1;

          #if USESERIAL==true
            Serial.print(F("VOL-"));
            Serial.print(F(" -"));
            Serial.print(CMDVolume);
           #endif

        }
        WheelVolDn = false;
        break;

      case CMD_MUTE:
        if (currentMuteMillis - muteRepeat > muteCooldown)
        { //500ms cooldown to prevent mute from toggling
          MUTE_SONY = true;
          muteRepeat = currentMuteMillis;

          #if USESERIAL==true
            Serial.print(F("MUTE "));
          #endif

        }
        break;

      default: //idle if no command is received
        //do nothing
        break;
    }
    action = CMD_NONE;

    if (MUTE_SONY)
    {

      #if USESERIAL==true
        Serial.println("Sony Mute()");
        Serial.println(millis());
      #endif             
     
      if (i2c_start(0x20<<1 | I2C_WRITE))
      {
        i2c_write(0x12);
        i2c_write(MUTE);
        i2c_stop();
      }
     
      #if USESERIAL==true
        Serial.print(F("Sony Mute Pushed  "));
        Serial.println(millis());
      #endif
     
      delay(SONY_BTN_PRESS);
       
      if (i2c_start(0x20<<1 | I2C_WRITE))
      {
        i2c_write(0x12);
        i2c_write(NONE);
        i2c_stop();
      }
     
      #if USESERIAL==true
        Serial.print(F("Sony Mute Released  "));
        Serial.println(millis());
      #endif
     
      delay(SONY_BTN_RELEASE);   
      MUTE_SONY = false;
    }

    if (CMDVolume != ACTVolume)
    {
      if (CMDVolume < ACTVolume)
      {
        if (i2c_start(0x20<<1 | I2C_WRITE))
        {
          i2c_write(0x12);
          i2c_write(VOL_LOWER);
          i2c_stop();
        }
     
        #if USESERIAL==true
          Serial.print(F("Sony Volume Down Pushed  "));
          Serial.println(millis());
          Serial.println(CMDVolume);
          Serial.println(ACTVolume);
        #endif
     
        delay(SONY_BTN_PRESS);  
       
        if (i2c_start(0x20<<1 | I2C_WRITE))
        {
          i2c_write(0x12);
          i2c_write(NONE);
          i2c_stop();
        }
     
        #if USESERIAL==true
          Serial.print(F("Sony Volume Down Released  "));
          Serial.println(millis());
          Serial.println(CMDVolume);
          Serial.println(ACTVolume);
        #endif
     
        delay(SONY_BTN_RELEASE);   
        ACTVolume = ACTVolume - 1;
      }

      if ((CMDVolume > ACTVolume) & (ACTVolume < 30))
      {
        if (i2c_start(0x20<<1 | I2C_WRITE))
        {
          i2c_write(0x12);
          i2c_write(VOL_RAISE);
          i2c_stop();
        }
     
        #if USESERIAL==true
          Serial.print(F("Sony Volume Up Pushed  "));
          Serial.println(millis());
          Serial.println(CMDVolume);
          Serial.println(ACTVolume);
        #endif
     
        delay(SONY_BTN_PRESS);  
       
        if (i2c_start(0x20<<1 | I2C_WRITE))
        {
          i2c_write(0x12);
          i2c_write(NONE);
          i2c_stop();
        }
     
        #if USESERIAL==true
          Serial.print(F("Sony Volume Up Released  "));
          Serial.println(millis());
          Serial.println(CMDVolume);
          Serial.println(ACTVolume);
        #endif
     
        delay(SONY_BTN_RELEASE);   
        ACTVolume = ACTVolume + 1;
      }   
    }
  }

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)