DrewMangus

Member Since: December 19, 2010

Country: United States

  • There is a Metal Nut underneath.

  • Yes, they will indeed.

  • I just received this interesting little doodad, I'm using it with a Teensy 3.0 and here is some demo Code I wrote for it. Maybe it can help some others out. I haven't had the issue with it that others have been seeing described as poor build quality. Also, the comment from Member #333036 was pretty spot on as far as pin out. I used the encoder library from PJRC found here example which handles this device well. It does however increment +-4 every tick of the detent so just be careful when coding.

    #include 
    
    Encoder encoder(A5, A4); //These 2 pins are A and B of the encoder side, C is connected to ground
    
    const int redPin =  10; 
    const int greenPin =  A8;
    const int bluePin =  9;
    volatile boolean encoder_button = false;
    
    void setup() {
      Serial.begin(9600);
      pinMode(A3, INPUT);
      pinMode(redPin, OUTPUT);
      pinMode(greenPin, OUTPUT);
      pinMode(bluePin, OUTPUT);
      attachInterrupt(A3, buttonPush, CHANGE);
    }
    
    void loop() {
      int32_t value;
      value = encoder.read();
        Serial.print("value = ");
        Serial.println(value);
    
      if (Serial.available()) {
        Serial.read();
        Serial.println("Reset Encoder to Zero");
        encoder.write(0);
      }
      if(encoder_button)
      {
        for(int i=0; i< 20; i++) //Careful with this if you or a friend has epilepsy 
        {
          setColor(255, 255, 255);
          delay(10);
          setColor(0, 0, 0);
          delay(100);
        }
        encoder_button = false;
        Serial.println("Button Pushed");
      }
      else
      {
        setColor(value,0,0);
        delay(1000);  
        setColor(0,value,0);
        delay(1000);
        setColor(0,0,value);
        delay(1000);
      }
    }
    
    void buttonPush()
    {
      encoder_button = true;
    }
    
    void setColor(int red, int green, int blue)
    {
      analogWrite(redPin, red);
      analogWrite(greenPin, green);
      analogWrite(bluePin, blue);  
    }
    
  • It's mostly the read function from what I debugged, I ended up with this and it works as far as I can tell on my 1999 Explorer.

    //Define Serial Ports so I remember which is which
    #define PC Serial
    #define OBD Serial2
    
    //Set up ring buffer
    char rxData[20];
    char rxIndex=0;
    
    void setup() 
    {
       PC.begin(9600);
       OBD.begin(9600);
    
       ODB_init();
    }
    
    void loop() 
    {
      PC.println(getRPM()); //Print the int returned from getRPM
      delay(2000);//wait 2 seconds and grab another reading
    }
    
    void ODB_init(void)
    {
      //Wait for a little while before sending the reset command to the OBD-II-UART
      delay(2000);
      //Reset the OBD-II-UART
      OBD.print("ATZ\r");
      //Wait for a bit before starting to send commands after the reset.
      delay(2000);
      OBD_read();
      OBD.print("ATE0\r");
      OBD_read();
      OBD.flush();  
    }
    
    int getRPM(void)
    {
      //Query the OBD-II-UART for the Vehicle rpm
      OBD.flush();
      OBD.print("010C\r");
      OBD_read();
      return ((strtol(&rxData[6],0,16)*256)+strtol(&rxData[9],0,16))/4;
    }
    
    void OBD_read(void)
    {
      char c;
      do{
        if(OBD.available() > 0)
        {
          c = OBD.read();
          PC.print(c);
          if((c!= '>') && (c!='\r') && (c!='\n')) //Keep these out of our buffer
          {
            rxData[rxIndex++] = c; //Add whatever we receive to the buffer
          }  
         }     
      }while(c != '>'); //The ELM327 ends its response with this char so when we get it we exit out.
      rxData[rxIndex++] = '\0';//Converts the array into a string
      rxIndex=0; //Set this to 0 so next time we call the read we get a "clean buffer"
    }
    

    Sorry if that code is formatted super funky, First post with code in it ^_^

    Cheers hope that helps out somebody.

  • --Why was he retired? --He got old. Then some thumb-sucker came along and tagged him "RED". --Red? --Yeah, RED. R-E-D, "Retired, Extremely Dangerous".

    I thought this fit though it is a movie quote.

No public wish lists :(