Solving problems

Last night, we worked a bit more when we got home and tried on getting the ultrasonic and capacitive sensor to be read at the same time in arduino. We also wanted to get the values printed in processing, but we were getting an OutOfBounds array error and we decided to call it a night.

The next day, I went to school and setup the arduino and breadboard. I noticed some of the wiring was wrong from the other night, corrected it and it worked perfectly in Arduino. Alright, one down.

Next, I looked at the Processing code from the last night and started tinkering with it. I resorted to rubberducking the code to Julien and he found the mistake, basically a basic declaration problem.

Arduino Code:


#include "mpr121.h"
#include 

int irqpin = 2; // Digital 2
boolean touchStates[12]; //to keep track of the previous touch states
const int pingPin = 7; //---added for ping
long duration, inches, cm; //---added for ping

void setup(){
pinMode(irqpin, INPUT);
digitalWrite(irqpin, HIGH); //enable pullup resistor

Serial.begin(9600);
Wire.begin();

mpr121_setup();
}

void loop(){
readTouchInputs();
GetPing();

Serial.print(cm);
Serial.print( "," );
Serial.print( touchStates[2] );
Serial.print( "," );
Serial.println( touchStates[8] );
delay( 50 );
}

// DOWN FROM HERE STARTS CODE FOR CAPACITIVE SENSOR
void readTouchInputs(){
if(!checkInterrupt()){
//read the touch state from the MPR121
Wire.requestFrom(0x5A,2);

byte LSB = Wire.read();
byte MSB = Wire.read();

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 &amp; (1&lt;<i> 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  0) {
val = myPort.readStringUntil(10);

if (val != null) {
val = trim(val);
int[] data = int(split(val, ','));
//println(data);

int ultrasonic = data[0];
int port2 = data[1];
int port8 = data[2];

println("ultrasonic: " + data[0]);
println("port 2: " + data[1]);
println("port 8: " + data[2]);
//
//

if (port2 == 1) {
background(255);
} else if (port8 == 1) {
background(255, 255, 51);
} else {
background(0);
}

//float distance = map(ultrasonic, 0, 100, 30, 150);
int distance = (int) map(ultrasonic, 0, 100, 30, 150);
ellipse(width/2, height/2, distance, distance);
}

}

}


Results:

 

Leave a comment

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started