Capacitive Sensor data 3D Wiew

edited March 2014 in Arduino
Hi

I ask for your help in the 3D sensor data view in Processing  "3D Column"
If you know a sample to share, help a lot!

see attached arduino sample code:



                           #include <CapacitiveSensor.h>

                            CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        
                            CapacitiveSensor   cs_4_5 = CapacitiveSensor(4,5);        
                            CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        

                            void setup()                    
                            {

                               cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     
                               Serial.begin(9600);

                            }

                            void loop()                    
                            {
                                long start = millis();
                                long total1 =  cs_4_2.capacitiveSensor(30);
                                long total2 =  cs_4_5.capacitiveSensor(30);
                                long total3 =  cs_4_8.capacitiveSensor(30);

                                Serial.print(millis() - start);        
                                Serial.print("\t");                    

                                Serial.print(total1);                  
                                Serial.print("\t");
                                Serial.print(total2);                
                                Serial.print("\t");
                                Serial.println(total3);               

                                delay(10);                           
                            }



Thanks

Answers

  • edited March 2014

    are we sure that this is processing / JAVA?

    Looks more like C / C++ / C#

  • when posting code:

    in the IDE:

    • click crtl-t

    • good indents

    in the browser:

    • paste it

    • leave 2 empty lines before it

    • mark / select entire code

    • then click C in the command bar

    • then Save

    Greetings Chrisir

  • please look here

    http://forum.processing.org/two/discussion/comment/11741#Comment_11741

    it's 2D but you can make it easily 3D

  • like this...

    int BAR_WIDTH = 20; // Use 4 for 256 values...
    
    void setup()
    {
      size(1024, 600, OPENGL);
      noLoop();
    
      String receivedValues = "54,545,61,646,110,1011,77,55,64,11,266,747"; // Random...
      int[] values = int(receivedValues.split(","));
    
      for (int x = 0; x < values.length; x++)
      {
        float val = map(values[x], 0, 1024, 0, height);
    
        pushMatrix();
    
        translate (BAR_WIDTH * x, height - (val/2), -29);
    
        // x,y,z
        box( BAR_WIDTH, val, BAR_WIDTH);
    
        popMatrix();
      }
    }
    //
    
  • edited March 2014

    Are we sure that this is Processing / JAVA? Looks more like C / C++ / C#

    @Chrisir, he's mentioned that was Arduino code. Arduino uses C instead of Java! And its draw() is called loop() too!

    image alt text

  • edited March 2014

    { PROCESSING SKETCH

        // Sensor orientation: corner 0,0 top left
        // Number of columns and rows in the grid
    
    
    
                int cols = 7;
                int rows = 10;
    
                // Declare 2D array
                float[] myArray = new float[cols*rows];
    
    
                 import processing.serial.*;
    
    
                 Serial myPort;
    
                 void setup() {
                  size(720, 720);
    
    
                  // List all the available serial ports
                  println(Serial.list());
                  // I know that the first port in the serial list on my mac
                  // is always my  Arduino, so I open Serial.list()[0].
                  // Open whatever port is the one you're using.
                  myPort = new Serial(this, Serial.list()[5], 9600);
                  // don't generate a serialEvent() unless you get a newline character:
                  myPort.bufferUntil('\n');
                  }
    
                  void draw() {
    
                  }
    
                  void serialEvent(Serial myPort) { 
                  // get the ASCII string:
                  String inString = myPort.readStringUntil('\n');
    
                  if (inString != null) {
                  // trim off any whitespace:
                  inString = trim(inString);
                  // split the string on the commas and convert the 
                  // resulting substrings into an integer array:
                  float[] myArray = float(split(inString, ","));
                  // if the array has at least three elements, you know
                  // you got the whole thing.  Put the numbers in the
                  // color variables:
                  println("Arrivato");
                  if (myArray.length >=64) {
    
                    for (int i = 0; i < cols; i++) {
                      for (int j = 0; j < rows; j++) {
                        stroke(255);
                        println("valori i=" + i + " j="+ j + "val=" + int(myArray[(i*rows)+j]));
                        fill(int(myArray[(i*rows)+j]));
                        rect(i*90,j*90,90,90); 
                       }
                    }
    
                  }
                  }
                  }
    
  • edited March 2014
    ***************************************************************
    8 x 8 sensor with Arduino Mega
    **************************************************************
    
    
    
    /*
    This example reads the output of an 8x8 matrix resistive sensor
     and sends its values serially. The Processing program at the bottom
     take those values and use them to change the background grey level of a 
     matrix on the screen.
    
    The circuit:
    Arduino digital outputs attached to 8 rows of sensor. 
    Arduino analog inputs attached to 8 columns of sensor with 1.5k pull down resistors.
    
    Sensor orientation: row 0, column 0 are the ones near the connectors.
    
    
    
            int Pin0 = A0;        // sensor attached to analog Pin0
            int Pin1 = A1;        // sensor attached to analog Pin1
            int Pin2 = A2;        // sensor attached to analog Pin2
            int Pin3 = A3;        // sensor attached to analog Pin3
            int Pin4 = A4;        // sensor attached to analog Pin4
            int Pin5 = A5;        // sensor attached to analog Pin5
            int Pin6 = A6;        // sensor attached to analog Pin6
    
    
            int dPin[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; //declaration of the pins we will use; i is the position within the array; i = 0 corresponds to output 2
            int i = 0;
    
            int sensorValue0 = 0; //value read from line 0 of the sensor
            int sensorValue1 = 1; //value read from line 1 of the sensor
            int sensorValue2 = 2; //value read from line 2 of the sensor
            int sensorValue3 = 3; //value read from line 3 of the sensor
            int sensorValue4 = 4; //value read from line 4 of the sensor
            int sensorValue5 = 5; //value read from line 5 of the sensor
            int sensorValue6 = 6; //value read from line 6 of the sensor
    
    
            int msensorValue0 = 0; // mapped value read from line 0 of the sensor
            int msensorValue1 = 1; // mapped value read from line 1 of the sensor
            int msensorValue2 = 2; // mapped value read from line 2 of the sensor
            int msensorValue3 = 3; // mapped value read from line 3 of the sensor
            int msensorValue4 = 4; // mapped value read from line 4 of the sensor
            int msensorValue5 = 5; // mapped value read from line 5 of the sensor
            int msensorValue6 = 6; // mapped value read from line 6 of the sensor
    
    
            void setup() {
    
              for (int i = 9; i >= 0 ; i--) {
            pinMode(dPin[i], OUTPUT);             //declaration of pin[i] as an OUTPUT
    
            pinMode (Pin0, INPUT);
            pinMode (Pin1, INPUT);
            pinMode (Pin2, INPUT);
            pinMode (Pin3, INPUT);
            pinMode (Pin4, INPUT);
            pinMode (Pin5, INPUT);
            pinMode (Pin6, INPUT);
            pinMode (Pin7, INPUT);
            pinMode (Pin8, INPUT);
            pinMode (Pin9, INPUT);
    
            }
              Serial.begin(9600);   //turn serial on
            }
    
            void loop(){
    
             for (int i = 9; i >= 0 ; i--) { 
    
              digitalWrite (dPin[i], HIGH); //turn row i on 
              sensorValue0 = analogRead (Pin6); //read value column 0
              // wait 10 milliseconds before the next loop
              // for the analog-to-digital converter to settle
              // after the last reading:
               delay(10);
              sensorValue1 = analogRead (Pin5); //read value column 2
              delay(10);
              sensorValue2 = analogRead (Pin4); //read value column 3
              delay(10);
              sensorValue3 = analogRead (Pin3); //read value column 4
              delay(10);
              sensorValue4 = analogRead (Pin2); //read value column 5
              delay(10);
              sensorValue5 = analogRead (Pin1); //read value column 5
              delay(10);
              sensorValue6 = analogRead (Pin0); //read value column 5
              delay(10);
              digitalWrite (dPin[i], LOW); //turn row i off 
    
    
              msensorValue0 = map (sensorValue0, 0, 1023, 255, 0);    //map all values read to a new range from 255 to 0
              msensorValue1 = map (sensorValue1, 0, 1023, 255, 0);
              msensorValue2 = map (sensorValue2, 0, 1023, 255, 0);
              msensorValue3 = map (sensorValue3, 0, 1023, 255, 0);
              msensorValue4 = map (sensorValue4, 0, 1023, 255, 0);
              msensorValue5 = map (sensorValue5, 0, 1023, 255, 0);
              msensorValue6 = map (sensorValue6, 0, 1023, 255, 0);
    
    
              Serial.print(msensorValue0);   //print first value on the serial port
              Serial.print(',');             // print comma
              Serial.print(msensorValue1);   //print second value on the serial port
              Serial.print(',');            //.....
              Serial.print(msensorValue2);
              Serial.print(',');
              Serial.print(msensorValue3);
              Serial.print(',');
              Serial.print(msensorValue4);
              Serial.print(',');
              Serial.print(msensorValue5);
              Serial.print(',');
              Serial.print(msensorValue6);
              Serial.print(',');
              if (i > 0){                   //don't print the comma at the end for the first 7 packages of data
              Serial.print(','); 
            }
            }
            Serial.println ();   //print a blank line - this line is important because Processing will start a serial event only after reading this blank line. 
            }
    
Sign In or Register to comment.