MuuTTa

Technology empowering people !

Arduino

Is time to work with arduino, lpcXpresso not works for me!

I’m using the arduino uno board.

The usb codes of the keys, by BSD guys and this for android (I never use them)

If arduino not works in Arch:

# chmod 777 /run/lock/

Note, I try using adding my user to a root group using 755 permission but not works 😦

For the next:

RFduino

Pending to do or for the next version
* Buttons without resistors using this page

30 comments on “Arduino

  1. Fredy Rouge
    1 April 2013

    First exploration, Reading all the MuuTTa-Wand buttons. (the code is not nice, is only a quick test)

    /*
    First exploration of arduino for MuuTTa
     */
    
    // constants won't change. They're used here to 
    // set pin numbers:
    const int PinF5 = 2;     // Pin for F5
    const int PinF4 = 3;     // Pin for F4
    const int PinF3 = 4;     // Pin for F3
    const int PinF2 = 5;     // Pin for F2
    const int PinF1 = 6;     // Pin for F1
    const int PinF6 = 7;     // Pin for F6
    const int PinF7 = 8;     // Pin for F7
    const int PinF8 = 9;     // Pin for F8
    const int PinF9 = 10;    // Pin for F9
    const int PinF10 = 11;   // Pin for F10
    const int ledPin = 13;  //  LED pin
    
    // variables will change:
    int StateF1 = 0;         // variable for reading the pushbutton status
    int StateF2 = 0;
    int StateF3 = 0;
    int StateF4 = 0;
    int StateF5 = 0;
    int StateF6 = 0;
    int StateF7 = 0;
    int StateF8 = 0;
    int StateF9 = 0;
    int StateF10 = 0;
    
    void setup() {
      // initialize the LED pin as an output:
      pinMode(ledPin, OUTPUT);      
      // initialize the Fx pin's as an inputs:
      pinMode(PinF1, INPUT);
      pinMode(PinF2, INPUT);
      pinMode(PinF3, INPUT);
      pinMode(PinF4, INPUT);
      pinMode(PinF5, INPUT);
      pinMode(PinF6, INPUT);
      pinMode(PinF7, INPUT);
      pinMode(PinF8, INPUT);
      pinMode(PinF9, INPUT);
      pinMode(PinF10, INPUT);     
    }
    
    void loop(){
      // read the state of the pushbutton value:
      StateF1 = digitalRead(PinF1);
      StateF2 = digitalRead(PinF2);
      StateF3 = digitalRead(PinF3);
      StateF4 = digitalRead(PinF4);
      StateF5 = digitalRead(PinF5);
      StateF6 = digitalRead(PinF6);
      StateF7 = digitalRead(PinF7);
      StateF8 = digitalRead(PinF8);
      StateF9 = digitalRead(PinF9);
      StateF10 = digitalRead(PinF10);
      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH:
      if (StateF1 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F2
      if (StateF2 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F3
      if (StateF3 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F4
      if (StateF4 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F5
      if (StateF5 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F6
      if (StateF6 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F7
      if (StateF7 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F8
      if (StateF8 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F9
      if (StateF9 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }
      //F10
      if (StateF10 == HIGH) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
      }  
    }
    

    Works πŸ™‚ but I have a hardware problem with one button 😦

  2. Fredy Rouge
    1 April 2013

    Reading MuTTa-Wand keys, a better code πŸ™‚

    /*
    First exploration of arduino for MuuTTa
     */
    
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int WandKeys = 10;
    const int ledPin = 13;  //  LED pin
    int StateS[] = {0,0,0,0,0,0,0,0,0,0};
    
    void setup() {
      int i = 0;
    
      pinMode(ledPin, OUTPUT); // LED as output
     
      for (i=0; i<WandKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
    
    void loop(){
      int i = 0;
      for (i=0; i<WandKeys; i++) {
        StateS[i] = digitalRead(WandS[i]);
      }
      for (i=0; i<WandKeys; i++) {
          if (StateS[i] == HIGH) {
            // turn LED on:
            digitalWrite(ledPin, HIGH);
          }
          else {
            // turn LED off:
            digitalWrite(ledPin, LOW);
          }
      }
    }
    
  3. Fredy Rouge
    1 April 2013

    Detection of the first two buttons at the some time, code is not nice but works!
    update using also the combination for Q key (MuuTTa-Wand Concept 1)

    /*
    First exploration of arduino for MuuTTa
     */
    
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int WandKeys = 10;
    const int ledPin = 13;  //  LED pin
    int StateS[] = {0,0,0,0,0,0,0,0,0,0};
    const int KeyA[] = {1,0,1,0,0,0,0,0,0,0};
    
    const int KeyQ[] = {0,0,0,0,1,0,0,1,1,0};
    const int KeyW[] = {0,0,0,1,0,0,0,1,1,0};
    const int KeyE[] = {0,0,1,0,0,0,0,1,1,0};
    const int KeyR[] = {0,1,0,0,0,0,0,1,1,0};
    const int KeyT[] = {1,0,0,0,0,0,0,1,1,0};
    
    void setup() {
      int i = 0;
    
      pinMode(ledPin, OUTPUT); // LED as output
     
      for (i=0; i<WandKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
    
    void loop(){
      int i = 0;
      for (i=0; i<WandKeys; i++) {
        StateS[i] = digitalRead(WandS[i]);
      }
      
      if (
      StateS[0] == KeyA[0] &&
      StateS[1] == KeyA[1] &&
      StateS[2] == KeyA[2] &&
      StateS[3] == KeyA[3] &&
      StateS[4] == KeyA[4] &&
      StateS[5] == KeyA[5] &&
      StateS[6] == KeyA[6] &&
      StateS[7] == KeyA[7] &&
      StateS[8] == KeyA[8] &&
      StateS[9] == KeyA[9] 
      ) {
        digitalWrite(ledPin, HIGH);
      }
      else {
        digitalWrite(ledPin, LOW);
      }
    
      if (
      StateS[0] == KeyQ[0] &&
      StateS[1] == KeyQ[1] &&
      StateS[2] == KeyQ[2] &&
      StateS[3] == KeyQ[3] &&
      StateS[4] == KeyQ[4] &&
      StateS[5] == KeyQ[5] &&
      StateS[6] == KeyQ[6] &&
      StateS[7] == KeyQ[7] &&
      StateS[8] == KeyQ[8] &&
      StateS[9] == KeyQ[9] 
      ) {
        digitalWrite(ledPin, HIGH);
      }
      else {
        digitalWrite(ledPin, LOW);
      }
    }
    
  4. Fredy Rouge
    2 April 2013

    I think that i find the solution here for improve the code:

    // this code assumes that pull-down resistors are used - invert the state if using pull-ups.
    
    int pins[] = {2,3,5,7,8,9}; // array holding the pins connected to switches
    int number_of_pins = sizeof(pins)/ sizeof(pins[0]);  // determines how many pins in the above array
    
    int switchStates = 0; // this will hold a bitmask of switch states 
    
    void setup() 
    { 
      Serial.begin(9600);
    }
    
    void loop()
    {
        // save the switch states as bits in the variable switchStates
        for(int i=0; i < number_of_pins; i++)
        {
          // set bits in switchState to represent the state of the switches
          int state = digitalRead( pins[i]);     
          bitWrite(switchStates, i, state);      
        }
        
        switch (switchStates)
        {
          // test for some combinations of switches we care about
          case  B000001: Serial.println("the first switch (pin 2) is pressed"); break;
          case  B000101: Serial.println("switches on pins 2 and 5 are pressed"); break;
          case  B111111: Serial.println("all switches are pressed"); break;      
        } 
        showFlags();   
        delay(1000);
    } 
    
    // reports flags that are set to see how the switchStates variable is used
    void showFlags()
    {
        Serial.println(switchStates, BIN);
        for(int sw = 0; sw < number_of_pins; sw++)
        {
          Serial.print("Switch ");
          Serial.print(sw);
          if( bitRead(switchStates, sw) == true)
             Serial.println(" is pressed ");
          else   
             Serial.println(" is not pressed");      
        }
        Serial.println();
    }
    
  5. Fredy Rouge
    2 April 2013

    I love to know binary, with this code I turn on the led when I push the first or the last button:

    /*
    First exploration of arduino for MuuTTa
     */
     
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int WandKeys = 10;
    const int ledPin = 13;  //  LED pin
    int StateS = 0; // this will hold a bitmask of switch states
    
     
    void setup() {
      pinMode(ledPin, OUTPUT); // LED as output
      
      for (int i=0; i<WandKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
     
    void loop(){
      for (int i=0; i<WandKeys; i++) {
        int State = digitalRead(WandS[i]);
        bitWrite(StateS, i, State);
      }
      
      switch (StateS) {
        case 1: digitalWrite(ledPin, HIGH); break;
        case 512: digitalWrite(ledPin, HIGH); break;
        default: digitalWrite(ledPin, LOW);
      }
    }
    
  6. Fredy Rouge
    2 April 2013

    Q W E R T keys:

    /*
    First exploration of arduino for MuuTTa
     */
     
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int NumberOfKeys = sizeof(WandS)/ sizeof(WandS[0]); //no entiendo por que divide pero funciona
    const int ledPin = 13;  //  LED pin
    int StateS = 0; // this will hold a bitmask of switch states
    
     
    void setup() {
      pinMode(ledPin, OUTPUT); // LED as output
      
      for (int i=0; i<NumberOfKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
     
    void loop(){
      for (int i=0; i<NumberOfKeys; i++) {
        int State = digitalRead(WandS[i]);
        bitWrite(StateS, i, State);
      }
      
      switch (StateS) { //Example: 512 = 1000000000 = last switch (F10 key) is on
        case 400: digitalWrite(ledPin, HIGH); break; //Q
        case 392: digitalWrite(ledPin, HIGH); break; //W
        case 388: digitalWrite(ledPin, HIGH); break; //E
        case 386: digitalWrite(ledPin, HIGH); break; //R
        case 385: digitalWrite(ledPin, HIGH); break; //T
        default: digitalWrite(ledPin, LOW);
      }
    }
    
  7. Fredy Rouge
    2 April 2013

    Now also sending the key via serial port:

    /*
    First exploration of arduino for MuuTTa
     */
     
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int NumberOfKeys = sizeof(WandS)/ sizeof(WandS[0]); //no entiendo por que divide pero funciona
    const int ledPin = 13;  //  LED pin
    int StateS = 0; // this will hold a bitmask of switch states
    
     
    void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT); // LED as output  
      for (int i=0; i<NumberOfKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
     
    void loop(){
      for (int i=0; i<NumberOfKeys; i++) {
        int State = digitalRead(WandS[i]);
        bitWrite(StateS, i, State);
      }
      
      switch (StateS) { //Example: 512 = 1000000000 = last switch (F10 key) is on
        case 400: digitalWrite(ledPin, HIGH); Serial.println("q"); break; //Q
        case 392: digitalWrite(ledPin, HIGH); Serial.println("w"); break; //W
        case 388: digitalWrite(ledPin, HIGH); Serial.println("e"); break; //E
        case 386: digitalWrite(ledPin, HIGH); Serial.println("r"); break; //R
        case 385: digitalWrite(ledPin, HIGH); Serial.println("t"); break; //T
        default: digitalWrite(ledPin, LOW);
      }
      delay(10);
    }
    

    Pending solve the Linux read because “tail -f” not works, for now “cat </dev/ttyACM0"

    • Fredy Rouge
      3 April 2013

      delay(200);
      I do a change, the delay now is 200 , for get one char at time because I was getting 3 or 4 times for one touch.

  8. Fredy Rouge
    3 April 2013

    Now I can read using screen but after use it I can’t upload the firmware to arduino, I get this error:

    Serial port '/dev/ttyACM0' not found Did you select the right one from the Tools > Serial Port menu? 
    
    • Fredy Rouge
      3 April 2013

      For solve this problem the solution is simple:

      $ pkill screen
      
  9. Fredy Rouge
    3 April 2013

    The problem wasn’t screen
    I run arduino from a terminal and I get:

    [fredyrouge@vostro200 concept1]$ arduino concept1.ino 
    Experimental:  JNI_OnLoad called.
    Stable Library
    =========================================
    Native lib Version = RXTX-2.1-7
    Java lib Version   = RXTX-2.1-7
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
    please see: How can I use Lock Files with rxtx? in INSTALL
    

    The solution is not nice 😦

    # chmod 777 /run/lock/
    
    • Fredy Rouge
      3 April 2013

      Now I understand screen was one problem and /run/lock permissions other!

  10. Fredy Rouge
    3 April 2013

    cat /tmp/arduino.input | tr ‘\r’ ‘\n’ | tr -d ‘\n’

    \r in newline in DOS
    \n newline in UNIX

  11. Fredy Rouge
    4 April 2013

    Now the idea is use arduino as HID USB keyboard, i find this tutorial:
    http://mitchtech.net/arduino-usb-hid-keyboard/
    For use as base, no I know that my arduino isn’t SMD:
    http://arduino.cc/en/Main/ArduinoBoardUnoSMD and i have to sold a resistor:
    http://arduino.cc/en/Hacking/DFUProgramming8U2

  12. Fredy Rouge
    4 April 2013

    Voy a desconectar los pines del arduino, son:

    11 10 9 8 7 6 5 4 3 2
    azul verde negro naranja rojo rojo naranja negro verde azul
    arduino uno

    Y el blanco en la tierra

  13. Fredy Rouge
    4 April 2013

    Installing the dfu programmer:

    $ yaourt -S dfu-programmer

    Put and remove the jumper no dejar el jumper puesto

    # dfu-programmer at90usb82 erase
    # dfu-programmer at90usb82 flash Arduino-usbserial-uno.hex
    Validating…
    4058 bytes used (99.07%)
    # dfu-programmer at90usb82 reset

    thanks to this post for this note:

    β€œError parsing the line. Something went wrong with creating the memory image.” β€” the .hex file is damaged, re-download it

    I open the IDE and put my sketch (following the guide)
    I do again the process with the jumper and:

    # dfu-programmer at90usb82 erase
    # dfu-programmer at90usb82 flash Arduino-keyboard-0.3.hex
    Validating…
    4022 bytes used (98.19%)
    # dfu-programmer at90usb82 reset

    And f*?%k, all this only for know how works:

    Flash Arduino-usbserial.hex bootloader with dfu-programmer (erase/flash/reset)
    Plug cycle the Arduino
    Flash firmware sketch using Arduino IDE
    Plug cycle the Arduino
    Flash Arduino-keyboard-0.3.hex bootloader with dfu-programmer (erase/flash/reset)
    Test and repeat

  14. Fredy Rouge
    4 April 2013

    Testing the demo:

    /* Arduino USB HID Keyboard Demo
     * Random Key/Random Delay
     */
    
    uint8_t buf[8] = { 
      0 }; 	/* Keyboard report buffer */
    
    void setup() 
    {
      Serial.begin(9600);
      randomSeed(analogRead(0));
      delay(200);
    }
    
    void loop() 
    {
      int randomChar = random(4, 130);
      long randomDelay = random(1000, 10000);
    
      delay(randomDelay);
    
      buf[2] = randomChar;	  // Random character
      Serial.write(buf, 8);	// Send keypress
      releaseKey();
    }
    
    void releaseKey() 
    {
      buf[0] = 0;
      buf[2] = 0;
      Serial.write(buf, 8);	// Release key  
    }
    

    And Works!!!

  15. Fredy Rouge
    4 April 2013

    MuuTTa-Wand as key for down the volume:

    /*
    First exploration of arduino for MuuTTa
     */
      
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int NumberOfKeys = sizeof(WandS)/ sizeof(WandS[0]); //no entiendo por que divide pero funciona
    const int ledPin = 13;  //  LED pin
    int StateS = 0; // this will hold a bitmask of switch states
    uint8_t buf[8] = { 0 }; /* Keyboard report buffer */
      
    void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT); // LED as output 
      for (int i=0; i<NumberOfKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
      
    void loop(){
      for (int i=0; i<NumberOfKeys; i++) {
        int State = digitalRead(WandS[i]);
        bitWrite(StateS, i, State);
      }
       
      switch (StateS) { //Example: 512 = 1000000000 = last switch (F10 key) is on
        case 400: digitalWrite(ledPin, HIGH); Serial.println("q"); break; //Q
        case 392: digitalWrite(ledPin, HIGH); Serial.println("w"); break; //W
        case 388: digitalWrite(ledPin, HIGH); Serial.println("e"); break; //E
        case 386: digitalWrite(ledPin, HIGH); Serial.println("r"); break; //R
        case 385: digitalWrite(ledPin, HIGH); Serial.println("t"); break; //T
        case 512: digitalWrite(ledPin, HIGH); buf[2] = 129; Serial.write(buf, 8); releaseKey();
        default: digitalWrite(ledPin, LOW);
      }
      delay(200);
    }
    
    void releaseKey()
    {
    buf[0] = 0;
    buf[2] = 0;
    Serial.write(buf, 8);	// Release key
    }
    
  16. Fredy Rouge
    9 April 2013

    For do more easy the programming process and remember the jumper:

    as-arduino.sh (you need Arduino-usbserial-uno.hex file in the directory)

    #!/bin/bash
    
    dfu-programmer at90usb82 erase && \
    dfu-programmer at90usb82 flash Arduino-usbserial-uno.hex && \
    dfu-programmer at90usb82 reset
    if [ $? != 0 ]; then
        echo "Temporary short using jhe jumper!!!!"
    else
        echo "Remember unplug and plug again the Arduino"
    fi
    

    as-keyboard.sh (you need Arduino-keyboard-0.3.hex file in the directory)

    #!/bin/bash
    
    dfu-programmer at90usb82 erase && \
    dfu-programmer at90usb82 flash Arduino-keyboard-0.3.hex && \
    dfu-programmer at90usb82 reset
    if [ $? != 0 ]; then
        echo "Temporary short using jhe jumper!!!!"
    else
        echo "Remember unplug and plug again the Arduino"
    fi
    
  17. Fredy Rouge
    9 April 2013

    Not works:

    digitalWrite(WandS[i], HIGH); // turn on pullup resistors
    

    This is for connect to 5V, i need to GROUND
    Reading http://arduino.cc/en/Tutorial/DigitalPins

    pulldown resistor (resistor to ground)

  18. Fredy Rouge
    9 April 2013

    No internal pull-down in arduino! http://www.squidoo.com/arduino-pull-down-resistors

  19. Fredy Rouge
    9 April 2013

    Something is wrong with the Q combination, pending do a test, now using the W key works!!!!!

    /*
    First exploration of arduino for MuuTTa
     */
       
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int NumberOfKeys = sizeof(WandS)/ sizeof(WandS[0]); //no entiendo por que divide pero funciona
    const int ledPin = 13;  //  LED pin
    int StateS = 0; // this will hold a bitmask of switch states
    uint8_t buf[8] = { 0 }; /* Keyboard report buffer */
       
    void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT); // LED as output
      for (int i=0; i<NumberOfKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
       
    void loop(){
      for (int i=0; i<NumberOfKeys; i++) {
        int State = digitalRead(WandS[i]);
        bitWrite(StateS, i, State);
      }
        
      switch (StateS) { //Example: 512 = 1000000000 = last switch (F10 key) is on
        case 400: digitalWrite(ledPin, HIGH); break; //Q
        case 392: digitalWrite(ledPin, HIGH); buf[2] = 0x1A; Serial.write(buf, 8); releaseKey(); break; //W
        case 388: digitalWrite(ledPin, HIGH); break; //E
        case 386: digitalWrite(ledPin, HIGH); break; //R
        case 385: digitalWrite(ledPin, HIGH); break; //T
        default: digitalWrite(ledPin, LOW);
      }
      delay(200);
    }
     
    void releaseKey()
    {
    buf[0] = 0;
    buf[2] = 0;
    Serial.write(buf, 8);   // Release key
    }
    
  20. Fredy Rouge
    11 April 2013

    QWERT as keyboard!!! and now the code is elegant πŸ™‚

    /*
    First exploration of arduino for MuuTTa
     */
       
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int NumberOfKeys = sizeof(WandS)/ sizeof(WandS[0]); //no entiendo por que divide pero funciona
    const int ledPin = 13;  //  LED pin
    int StateS = 0; // this will hold a bitmask of switch states
    uint8_t buf[8] = { 0 }; /* Keyboard report buffer */
    int keyCode;
       
    void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT); // LED as output
      for (int i=0; i&lt;NumberOfKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
       
    void loop(){
      for (int i=0; i&lt;NumberOfKeys; i++) {
        int State = digitalRead(WandS[i]);
        bitWrite(StateS, i, State);
      }
        
      switch (StateS) { //Example: 512 = 1000000000 = last switch (F10 key) is on
        case 400: sendKey(keyCode = 0x14); break; //Q
        case 392: sendKey(keyCode = 0x1A); break; //W
        case 388: sendKey(keyCode = 0x08); break; //E
        case 386: sendKey(keyCode = 0x15); break; //R
        case 385: sendKey(keyCode = 0x17); break; //T
        default: digitalWrite(ledPin, LOW);
      }
      delay(200);
    }
     
    void sendKey(int keyCode) {
      digitalWrite(ledPin, HIGH);
      buf[2] = keyCode;
      Serial.write(buf, 8);
      buf[0] = 0;
      buf[2] = 0;
      Serial.write(buf, 8);   // Release key
    }
    
  21. Fredy Rouge
    11 April 2013

    Alpha chars enter, space and backspace:

    /*
    First exploration of arduino for MuuTTa
     */
       
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int NumberOfKeys = sizeof(WandS)/ sizeof(WandS[0]); //no entiendo por que divide pero funciona
    const int ledPin = 13;  //  LED pin
    int StateS = 0; // this will hold a bitmask of switch states
    uint8_t buf[8] = { 0 }; /* Keyboard report buffer */
    int keyCode;
       
    void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT); // LED as output
      for (int i=0; i<NumberOfKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
       
    void loop(){
      for (int i=0; i<NumberOfKeys; i++) {
        int State = digitalRead(WandS[i]);
        bitWrite(StateS, i, State);
      }
        
      switch (StateS) { //Example: 512 = 1000000000 = last switch (F10 key) is on
        case 400: sendKey(keyCode = 0x14); break; // Q
        case 392: sendKey(keyCode = 0x1A); break; // W
        case 388: sendKey(keyCode = 0x08); break; // E
        case 386: sendKey(keyCode = 0x15); break; // R
        case 385: sendKey(keyCode = 0x17); break; // T
        
        case 464: sendKey(keyCode = 0x04); break; // A
        case 456: sendKey(keyCode = 0x16); break; // S
        case 452: sendKey(keyCode = 0x07); break; // D
        case 450: sendKey(keyCode = 0x09); break; // F
        case 449: sendKey(keyCode = 0x0A); break; // G
        
        case 208: sendKey(keyCode = 0x1D); break; // Z
        case 200: sendKey(keyCode = 0x1B); break; // X
        case 196: sendKey(keyCode = 0x06); break; // C
        case 194: sendKey(keyCode = 0x19); break; // V
        case 193: sendKey(keyCode = 0x05); break; // B
        
        
        case  44: sendKey(keyCode = 0x1C); break; // Y
        case  76: sendKey(keyCode = 0x18); break; // U
        case 140: sendKey(keyCode = 0x0C); break; // I
        case 268: sendKey(keyCode = 0x12); break; // O
        case 524: sendKey(keyCode = 0x13); break; // P
        
        case  46: sendKey(keyCode = 0x0B); break; // H
        case  78: sendKey(keyCode = 0x0D); break; // J
        case 142: sendKey(keyCode = 0x0E); break; // K
        case 270: sendKey(keyCode = 0x0F); break; // L
        case 526: sendKey(keyCode = 0x33); break; // ;
        
        case  38: sendKey(keyCode = 0x11); break; // N
        case  70: sendKey(keyCode = 0x10); break; // M
        case 134: sendKey(keyCode = 0x36); break; // ,
        case 262: sendKey(keyCode = 0x37); break; // .
        case 518: sendKey(keyCode = 0x38); break; // /
        
        
        case 396: sendKey(keyCode = 0x2C); break; // SPACE
        case 198: sendKey(keyCode = 0x28); break; // ENTER
        case 462: sendKey(keyCode = 0x2A); break; // ERASE
        
        default: digitalWrite(ledPin, LOW);
      }
      delay(200);
    }
     
    void sendKey(int keyCode) {
      digitalWrite(ledPin, HIGH);
      buf[2] = keyCode;
      Serial.write(buf, 8);
      buf[0] = 0;
      buf[2] = 0;
      Serial.write(buf, 8);   // Release key
    }
    
  22. Pingback: The blog | MuuTTa

  23. Fredy Rouge
    30 April 2013

    Changes in the codification for do it more easy:

    /*
    First exploration of arduino for MuuTTa
     */
       
    int WandS[] = {2,3,4,5,6,7,8,9,10,11}; //S0 in wand is pin 2 in Arduino
    const int NumberOfKeys = sizeof(WandS)/ sizeof(WandS[0]); //no entiendo por que divide pero funciona
    const int ledPin = 13;  //  LED pin
    int StateS = 0; // this will hold a bitmask of switch states
    uint8_t buf[8] = { 0 }; /* Keyboard report buffer */
    int keyCode;
       
    void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT); // LED as output
      for (int i=0; i<NumberOfKeys; i++) {  // MuuTTa-Wand-buttons (Sx) as input
        pinMode(WandS[i], INPUT);
      }
    }
       
    void loop(){
      for (int i=0; i<NumberOfKeys; i++) {
        int State = digitalRead(WandS[i]);
        bitWrite(StateS, i, State);
      }
        
      switch (StateS) { //Example: 512 = 1000000000 = last switch (F10 key) is on
        case 208: sendKey(keyCode = 0x14); break; // Q
        case 200: sendKey(keyCode = 0x1A); break; // W
        case 196: sendKey(keyCode = 0x08); break; // E
        case 194: sendKey(keyCode = 0x15); break; // R
        case 193: sendKey(keyCode = 0x17); break; // T
        
        case 464: sendKey(keyCode = 0x04); break; // A
        case 456: sendKey(keyCode = 0x16); break; // S
        case 452: sendKey(keyCode = 0x07); break; // D
        case 450: sendKey(keyCode = 0x09); break; // F
        case 449: sendKey(keyCode = 0x0A); break; // G
        
        case 400: sendKey(keyCode = 0x1D); break; // Z
        case 392: sendKey(keyCode = 0x1B); break; // X
        case 388: sendKey(keyCode = 0x06); break; // C
        case 386: sendKey(keyCode = 0x19); break; // V
        case 385: sendKey(keyCode = 0x05); break; // B
        
        
        case  38: sendKey(keyCode = 0x1C); break; // Y
        case  70: sendKey(keyCode = 0x18); break; // U
        case 134: sendKey(keyCode = 0x0C); break; // I
        case 262: sendKey(keyCode = 0x12); break; // O
        case 518: sendKey(keyCode = 0x13); break; // P
        
        case  46: sendKey(keyCode = 0x0B); break; // H
        case  78: sendKey(keyCode = 0x0D); break; // J
        case 142: sendKey(keyCode = 0x0E); break; // K
        case 270: sendKey(keyCode = 0x0F); break; // L
        case 526: sendKey(keyCode = 0x33); break; // ;
        
        case  44: sendKey(keyCode = 0x11); break; // N
        case  76: sendKey(keyCode = 0x10); break; // M
        case 140: sendKey(keyCode = 0x36); break; // ,
        case 268: sendKey(keyCode = 0x37); break; // .
        case 524: sendKey(keyCode = 0x38); break; // /
        
        
        case 396: sendKey(keyCode = 0x2C); break; // SPACE
        case 198: sendKey(keyCode = 0x2A); break; // BACK-SPACE
        case 330: sendKey(keyCode = 0x28); break; // ENTER
        
        default: digitalWrite(ledPin, LOW);
      }
      delay(200);
    }
     
    void sendKey(int keyCode) {
      digitalWrite(ledPin, HIGH);
      buf[2] = keyCode;
      Serial.write(buf, 8);
      buf[0] = 0;
      buf[2] = 0;
      Serial.write(buf, 8);   // Release key
    }
    
    

Leave a reply to Fredy Rouge Cancel reply

Information

This entry was posted on 1 April 2013 by in MuuTTaWand Concept 1.