capacitive touch and grounding GPIO

Hi, I am trying to modify this tutorial code to

  • Active 6 different pins via a capacitive touch piece of metal I have
  • I want to send the output to the GPIO of my raspberry pi (USB communication is not an option in this case)

My Raspberry pi script calls for my GPIO 17 to be grounded.

Can someone help my tweak this code so that I can trigger 6 pins and only activate the pins when the metal is touched?

Thanks for any help!

/*
  Arduino Starter Kit example
 Project 13  - Touch Sensor Lamp
 
 This sketch is written to accompany Project 13 in the
 Arduino Starter Kit
 
 Parts required:
 1 Megohm resistor
 metal foil or copper mesh
 220 ohm resistor
 LED
 
 Software required : 
 CapacitiveSensor library by Paul Badger
 http://arduino.cc/playground/Main/CapacitiveSensor
 
 Created 18 September 2012
 by Scott Fitzgerald
 
 http://arduino.cc/starterKit
 
 This example code is part of the public domain 
 */

// import the library (must be located in the
// Arduino/libraries directory)
#include <CapacitiveSensor.h>

// create an instance of the library
// pin 4 sends electrical energy
// pin 2 senses senses a change
CapacitiveSensor capSensor = CapacitiveSensor(4,2);

// threshold for turning the lamp on
int threshold = 1000;

// pin the LED is connected to
const int ledPin = 12;


void setup() {
  // open a serial connection
  Serial.begin(9600);
  // set the LED pin as an output
  pinMode(ledPin, OUTPUT);
  Keyboard.begin();
}

void loop() {
  // store the value reported by the sensor in a variable
  long sensorValue = capSensor.capacitiveSensor(30);

  // print out the sensor value
  Serial.println(sensorValue); 

  // if the value is greater than the threshold
  if(sensorValue > threshold) {
    // turn the LED on
    digitalWrite(ledPin, HIGH);
    if(digitalRead(12)==HIGH){
    delay(125);      
    }
  }
  // if it's lower than the threshold
  else {
    // turn the LED off
    digitalWrite(ledPin, LOW);
    delay(100);
  }

  delay(10);
}

My Raspberry pi script calls for my GPIO 17 to be grounded.

Because the Pi is a 3V3 system and the Arduino is a 5V system you can not connect them directly. They need to go through a potential divider.

Using 6 pins running cap sense is not going to be very stable.

oooooo :( this didnt even cross my mind. So, not even by using a resistor between the leonardo output and the gpio of the RPI would work?

No you need two resistors in a potential divider. http://blog.oscarliang.net/raspberry-pi-and-arduino-connected-serial-gpio/

So if I am understanding this correctly, I apologize as this is the first time I am trying to communicate these two devices together, each output from the Leo will need a 1.6k (white wire) and a 3.3k (from ground).

Theoretically what Im thinking is: If I am running each Leo output (6 pins total) to a 1 of 6 pi’s, each white wire would go to the desired pi GPIO 17 with a 1.6k along the white then every one of these white wires will feed to the same ground wire but be split 6 ways.

Please see the diagram Ive created.

Will this in fact register on the pi, when I ground by touching a piece of capacitive metal as GPIO being grounded?
What is the red wire for in the example you referenced?
Can the two resistor be soldered at one end then continue to the rpi?

Thank you very much for the reply!

diagram.jpg

So if I am understanding this correctly, I apologize as this is the first time I am trying to communicate these two devices together, each output from the Leo will need a 1.6k (white wire) and a 3.3k (from ground).

Yes

then every one of these white wires will feed to the same ground wire but be split 6 ways.

Yes.

Will this in fact register on the pi, when I ground by touching a piece of capacitive metal as GPIO being grounded?

What is capacitive metal? This will register when you ground any Pi pin, providing you:- 1) Set the Arduino pin to be an output and make that output HIGH. 2) Set the Pi GPIO to be an input with the pull up resistors enabled.

Do not ground an Arduino pin that is set to an output and that output is HIGH, you will burn it out or at least damage that pin.

What is the red wire for in the example you referenced?

For sending serial data from the Pi to the Arduino. Note that the example was specifically about serial data but it applies to ANY GPIO pin. Why do you want to use 6 Pis? There is something you are not understanding. This sounds like an X-Y Problem

I didnt want to bog down the post with my whole project detail. But here it is none the less.

I am running an interactive video program on my PI, that when GPIO 17 is grounded movie1 swaps with move2. Upon ungrounding of GPIO 17, movie1 returns to play.

Since I cannot easily sync all the pi data across a network, it's well beyond my skill set, I was planning on on running the video player across 6 independent pi's then run one Arduino, 6 output pins and one input from a capacitive piece of steel handle.

Once triggered, the output would communicate to the 6 pi's that their individual GPIO 17 is grounded to activate the interaction.

across 6 independent pi's then run one Arduino, 6 output pins and one input from a capacitive piece of steel handle.

Why do you need 6 outputs from the Arduino? A single output going through those two resistors can be connected to the GPIO pins of all the Pis. Remember to make the ground on all 6 Pis and the Arduino common.

Really? :o

That's awesome, it appears that everything is sharing the same ground according to the diagram.

|356x500

i think I might have a useful piece of hardware from an old computer that might make this easier.

So the code I previously posted in the first post would work by using the diagram you originally sent and splitting the white wire out into 6 wires after the resistors.

I should probably use a breadboard for ease of setup.

So the code I previously posted in the first post would work by using the diagram you originally sent and splitting the white wire out into 6 wires after the resistors.

Yes.

I should probably use a breadboard for ease of setup.

I would always advise against solderless bread board it is notoriously unreliable.

Would you suggest then that I hard wire (solder) all of this together? I'm not sure where I can get a soldered perf-board in short notice. I only have 2 days before this project is due and I have been trying to trouble shoot this for some time.

I really appreciate your time and advice. Thank you! 8)

Would you suggest then that I hard wire (solder) all of this together?

Yes.

I can get a soldered perf-board in short notice.

Farnell or Rapid Ekevctronics

@Grumpy_mike

can the resistors be soldered together along with 6 wires going to each pi?

Another question, but this may not be the correct place to post,

In order to ensure the the capacitive charge is detected, it is probably best to have people stand on a rubber mat to ensure they are grounded?

If I cannot find a 1.6k ohm resistor, is there another option I can try? The local Fry's electronics carries a 1.5k ohm but not 1.6k

can the resistors be soldered together along with 6 wires going to each pi?

Not sure what you are describing but you can solder up anything that is topologically equivalent to the circuit.

it is probably best to have people stand on a rubber mat to ensure they are grounded?

No. Standing on a rubber mat ensures that you are not grounded, but either way it is the bulk effect of your body that affects the capacitance you are measuring.

If I cannot find a 1.6k ohm resistor, is there another option I can try? The local Fry's electronics carries a 1.5k ohm but not 1.6k

While that link uses 1K6 and 3K3, I always use 510R and 1K which perhaps are easier to find. But a 1K5 will do fine.

Not sure what you are describing but you can solder up anything that is topologically equivalent to the circuit.

Thank you for the replies! What I am referring to is in the diagram where the two resistors are nearest the white wire, could I solder them both at their ends as well as the wires that will go out to each of the pi's, without causing any voltage problems.

it appears something like this is available at my local electronics shop:

http://www.frys.com/product/997786?site=sr:SEARCH:MAIN_RSLT_PG

http://www.frys.com/product/7307634;jsessionid=BOhF+2tokz7vyMR-4ZbH8A__.node3?site=sr:SEARCH:MAIN_RSLT_PG

chuco61: Thank you for the replies! What I am referring to is in the diagram where the two resistors are nearest the white wire, could I solder them both at their ends as well as the wires that will go out to each of the pi's, without causing any voltage problems.

Sorry still can't follow what you mean. That diagram has three white sections of wire.

The physical arrangement does not matter in this case so long as the schematic it follows is correct. In other words you can stretch or shrink the length of any wire, just so long as they follow the right route.

Those resistors look fine.

Grumpy_Mike:
Sorry still can’t follow what you mean. That diagram has three white sections of wire.

The physical arrangement does not matter in this case so long as the schematic it follows is correct. In other words you can stretch or shrink the length of any wire, just so long as they follow the right route.

Those resistors look fine.

Sorry for not explaining it better. this is what I mean, where the actual wires of the resistors are soldered directly together along with the 6 wires going to individual pi’s. I attached a new diagram.

Thank you so much for your quick replies and feedback, i really appreciate it

diagram.jpg