Quantcast
Channel: Arduino - Processing 2.x and 3.x Forum
Viewing all 747 articles
Browse latest View live

How to make an image fade to another image when a certain amount of light falls on a LDR?

$
0
0

Hi, I have been trying to make an image transistion to another image when a certain amount of light falls on a LDR, and transistions back when that light is not shining on the LDR anymore. However, the piece of code is not working properly. I am new to processing, so there is a good chance that I am doing it completely wrong. It would be lovely if someone could help me achieve the fade in and out! Thanks in advance! Here is a part of my code, and what I have tried to do for the fade:

int transparency = 0;

void setup() {
  img = loadImage(imgFileName+"."+fileType);
  bla = loadImage("mermaid.jpg");
  size(img.width, img.height);
  image(img, 0, 0);

  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  arduino.pinMode(ledPin, Arduino.OUTPUT);
  arduino.pinMode(sensorPin, Arduino.INPUT);
}
void draw() {
      int analogValue =  arduino.analogRead(sensorPin);
      println(analogValue);

      if (analogValue > 900) {
        noTint();
        image(bla, 0, 0);
      } else {
        while (column < width-1) {
          img.loadPixels(); 
          sortColumn();
          column++;
          img.updatePixels();
        }

        while (row < height-1) {
          img.loadPixels(); 
          sortRow();
          row++;
          img.updatePixels();
        }

     if (transparency < 255) {
          transparency++; 
        }
        tint(255, 255, 255, transparency);
        image(img, 0, 0);
        //automatically save the image 
        if (!saved && frameCount >= loops) {
          saveFrame(imgFileName+"_"+mode+".png");
          saved = true;
        }
      }
    }

opengl or p3d

$
0
0

hello everyone, ...

i use P3D in my mputeapot.pde program for my arduino drive processing 3, and now as i change my pc machine, processing send me back this error : OpenGL error 1280 at bot beginDraw(): invalid enumerant

here is my code:

` import processing.serial.*; import processing.opengl.*; import toxi.geom.*; import toxi.processing.*;

// NOTE: requires ToxicLibs to be installed in order to run properly. // 1. Download from http://toxiclibs.org/downloads // 2. Extract into [userdir]/Processing/libraries // (location may be different on Mac/Linux) // 3. Run and bask in awesomeness

ToxiclibsSupport gfx;

Serial port; // The serial port char[] teapotPacket = new char[14]; // InvenSense Teapot packet int serialCount = 0; // current packet byte position int aligned = 0; int interval = 0;

float[] q = new float[4]; Quaternion quat = new Quaternion(1, 0, 0, 0);

float[] gravity = new float[3]; float[] euler = new float[3]; float[] ypr = new float[3];

void setup() { // 300px square viewport using OpenGL rendering size(300, 300, P3D); gfx = new ToxiclibsSupport(this);

// setup lights and antialiasing
lights();
smooth();

// display serial port list for debugging/clarity
println(Serial.list());

// get the first available port (use EITHER this OR the specific port code below)
String portName = "COM3";

// get a specific serial port (use EITHER this OR the first-available code above)
//String portName = "COM4";

// open the serial port
port = new Serial(this, portName, 115200);

// send single character to trigger DMP init/start
// (expected by MPU6050_DMP6 example Arduino sketch)
port.write('r');

}

void draw() { if (millis() - interval > 1000) { // resend single character to trigger DMP init/start // in case the MPU is halted/reset while applet is running port.write('r'); interval = millis(); }

// black background
background(0);

// translate everything to the middle of the viewport
pushMatrix();
translate(width / 2, height / 2);

// 3-step rotation from yaw/pitch/roll angles (gimbal lock!)
// ...and other weirdness I haven't figured out yet
//rotateY(-ypr[0]);
//rotateZ(-ypr[1]);
//rotateX(-ypr[2]);

// toxiclibs direct angle/axis rotation from quaternion (NO gimbal lock!)
// (axis order [1, 3, 2] and inversion [-1, +1, +1] is a consequence of
// different coordinate system orientation assumptions between Processing
// and InvenSense DMP)
float[] axis = quat.toAxisAngle();
rotate(axis[0], -axis[1], axis[3], axis[2]);

// draw main body in red
fill(255, 0, 0, 200);
box(10, 10, 200);

// draw front-facing tip in blue
fill(0, 0, 255, 200);
pushMatrix();
translate(0, 0, -120);
rotateX(PI/2);
drawCylinder(0, 20, 20, 8);
popMatrix();

// draw wings and tail fin in green
fill(0, 255, 0, 200);
beginShape(TRIANGLES);
vertex(-100,  2, 30); vertex(0,  2, -80); vertex(100,  2, 30);  // wing top layer
vertex(-100, -2, 30); vertex(0, -2, -80); vertex(100, -2, 30);  // wing bottom layer
vertex(-2, 0, 98); vertex(-2, -30, 98); vertex(-2, 0, 70);  // tail left layer
vertex( 2, 0, 98); vertex( 2, -30, 98); vertex( 2, 0, 70);  // tail right layer
endShape();
beginShape(QUADS);
vertex(-100, 2, 30); vertex(-100, -2, 30); vertex(  0, -2, -80); vertex(  0, 2, -80);
vertex( 100, 2, 30); vertex( 100, -2, 30); vertex(  0, -2, -80); vertex(  0, 2, -80);
vertex(-100, 2, 30); vertex(-100, -2, 30); vertex(100, -2,  30); vertex(100, 2,  30);
vertex(-2,   0, 98); vertex(2,   0, 98); vertex(2, -30, 98); vertex(-2, -30, 98);
vertex(-2,   0, 98); vertex(2,   0, 98); vertex(2,   0, 70); vertex(-2,   0, 70);
vertex(-2, -30, 98); vertex(2, -30, 98); vertex(2,   0, 70); vertex(-2,   0, 70);
endShape();

popMatrix();

}

void serialEvent(Serial port) { interval = millis(); while (port.available() > 0) { int ch = port.read(); print((char)ch); if (ch == '$') {serialCount = 0;} // this will help with alignment if (aligned < 4) { // make sure we are properly aligned on a 14-byte packet if (serialCount == 0) { if (ch == '$') aligned++; else aligned = 0; } else if (serialCount == 1) { if (ch == 2) aligned++; else aligned = 0; } else if (serialCount == 12) { if (ch == '\r') aligned++; else aligned = 0; } else if (serialCount == 13) { if (ch == '\n') aligned++; else aligned = 0; } //println(ch + " " + aligned + " " + serialCount); serialCount++; if (serialCount == 14) serialCount = 0; } else { if (serialCount > 0 || ch == '$') { teapotPacket[serialCount++] = (char)ch; if (serialCount == 14) { serialCount = 0; // restart packet byte position

                // get quaternion from data packet
                q[0] = ((teapotPacket[2] << 8) | teapotPacket[3]) / 16384.0f;
                q[1] = ((teapotPacket[4] << 8) | teapotPacket[5]) / 16384.0f;
                q[2] = ((teapotPacket[6] << 8) | teapotPacket[7]) / 16384.0f;
                q[3] = ((teapotPacket[8] << 8) | teapotPacket[9]) / 16384.0f;
                for (int i = 0; i < 4; i++) if (q[i] >= 2) q[i] = -4 + q[i];

                // set our toxilibs quaternion to new data
                quat.set(q[0], q[1], q[2], q[3]);

                /*
                // below calculations unnecessary for orientation only using toxilibs

                // calculate gravity vector
                gravity[0] = 2 * (q[1]*q[3] - q[0]*q[2]);
                gravity[1] = 2 * (q[0]*q[1] + q[2]*q[3]);
                gravity[2] = q[0]*q[0] - q[1]*q[1] - q[2]*q[2] + q[3]*q[3];

                // calculate Euler angles
                euler[0] = atan2(2*q[1]*q[2] - 2*q[0]*q[3], 2*q[0]*q[0] + 2*q[1]*q[1] - 1);
                euler[1] = -asin(2*q[1]*q[3] + 2*q[0]*q[2]);
                euler[2] = atan2(2*q[2]*q[3] - 2*q[0]*q[1], 2*q[0]*q[0] + 2*q[3]*q[3] - 1);

                // calculate yaw/pitch/roll angles
                ypr[0] = atan2(2*q[1]*q[2] - 2*q[0]*q[3], 2*q[0]*q[0] + 2*q[1]*q[1] - 1);
                ypr[1] = atan(gravity[0] / sqrt(gravity[1]*gravity[1] + gravity[2]*gravity[2]));
                ypr[2] = atan(gravity[1] / sqrt(gravity[0]*gravity[0] + gravity[2]*gravity[2]));

                // output various components for debugging
                //println("q:\t" + round(q[0]*100.0f)/100.0f + "\t" + round(q[1]*100.0f)/100.0f + "\t" + round(q[2]*100.0f)/100.0f + "\t" + round(q[3]*100.0f)/100.0f);
                //println("euler:\t" + euler[0]*180.0f/PI + "\t" + euler[1]*180.0f/PI + "\t" + euler[2]*180.0f/PI);
                //println("ypr:\t" + ypr[0]*180.0f/PI + "\t" + ypr[1]*180.0f/PI + "\t" + ypr[2]*180.0f/PI);
                */
            }
        }
    }
}

}

void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) { float angle = 0; float angleIncrement = TWO_PI / sides; beginShape(QUAD_STRIP); for (int i = 0; i < sides + 1; ++i) { vertex(topRadiuscos(angle), 0, topRadiussin(angle)); vertex(bottomRadiuscos(angle), tall, bottomRadiussin(angle)); angle += angleIncrement; } endShape();

// If it is not a cone, draw the circular top cap
if (topRadius != 0) {
    angle = 0;
    beginShape(TRIANGLE_FAN);

    // Center point
    vertex(0, 0, 0);
    for (int i = 0; i < sides + 1; i++) {
        vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
        angle += angleIncrement;
    }
    endShape();
}

// If it is not a cone, draw the circular bottom cap
if (bottomRadius != 0) {
    angle = 0;
    beginShape(TRIANGLE_FAN);

    // Center point
    vertex(0, tall, 0);
    for (int i = 0; i < sides + 1; i++) {
        vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
        angle += angleIncrement;
    }
    endShape();
}

}`

if you got and idea...thanks for all...

teapot is a plane..

$
0
0

B-) hi everyone..

in the teapot jeff rowberg's programm using mpu6050 , the picture is a plane ...

have you any pointing or url programs that's move a real teapot instead of a plane ?

tea

thank you.. :D

Bluetooth connection

$
0
0

I am encountering problems getting the Bluetooth talking.

I am using the blendmicro microcontroller which claims a arduino as its core, and it has bluetooth low energy 4.0 capability. so i have loaded arduino code simply "bt.begin()" to start broadcasting the bluetooth signals. The problems now is i couldn't see anything in the serial monitor in arduino, so I can't transmit the data serially to processing.

is there anyway that i can capture the data broadcast by blendmicro in processing or the way around capturing it in arduino and transfer it serially to processing?

I am using a mac.

I really appreciate your help! Thank you!

Moving a servo with camera motion detection.

$
0
0

Hello there, I follow the community since a couple of year, I usually found all the answers to my questions just lookin up for them, but this time I needed to write my first post. :) I'm workin on a university project in which I need to move a camera on x and y axes through two servos, one axis each, following the movement the camera detect...

I basically used the LiveCam example from OpenCV Github https://github.com/atduskgreg/opencv-processing/tree/master/examples/LiveCamTest

which does face recognition and tells the X position in the frame (I dont know why, but gives just 0-1 as Y position) I linked the values of faces[i].x and faces[i].y to the servo rotation angle (quite randomly, just for testing the connection to Arduino).

import gab.opencv.*;

import processing.video.*;

import java.awt.*;

import processing.serial.*;

import cc.arduino.*;

Capture video;

OpenCV opencv;

Arduino arduino;

void setup() {

size(640, 480);

arduino = new Arduino(this, Arduino.list()[0], 57600);

arduino.pinMode(4, Arduino.SERVO);

video = new Capture(this, 640/2, 480/2,30);

opencv = new OpenCV(this, 640/2, 480/2);

opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);

video.start();

}

void draw() {

scale(2);

opencv.loadImage(video);

image(video, 0, 0 );

noFill();

stroke(0, 255, 0);

strokeWeight(3);

Rectangle[] faces = opencv.detect();

println(faces.length);

for (int i = 0; i < faces.length; i++) {

println(faces[i].x + "," + faces[i].y);

rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);

arduino.servoWrite(4, constrain(180 - faces[i].x, 0, 180));

arduino.servoWrite(5, constrain(faces[i].y, 180, 0)); }

}

void captureEvent(Capture c) {

c.read(); }

My main question is: How to interface the detection on the 180º on x and y... I mean, it would be quite easy to calibrate it on a static frame, the problem comes when the camera is moving following the "target" movement and has to continue following it through the 180º. (Probably telling it to keep the subject centered?)

the secondary questions are: Face detection is a s**t for my purpose... I mean, if the face is not watching to the camera, it doesn't detect it. So I think I'll need to use something like Blob detection, based on movement and here comes others complication: First of all, I can't link other examples to live camera but face detection... then: Using some kind of Motion detection, will it get confuse having a moving camera?

Hope that everything is quite clear... thanks for your time. :)

working with images

$
0
0

ey, hi, guys, I'm new here.

I'm looking for a way to put images on the canvas. I need them to appear at a random position when I send a float from pure data through OSC (this is resolved, I'm already using OSC to control some things in processing). also I need to control the size of the images, I need to animate this image (just a few frames) AND I need to make it disappear after x miliseconds. I would like these images to have an alpha, so I can see the background behind the silhouette. let me explain what i'm working at: I want to create an image when a bass drum sounds (this is done by pure data and ableton). the bass drum it's just like 200 miliseconds, so I need to put and image and this should automatically disappear after 200 miliseconds.

hope you understand!

thanks in advance!

collecting, averaging & ignoring duplicate serial data

$
0
0

Hey, I'm trying to receive data from the serial port, collect a sample group ('numReadings'), average it ('average'), and print it to screen only if the new average ('average') isn't equal to the old average ('previousAverage').

Below I have some really horrible code, trying to illustrate the idea, but i'm having trouble pulling it all together and amn't 100% if this is the best way to do it.

Would really appreciate if anyone was able to offer advice!

Cheers,

Ross

import processing.serial.*;

Serial myPort;
int numReadings = 512;
int readIndex = 0;
int total = 0;
int average = 0;
int previousAverage = 0;
int[] readings = new int[numReadings];

void setup() {

  size(640, 640);
  background(30);
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('n');
}

void draw() {
}

void serialEvent (Serial MyPort) {

    for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }

  String inString = myPort.readStringUntil('\n');

  if (inString != null){
    inString = trim(inString);
  }

  total = total - readings[readIndex];
  readings[readIndex] = inString;
  total = total + readings[readIndex];
  readIndex = readIndex + 1;


  if (readIndex >= numReadings) {
  readIndex = 0;
  }

average = total / numReadings;

if (average != previousAverage) {
println(average);
}
  previousAverage = average;
}

Processing 2.2.1 (i need to update i know) Windows 8

receiving serial data and displaying it problems with 3dr radio

$
0
0

Hi , I have just started using processing but have been using arduino for a couple of years . I am using this code to display csv data on my computer https://github.com/sebnil/RealtimePlotter. When i receive the data throug the usb cable everything works as it should how ever when i receive it though the 3dr radio gets messed up the strange thing though is that if i view the data from the 3dr radio in the serial monitor it reads perfect . Its not complete rubbish like when the baud rate is wrong it just misses some characters , this is even when i send the data at only about 100 characters per second . Does any one have an idea whats going on here ?


Arduino-based GPS System

$
0
0

I want to make a GPS system using an Arduino (Uno, R3). I want the GPS data to be sent to a Processing sketch on my laptop. Will it work if I use AltSoftSerial and the UART on the Arduino to reliably receive GPS data and transmit it to my laptop? What should be connected to the software serial port and what should be connected to the UART? What speeds should I use? Thanks in advance for your help.

How to connect Arduino to processing

$
0
0

Hi,

I am new to the Arduino world and i am trying to program the TFT lights in Arduino to change colour in processing. I was wondering if someone could be kind enough to explain what i need to do? what libraries may i need and how to do this?

Regards

Can you add code into standard firmata to make a design on a tft screen?

$
0
0

Can you add code into standard firmata to make a design on a tft screen?

How do i get the code to display at the same time of 2 screens

$
0
0

I have 2 1.4TFT screens wired up to an Arduino board and only one is displaying the graphic. How do i get it to display both at the same time?

Arduino code

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

#define TFT_CS   (4, 10)
#define TFT_RST  (3, 9)
#define TFT_DC   (2, 8)
#define TFT_SCLK (7, 13)
#define TFT_MOSI (5, 11)

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

void setup(void) {
  tft.initR(INITR_144GREENTAB);   // initialize a ST7735S chip, black tab
  testdrawrects(ST7735_WHITE);
}

void loop() {
  tft.invertDisplay(false);
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

ArrayIndexOutOfBoundsException error in code

$
0
0

Hi!

I'm trying to visually show a heartbeat with processing, the code that detects the heartbeat is from Arduino (downloaded from pulsesensor.com, who make the sensor). The manufacturer also provides a processing code, but I get the following error when I try to run it:

ArrayIndexOutOfBoundsException: 9 in the following line of code:

port = new Serial(this, Serial.list()[9], 115200); // make sure Arduino is talking serial at this baud rate

I'm very new to processing (and Arduino), but to me it seems like it doesn't like the [9]. However, I have no idea what to change it to. What should I replace the 9 for (or what is wrong with the line) to make it work?

Thanks!

arduino.pulseIn(int,int) and Processing

$
0
0

`import processing.serial.*; import cc.arduino.*;

Arduino arduino;

int l = 0; int r=-180; int t; float z;

void setup() { frameRate(40); size(500, 500); println(Arduino.list()); arduino = new Arduino(this, Arduino.list()[0], 57600); arduino.pinMode(10, Arduino.SERVO); arduino.pinMode(8, Arduino.INPUT); }

void draw() { translate(250, 250); background(250); screen();

strokeWeight(3); stroke(0, 255, 0); strokeWeight(2); if (l>=-181 ) { l--; t=1; z = radians(l); } if (l<-180) { r++; t=r; z = radians(r); } if (r==0) { r=-180; l=0; }

pushMatrix(); rotate(z); line(0, 0, 100, 0); popMatrix(); }

void screen() { stroke(0); fill(0); arc(0, 0, 200, 200, PI, TWO_PI); }

void ar(){ arduino.servoWrite(10, t);
arduino.digitalWrite(8, Arduino.HIGH); arduino.pulseIn(8, Arduino.HIGH); }`

pulseIn(int,int); is not a function, Can I add this to the arduino library or would it not work for processing even if added? Or is there another way to use a ping sensor in processing?

Finding the right serial port for Arduino

$
0
0

Hi guys, in my project i have to communicate with arduino by the serial port. I'm using this code:

port = new Serial(this, Serial.list()[0], 115200);

But is there a way to find automatically the right port? because on others computers i have always to change the number of port, like 1 or 2. Is there a command that can do that?

Thank you


How can i use Keypressed instead of mouse position in processing to work with arduino?

$
0
0

Hi, so this is my code so far and all works well. However i would like to use 3 hotkeys to change the colour than mouse position.

Anyone know how i can do this?

Thanks

Processing code

   import processing.serial.*;
   Serial port;
   int c;

   void setup() {
     size(300, 150);
    // println("Available serial ports:");
    // println(Serial.list());
    port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
    c = 2;
   }

  void draw() {
  background(255);
  line(100, 0, 100, height);
  line(200, 0, 200, height);
   // write the current X-position of the mouse to the serial port as
  // a single byte

 int newc = int(1 + mouseX/100);
 if (newc != c) {
 c = newc;

println(">> " + c); // DEBUG
port.write("" + c);
 }
}

Arduino code

   #include <Adafruit_GFX.h>    // Core graphics library
   #include <Adafruit_ST7735.h> // Hardware-specific library
   #include <SPI.h>

   #define TFT_CS     10
   #define TFT_RST    9
   #define TFT_DC     8
   #define TFT_SCLK 13
   #define TFT_MOSI 11

   Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

   void setup(void) {
     Serial.begin(9600);
     tft.initR(INITR_144GREENTAB);
     tft.fillScreen(ST7735_BLACK);
     Serial.println("OK!");
   }

   void loop() {
     tft.invertDisplay(false);
     if (Serial.available()) {
       byte c = Serial.read();
       if (c == '1') {
         testdrawrects(ST7735_GREEN);
       } else if (c == '2') {
         testdrawrects(ST7735_WHITE);
       } else if (c == '3') {
         testdrawrects(ST7735_RED);
       }
       Serial.println(c); // DEBUG
     }
   }

   void testdrawrects(uint16_t color) {
     // tft.fillScreen(ST7735_BLACK);
     for (int16_t x=0; x < tft.width(); x+=6) {
       tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
     }
   }

Cannot parse a string from serial

$
0
0

A week ago I wrote a little sketch that reveals a bitmap pixel by pixel based on mouse coordinates. Thanks to the good people here it works like a charm. If you're interested, here it is:

import processing.serial.*; //import the Serial library

Serial myPort;  //the Serial port object

PImage img;

void setup()
{

  size(182,262);  //This is the size of the canvas and the range of the printer
  // Make a new instance of a PImage by loading an image file
  img = loadImage("parel.bmp");
  tint(255,100);
  image (img,0,0);

}


void draw()
{
  color pix = img.get(mouseX, mouseY);
  stroke(pix);
  point(mouseX, mouseY);
}

So I am trying to expand this sketch by receiving pixel data from my arduino. I wrote a little arduino sketch that systematically sends all the pixel coordinates in the bitmap mentioned above over serial. And that seems to work too. But Processing is giving me some trouble here when I try to receive the coordinates over serial. Here's the sketch:

import processing.serial.*; //import the Serial library

Serial myPort;  //the Serial port object
String strIn = "";  //Declare a string with name str_in, this will store the coordinates received from the arduino
String portName = "";  //apparently this is necessary
int coordinates;
int locX= 0;
int locY= 0;

PImage img;

void setup()
{

  size(182,262);  //This is the size of the canvas and the range of the printer
  // Make a new instance of a PImage by loading an image file
  img = loadImage("parel.bmp");
  tint(255,100);
  image (img,0,0);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName,9600);
}


void draw()
{
  while (myPort.available() > 0) {                 // If data is available,
  strIn = myPort.readStringUntil('\n');         // read it and store it in a string called strIn
  }
  int[] coordinates = int(split(strIn, ","));
  //This should cut the strIn string in two integers, separated by a space
  //and called coordinates. We expect a message coming in something like "XXX YYY"
  int locX = coordinates[0];        //This says that the first integer is an integer called LocX
  int locY = coordinates[1];       //This says that the first integer is an integer called LocX
  color pix = img.get(locX, locY);
  stroke(pix);
  point(locX, locY);
}

The debugger tells me it stores the incoming serial message in the strIn string, but locX and locY remain at 0. If I run the sketch without the debugger I get an arrayindexoutofboundsexception in line 34, which I think means it doesn't store anything in LocY. From what I read on this forum, I get that serial communication is troubling a lot more people than just me, but I can't find what the problem is. So if anybody has any ideas, you'd be a great help. My bitmap image is attached here as well.

parel

Heart beat sensor , play a song of a similiar BPM to match the BPM of the heart sensor?

$
0
0

Hi , im new to Arduino stuff , but i have a project where by i want the bpm of the heart sensor to play a song of a similiar bpm through processing , i would like to have a library of say 5 songs or so , if anyone has any advice or help that would be greatly appreciated thank you

Servoing how is it done using the OpenCV for Processing and Arduino Serial ?

$
0
0

im trying to use something like IK or FK for controlling a Array of motors with chain like connection "one moves rest follows" according to serial communication that is since Arduino is the MCU running the functions

Create a graph (live-feed or after data collection) of sensor data from an Arduino serial port

$
0
0

Hi,

I have a code which takes data from 2 sensors that is incoming through the serial port of an Arduino and outputs it into a .csv file. This data is received as a float of the format "y, x" which is then delimited/split by the use of the comma and put into an array. The "y" data is a depth in mm measurement and the "x" is a correlating distance moved in mm.

I have been trying to get the code to output either a live-feed line graph or a line graph after the file is written with data "x" on the x-axis and "y" on the y-axis.

My experience with Processing is very limited and I have tried with no luck to adapt pretty much all of the examples I could find on the various forums and tutorials. Any help that could be offered would be very gratefully received, I don't mind if the solution is live-feed or after the .csv is written just having a graph out would be great.

Below I have shown a plot I did manually in excel to show the kind of output I am trying to get as well as the code I have got already which I have annotated on to try to make understanding my process as pain-free as possible.

Output_Example

import processing.serial.*;
Serial myPort; //creates a software serial port
Table dataTable; //table where values are stored
Table table;

int numReadings = 500; //number of readings from sensors until .csv file is written
int readingCounter = 0; //counts each reading to compare to numReadings.

String val;
String fileName;

void setup()
{
  String portName = Serial.list()[0]; //defines COM port

  myPort = new Serial(this, portName, 9600); //port setup, 9600 baud rate

  table = new Table();

  //table.addColumn("id"); //id number for incoming data starting

  //the following adds columns for time. (currently not used)
  //table.addColumn("year");
  //table.addColumn("month");
  //table.addColumn("day");
  //table.addColumn("hour");
  //table.addColumn("minute");
  //table.addColumn("second");
  //table.addColumn("milliseconds");

  //the following adds columns for each sensor set. Change for sensors and keep in correct order.
  table.addColumn("Depth");
  table.addColumn("Width");

}

void serialEvent(Serial myPort){

  try {
  val = myPort.readStringUntil('\n'); //The newline separator separates each Arduino loop and so collection of data.
  if (val!= null) { //Verifies reading
    val = trim(val); //gets rid of any whitespace or Unicode nonbreakable space
    println(val); //Shows received data
    float sensorVals[] = float(split(val, ',')); //parses the packet from Arduino and places the float values into the sensorVals array.

    TableRow newRow = table.addRow(); //adds a row for new reading
    //following not used at present
    //newRow.setInt("id", table.lastRowIndex());//record an id for readings

    //record time stamp
    //newRow.setInt("year", year());
    //newRow.setInt("month", month());
    //newRow.setInt("day", day());
    //newRow.setInt("hour", hour());
    //newRow.setInt("minute", minute());
    //newRow.setInt("second", second());

    //record sensor information. Make sure same as sensor column names.
    newRow.setFloat("Depth", sensorVals[0]);
    newRow.setFloat("Width", sensorVals[1]);

    readingCounter++; //writes file every numReadings reading cycles

    //saves the table as a csv in the same folder as the sketch every numReadings.
    if (readingCounter % numReadings ==0)//checks number of readings is correct
    {
      fileName = str(year()) + str(month()) + str(day()) + str(table.lastRowIndex()); //filename is of the form year+month+day+readingCounter
      saveTable(table, fileName + ".csv"); //saves the data as a .csv
    }
   }
  }
  catch(RuntimeException e) {//catches errors
    e.printStackTrace();
  }

}

void draw () {

}

Sam

Viewing all 747 articles
Browse latest View live