Loading...
  Show Posts
Pages: 1 [2]
16  Using Arduino / Programming Questions / capsense help on: January 17, 2012, 07:59:52 pm
hey guys

so im building an instrument with capacitive touch sensors for keys.
i have the amazing MPR121 capacitance breakout board and it works wonderfully.

however, it only enables me to get input from 12 electrodes. i need 13 for a full octave (c to c').

i downloaded capsense, and tried to implement the code into my pre-existing MPR sketch, and well - i do get input from the capsense button on the arduino - but the latency is around 1 second!

if you could help me out, and tell me why my code slows down like that - i would be a very happy person.

here is my messy code - capsense is //commented. MPR121 code is taken from bildr.org

::

Code:
//#include <CapSense.h>
#include "mpr121.h"
#include <Wire.h>
#include <SimpleMessageSystem.h>

//CapSense   cs_19_15 = CapSense(2,3);

int irqpin = 12;  // Digital 12
boolean touchStates[12]; //to keep track of the previous touch states

void setup(){
  pinMode(irqpin, INPUT);
  digitalWrite(irqpin, HIGH); //enable pullup resistor
 
  Serial.begin(9600);
  Wire.begin();

  mpr121_setup();
}

void loop(){
// 
//    long tot = cs_19_15.capSense(30);
//  Serial.print(tot);
//  Serial.println("\t");
//
//  if(tot < 5000){
//    digitalWrite(13, LOW);
//  }
//  if(tot > 5000){
//
//    digitalWrite(13, HIGH);
//  }
//  delay(10);
//}
 
  readTouchInputs();
  {

  if (messageBuild() > 0) { // Checks to see if the message is complete and erases any previous messages
    switch (messageGetChar()) { // Gets the first word as a character
    case 'r': // Read pins (analog or digital)
      readpins(); // Call the readpins function
      break; // Break from the switch
    case 'w': // Write pin
      writepin(); // Call the writepin function
    }

  }

}
}







void readTouchInputs(){
  if(!checkInterrupt()){
   
    //read the touch state from the MPR121
    Wire.requestFrom(0x5A,2);
   
    byte LSB = Wire.receive();
    byte MSB = Wire.receive();
   
    uint16_t touched = ((MSB << 8) | LSB); //16bits that make up the touch states

   
    for (int i=0; i < 12; i++){  // Check what electrodes were pressed
      if(touched & (1<<i)){
     
        if(touchStates[i] == 0){
          //pin i was just touched
          Serial.print("pin ");
          Serial.print(i);
          Serial.println(" was just touched");
            digitalWrite(i+2, HIGH);
            digitalWrite(13, HIGH);
       
        }else if(touchStates[i] == 1){
          //pin i is still being touched
        } 
     
        touchStates[i] = 1;     
      }else{
        if(touchStates[i] == 1){

          Serial.print("pin ");
          Serial.print(i);
          Serial.println(" is no longer being touched");
            digitalWrite(i+2, LOW);
            digitalWrite(13, LOW);
         
          //pin i is no longer being touched
       }
       
        touchStates[i] = 0;
      }
   
    }
   
  }
}




void mpr121_setup(void){
 
  // Section A - Controls filtering when data is > baseline.
  set_register(0x5A, MHD_R, 0x01);
  set_register(0x5A, NHD_R, 0x01);
  set_register(0x5A, NCL_R, 0x00);
  set_register(0x5A, FDL_R, 0x00);

  // Section B - Controls filtering when data is < baseline.
  set_register(0x5A, MHD_F, 0x01);
  set_register(0x5A, NHD_F, 0x01);
  set_register(0x5A, NCL_F, 0xFF);
  set_register(0x5A, FDL_F, 0x02);
 
  // Section C - Sets touch and release thresholds for each electrode
  set_register(0x5A, ELE0_T, TOU_THRESH);
  set_register(0x5A, ELE0_R, REL_THRESH);
 
  set_register(0x5A, ELE1_T, TOU_THRESH);
  set_register(0x5A, ELE1_R, REL_THRESH);
 
  set_register(0x5A, ELE2_T, TOU_THRESH);
  set_register(0x5A, ELE2_R, REL_THRESH);
 
  set_register(0x5A, ELE3_T, TOU_THRESH);
  set_register(0x5A, ELE3_R, REL_THRESH);
 
  set_register(0x5A, ELE4_T, TOU_THRESH);
  set_register(0x5A, ELE4_R, REL_THRESH);
 
  set_register(0x5A, ELE5_T, TOU_THRESH);
  set_register(0x5A, ELE5_R, REL_THRESH);
 
  set_register(0x5A, ELE6_T, TOU_THRESH);
  set_register(0x5A, ELE6_R, REL_THRESH);
 
  set_register(0x5A, ELE7_T, TOU_THRESH);
  set_register(0x5A, ELE7_R, REL_THRESH);
 
  set_register(0x5A, ELE8_T, TOU_THRESH);
  set_register(0x5A, ELE8_R, REL_THRESH);
 
  set_register(0x5A, ELE9_T, TOU_THRESH);
  set_register(0x5A, ELE9_R, REL_THRESH);
 
  set_register(0x5A, ELE10_T, TOU_THRESH);
  set_register(0x5A, ELE10_R, REL_THRESH);
 
  set_register(0x5A, ELE11_T, TOU_THRESH);
  set_register(0x5A, ELE11_R, REL_THRESH);
 
  // Section D
  // Set the Filter Configuration
  // Set ESI2
  set_register(0x5A, FIL_CFG, 0x04);
 
  // Section E
  // Electrode Configuration
  // Set ELE_CFG to 0x00 to return to standby mode
  set_register(0x5A, ELE_CFG, 0x0C);  // Enables all 12 Electrodes
 
 
  // Section F
  // Enable Auto Config and auto Reconfig
  /*set_register(0x5A, ATO_CFG0, 0x0B);
  set_register(0x5A, ATO_CFGU, 0xC9);  // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V   set_register(0x5A, ATO_CFGL, 0x82);  // LSL = 0.65*USL = 0x82 @3.3V
  set_register(0x5A, ATO_CFGT, 0xB5);*/  // Target = 0.9*USL = 0xB5 @3.3V
}


boolean checkInterrupt(void){
  return digitalRead(irqpin);
}


void set_register(int address, unsigned char r, unsigned char v){
    Wire.beginTransmission(address);
    Wire.send(r);
    Wire.send(v);
    Wire.endTransmission();
}

//commence max communication!



void readpins(){ // Read pins (analog or digital)

  switch (messageGetChar()) { // Gets the next word as a character

    case 'd': // READ digital pins

    messageSendChar('d');  // Echo what is being read
    for (char i=2;i<14;i++) {
      messageSendInt(digitalRead(i)); // Read pins 2 to 13
    }
    messageEnd(); // Terminate the message being sent
    break; // Break from the switch

  case 'a': // READ analog pins

    messageSendChar('a');  // Echo what is being read
    for (char i=0;i<6;i++) {
      messageSendInt(analogRead(i)); // Read pins 0 to 5
    }
    messageEnd(); // Terminate the message being sent

  }

}

void writepin() { // Write pin

  int pin;
  int state;

  switch (messageGetChar()) { // Gets the next word as a character

    case 'a' : // WRITE an analog pin

    pin = messageGetInt(); // Gets the next word as an integer
    state = messageGetInt(); // Gets the next word as an integer
    pinMode(pin, OUTPUT); //Sets the state of the pin to an output
    analogWrite(pin, state); //Sets the PWM of the pin
    break;  // Break from the switch


    // WRITE a digital pin
  case 'd' :

    pin = messageGetInt();  // Gets the next word as an integer
    state = messageGetInt();  // Gets the next word as an integer
    pinMode(pin,OUTPUT);  //Sets the state of the pin to an output
    digitalWrite(pin,state);  //Sets the state of the pin HIGH (1) or LOW (0)
   

  }

}
17  Using Arduino / General Electronics / Re: help with optocouplers on: January 16, 2012, 01:38:56 pm
hey grumps

here is what my schematic looks like right now, resulting in the puny 5v output from the opto::


i have a TIP120, and wanted to ask you - would this possibly solve my problem?


thanks for hanging in there...
18  Using Arduino / General Electronics / Re: help with optocouplers on: January 16, 2012, 07:34:55 am
hey grumpy

i dont really know... but here is the LM schematic http://farm5.static.flickr.com/4084/4844649061_5724da5cce.jpg

is it drawing too much current?
19  Using Arduino / General Electronics / Re: help with optocouplers on: January 16, 2012, 07:14:14 am
i am trying to switch 12v LM386amps on and off. so i'm guessing the optocoupler transistor side can't handle 12volts?

20  Using Arduino / General Electronics / help with optocouplers on: January 15, 2012, 05:51:14 pm
i am trying to switch a 12v current on and off using a 4n25 optocoupler.

12v are hooked up to the collector - but when i turn on the diode - the emitter will only give me around 5 volts. i tried switching power supplies, even gave it 24v, which resulted in a 7v output from the emitter...

i have a digital pin connected to a 220ohm resistor to the anode, cathode goes to arduino ground.

i don't think the resistor between the arduino and the 4n25 is too big, the led should light up nicely... so where is all my current going?

any help would be greatly appreciated!!

thanks
21  Using Arduino / Sensors / Re: MPR121 simulated 13th pin on: January 07, 2012, 06:52:24 am
im talking about the pins on the MPR, not the arduino...
22  Using Arduino / Sensors / MPR121 simulated 13th pin on: January 06, 2012, 05:02:39 pm
hi guys

just started rocking out with my mpr121... it's great!

however, the twelve pins are not enaugh.i am making a one octave keyboard (c - c') so i need 13 touch sensors.

i wanted to know if you guys could give me some tips on how to make a "simulated 13th pin"? stuff to read etc...

any help would be greatly appreciated!
thank you

-úlfur
23  Using Arduino / General Electronics / Re: DIY EBOW to control LED brightness! on: January 03, 2012, 04:50:34 pm


i am still a novice at electronics.. but - does this make any sense?

any help would be greatly appreciated!
thanks
24  Using Arduino / General Electronics / DIY EBOW to control LED brightness! on: January 03, 2012, 11:30:34 am
hi guys

i am making an electromagnetic instrument, - basically a harp with 12 ebows on 36 strings. the ebows drive the strings, and are triggered with an arduino.

here is the prototype driving strings on a piano (i am currently building the harp)

i have worked everything out, but i really want to add a neat feature to the device. i would like to add an amber LED to each ebow, which brightness is controlled by the volume of the input signals coil.

here is the schematic i based my ebows on::


so, when a string is vibrating - the signal of the pick-up coil controls the brightness of the led.

can the LM386 drive a single LED by default? how would i implement this into the circuit? whats the most simple way to do this?

thanks!!
all the best
úlfur
25  Using Arduino / Project Guidance / Re: [help!] advice on an optocoupler array on: November 07, 2011, 10:34:12 am
hi, thanks for the reply!

so using the 220 ohm resistors i would be at risk of frying the arduino? or perhaps only if ALL optocouplers are triggered at once?

and -how do you mean, into the atmega?

26  Using Arduino / Project Guidance / [help!] advice on an optocoupler array on: November 07, 2011, 09:46:31 am
i am building a switch board with twelve 4n25 optocouplers, to be controlled by my arduino.

i intend to connect each digital pin of my duemilanove to a 220 OHM resistor and then into the led anode. cathode goes straight to ground.

i am not sure about the amperage of the couplers, but here is the datasheet :: http://www.vishay.com/docs/83725/4n25.pdf

so, my question is: is it safe to connect all these couplers to the digital pins at the same time? will it fry my chip?

thanks!
27  Using Arduino / Project Guidance / optocoupler trouble on: November 06, 2011, 04:02:14 pm
hi guys

i just wired up some coils to a 2n25 optocoupler. what it's supposed to do is turn the 9v battery on/off. picture included.

im currently running the blink program to switch the coils on and off, and it works...

BUT

for some reason the coils are much weaker when getting power from the transistor, than when i connect them directly to the battery.

i'm a real novice, but eager to learn. do you have any thoughts on this? why is the optocoupler sending out such a weak current?

thank you
28  Forum 2005-2010 (read only) / Interfacing / 6vdc solenoid help. on: March 31, 2009, 10:43:38 am
hello

i have the duemilanove board, and just found this 6v DC solenoid at a local workshop.

i read the pdfs on relays and solenoids, but i thought maybe the arduino's internal power supply of 5v might suffice for driving the solenoid to maybe hit a bell or something.

do i need a transistor to do this? or do the digital outputs of the arduino serve as on off switches for the solenoid?

also, code examples would be awesome....!

thanks guys
 smiley-wink

-dataplex
Pages: 1 [2]