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

Pulse Input Displayed to Processing Window

$
0
0

Hello! First time poster, new to Processing.

I was following the following tutorial on making a Pulse Sensor: https://www.youtube.com/watch?v=psTa5ZrqAyo

I was able to see output from a scope. I can therefore conclude output is being sent to the Arduino.

The code provided does not draw any pulse in Processing 3. I added a few lines, they are:

noFill();
stroke(0,255,0);
strokeWeight(4);

On lines 40-42. The rest is original code from the tutorial.

It is as follows:

    // Based on examples from Arduino's Graphing Tutorial and OscP5 documentation
    import processing.serial.*;
    Serial myPort; // The serial port
    int xPos = 1; // horizontal position of the graph
    float oldHeartrateHeight = 0; // for storing the previous reading


    void setup () {
    // set the window size:
    size(600, 400);
    frameRate(25);

    // List available serial ports.
    println(Serial.list());

    // Setup which serial port to use.
    // This line might change for different computers.
    myPort = new Serial(this, Serial.list()[0], 9600);

    // set inital background:
    background(0);
    }

    void draw () {
    }

    void serialEvent (Serial myPort) {
    // read the string from the serial port.
    String inString = myPort.readStringUntil('\n');

    if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int
    println();
    int currentHeartrate = int(inString);

    // draw the Heartrate BPM Graph.
    float heartrateHeight = map(currentHeartrate, 0, 1023, 0, height);
    noFill();
    stroke(0,255,0);
    strokeWeight(4);
    line(xPos - 1, height - oldHeartrateHeight, xPos, height - heartrateHeight);
    oldHeartrateHeight = heartrateHeight;
    // at the edge of the screen, go back to the beginning:
    if (xPos >= width) {
    xPos = 0;
    background(0);
    } else {
    // increment the horizontal position:
    xPos++;

    }
    }
    }

Any ideas what lines I need to append to get the output to display?

Any help is much appreciated, thanks in advance.


How to control USB relay board

Windows GUI in a Mac, how do I do that?

$
0
0

I have a GUI that was built with Processing on a Windows 10 machine. I need to be able to use it with a Mac.

How do I export it so I can use it on a Mac.

using processing for 3D image mapping

$
0
0

actually I'm Arduino Neopixel fan and tried to run the spherical POV. For run POV, each image should be converted to the number of lines which is used in each revolution , I think convert the planner POV must not be so hard for java base processing to pixelizid into lines but I don't now how to map an image on spherical and then converted to image lines I really appreciated for any comment

connecting an lcd to processing

$
0
0

Hello I used a processing sketch that shows a graphic form of information recieved from a pulse sensor. I would like to take that information and display it on an lcd screen. I don't know how to take that data and send it out of processing and into the lcd, so I could really use some help! thanks

Problem dispose exit program and arduino code

Serial Port Error

$
0
0

Hi I'm trying to connect a USB mouse via serial port, to change the colour of a rectangle depending on the position of the mouse. I'm trying to learn about serial ports, I do know that the same could be done using the mousepos function.

The issue I get is, usb port is not displayed in processing only bluetooth ports. I tried connecting the ardiuno and that is detected.

Any help would be greatly appreciated.

I'm using a Mac.

Processing and AWS Cloud feature integration problem (Eclipse)

$
0
0

Hello people.

I'm trying to integrate my Processing code(which is working perfectly fine with some GUI (using G4P)) with AWS Toolkit for Eclipse.

The Processing part is working as it should, however, when I create a project using AWS Eclipse Toolkit, using "New AWS Java Project" option, and try to integrate them, I get the following error:

java.lang.RuntimeException: java.lang.ClassNotFoundException: GUIProject
    at processing.core.PApplet.runSketch(PApplet.java:10268)
    at processing.core.PApplet.main(PApplet.java:10088)
    at processing.core.PApplet.main(PApplet.java:10070)
    at project.gui.GUIProject.main(GUIProject.java:83)
Caused by: java.lang.ClassNotFoundException: GUIProject
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at processing.core.PApplet.runSketch(PApplet.java:10261)
    ... 3 more

I'm pretty sure I included and set the jar paths correctly(since it was working before integrating with AWS). Any help would be very appreciated!!!

Here's my code:

package project.gui;

import processing.core.PApplet;
import processing.serial.*;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.PutItemRequest;
import com.amazonaws.services.dynamodbv2.model.PutItemResult;
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType;
import com.amazonaws.services.dynamodbv2.util.TableUtils;

import g4p_controls.*;

//reference: https://processing.org/tutorials/eclipse/

public class GUIProject extends PApplet{
    //Variables
    static AmazonDynamoDBClient dynamoDB;
    boolean isPaused = true; //Variable needed to check whether the user pressed pause or not.
    User user = new User(); //Create a User in order to store their personal details
    Serial myPort;
    String val;
    GWindow mainWindow;
    GButton btnStart;
    GButton btnPause;
    GButton btnExit;
    GLabel lblName;
    GLabel lblAge;
    GLabel lblGender;
    GLabel lblMessage;
    GLabel lblMessageWarning;
    GTextField tfName;
    GTextField tfAge;
    GTextField tfGender;

    private static Map<String, AttributeValue> newItem(String uniqueID, String name, String age, String gender, String date1, String date2, String time1, String time2,  List<String> distance) {
        Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
        item.put("uniqueID", new AttributeValue(uniqueID));
        item.put("name", new AttributeValue(name));
        item.put("age", new AttributeValue(age));
        item.put("gender", new AttributeValue(gender));
        item.put("date1", new AttributeValue(date1));
        item.put("date2", new AttributeValue(date2));
        item.put("time1", new AttributeValue(time1));
        item.put("time2", new AttributeValue(time2));
        item.put("distance", new AttributeValue(distance));

        return item;
    }

    private static void init(){
        AWSCredentials credentials = null;
        // get credentials and set dynamoDB region
        try {
            credentials = new ProfileCredentialsProvider("default").getCredentials();
        } catch (Exception e) {
        }
        dynamoDB = new AmazonDynamoDBClient(credentials);
        Region region = Region.getRegion(Regions.US_EAST_1);
        dynamoDB.setRegion(region);
    }

    public static void main(String[] args) {
        PApplet.main("GUIProject");
    }

    public void settings(){
        size(300,270);
    }
    public void setup(){
        myPort = new Serial(this, Serial.list()[0], 9600);

        lblName = new GLabel(this, 50, 30, 80, 30, "Name: ");
        lblAge = new GLabel(this, 50, 70, 80, 30, "Age: ");
        lblGender = new GLabel(this, 50, 110, 80, 30, "Gender: ");
        lblMessage = new GLabel(this, 50, 140, 80, 30, "");
        lblMessageWarning = new GLabel(this, 50, 140, 150, 30, "");
        tfName = new GTextField(this, 100, 30, 150, 20);
        tfAge = new GTextField(this, 100, 70, 150, 20);
        tfGender = new GTextField(this, 100, 110, 150, 20);
        btnStart = new GButton(this, 10, 170, 80, 30, "Start");
        btnPause = new GButton(this, 110, 170, 80, 30, "Pause");
        btnExit = new GButton(this, 210, 170, 80, 30, "End Session");

    }

    public void draw(){
        if(isPaused == false){
            background(200);
            lblMessageWarning.setText("");
            //After pressing Start, user should not be able to change their details
            tfName.setEnabled(false);
            tfAge.setEnabled(false);
            tfGender.setEnabled(false);

            if ( myPort.available() > 0) {  // If data is available,
                val = myPort.readStringUntil('\n');         // read it and store it in val
            }
            if(val == null || val.length() == 3){
                val = "out_of_range";
                //System.out.println(val);
                lblMessage.setText(val);
                user.setDistanceToVector(val);
            }
            else{
                //System.out.println(val.trim()); //print it out in the console
                lblMessage.setText(val.trim());
                user.setDistanceToVector(val.trim());
            }
        }
        else {
            lblMessage.setText("");
            background(200);
        }
    }

    public void handleButtonEvents(GButton button, GEvent event) {
        if(button == btnStart && event == GEvent.CLICKED){
            if(tfName.getText() == "" || tfAge.getText() == "" || tfGender.getText() == ""){
                lblMessageWarning.setText("Please fill in the form.");
            }
            else {
                user.setName(tfName.getText());
                user.setAge(tfAge.getText());
                user.setGender(tfGender.getText());
                isPaused = false;
            }
        }
        if(button == btnPause && event == GEvent.CLICKED){
            isPaused = true;
        }
        if(button == btnExit && event == GEvent.CLICKED){
            DateFormat dateFormatEnd = new SimpleDateFormat("dd/MM/yyyy");
            DateFormat timeFormatEnd = new SimpleDateFormat("HH:mm:ss");
            //get current date time with Date()
            Date today_date_end = new Date();
            String dateEnd = dateFormatEnd.format(today_date_end);
            String timeEnd = timeFormatEnd.format(today_date_end);
            user.setDateEnd(dateEnd);
            user.setTimeEnd(timeEnd);

            init();
            String tableName = "asas";
            // Check is table exists if it does not, create it
            try {
                Map<String, AttributeValue> item;
                // Create a table with a primary hash key named 'name', which holds
                // a string
                CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
                        .withKeySchema(new KeySchemaElement().withAttributeName("uniqueID").withKeyType(KeyType.HASH))
                        .withAttributeDefinitions(
                                new AttributeDefinition().withAttributeName("uniqueID").withAttributeType(ScalarAttributeType.S))
                        .withProvisionedThroughput(
                                new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));

                // Create table if it does not exist yet
                TableUtils.createTableIfNotExists(dynamoDB, createTableRequest);
                // wait for the table to move into ACTIVE state
                System.out.println("Checking table status.");
                TableUtils.waitUntilActive(dynamoDB, tableName);
                System.out.println("Table status: OK!");

                // Describe our new table
                //DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
                //TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
                //System.out.println("Table Description: " + tableDescription);

                // Add an item
                item = newItem(User.getID(), User.getName(), User.getAge(),User.getGender(), User.getDateBegin(), User.getDateEnd(), User.getTimeBegin(), User.getTimeEnd(), User.getDistanceArray());
                PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
                PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
                System.out.println("Result: " + putItemResult);

            } catch (AmazonServiceException ase) {
                System.out.println("Caught an AmazonServiceException, which means your request made it "
                        + "to AWS, but was rejected with an error response for some reason.");
                System.out.println("Error Message:    " + ase.getMessage());
                System.out.println("HTTP Status Code: " + ase.getStatusCode());
                System.out.println("AWS Error Code:   " + ase.getErrorCode());
                System.out.println("Error Type:       " + ase.getErrorType());
                System.out.println("Request ID:       " + ase.getRequestId());
            } catch (AmazonClientException ace) {
                                                     System.out.println(
                                                     "Caught an AmazonClientException, which means the client encountered "
                                                     +
                                                     "a serious internal problem while trying to communicate with AWS, "
                                                     +
                                                     "such as not being able to access the network."
                                                     ); System.out.println(
                                                     "Error Message: " +
                                                     ace.getMessage());
            }
            catch (InterruptedException ace) {
                 System.out.println(
                 "Caught an InterruptedException, which means the client encountered "
                 +
                 "a serious internal problem while trying to communicate with AWS, "
                 +
                 "such as not being able to access the network.");
                 System.out.println("Error Message: " + ace.getMessage());
            }
            exit();
        }
    }
}

Thank you very much.


Logic analyzer

$
0
0

Hello, i am working on a very simple logyc analyzer.

The hardware is made of an arduino which semd through serial this kind of data:

100:20:20

Where the first number is the time in microseconds when the pulse is high, the second low, and the last is the duty cycle.

Processing read everything correct from arduino

My problem is in drawing it. I tried with lines and points but i m not able to draw it correct

Arduino Serial to Processing Serial Problem with Bluetooth :(

$
0
0

With HC-SR04 sensor, I'm trying to put Arduino Serial output to Processing with Bluetooth

On Arduino, I can get perfect distance output on serial monitor (like 2~30)

However, When I try to transport that serial to Processing with Bluetooth

It turns to someting like -1, 55, 54 on Processing Serial monitor

This is my Arduino code

int trigPin = A5;
int echoPin = A4;
void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
long duration, distance;
  digitalWrite(trigPin, HIGH);
  delay(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distance = ((float)(340 * duration) / 10000) / 2;

  Serial.print(distance);
  delay(500);
  if (Serial.available() > 0) {
    Serial.read();
    Serial.write(distance);
  }
}

This is Processing code

    import processing.serial.*;

    Serial serial;

    void setup() {
      size(400, 400);

     // println(Serial.list());
      serial = new Serial(this, Serial.list()[1], 9600);
      int start = millis();
      while (millis() < start + 4000) {
      }
      serial.write(1);
     frameRate(10);
    }

    void draw() {
      if (serial.available() > 0) {
        background(serial.read(),0,0);
        serial.write(1);
      }
          println(serial.read());
    }

Can you help me?

Turning on relays via serial port,building the GUI

$
0
0

I've made a small program to turn on and off relays via ardiuno and it works. Now I would like to make a proper interface so basically have rectangle on screen and show which button/light is turned on. So when I press 1 the rectangle labled light 1 should turn red and go back to the when I release the key. the problem i'm having is that when the rectangle turns red it stays red without going back even when key is release. I could use the keyReleased function but then how would I include that into my current program?

import processing.serial.*;

Serial myPort;  // Create object from Serial class

void setup()
{
  size(200, 200);
  String portName = Serial.list()[5];
  myPort = new Serial(this, portName, 9600);
  printArray(Serial.list());
}
void draw() {
  if ((keyPressed == true)&&(key == '1'))
  {
    myPort.write('a');
    println("1");
  } else if ((keyPressed == true)&&(key == '2')) {
    myPort.write('b');
    println("2");
  } else if ((keyPressed == true)&&(key == '3')) {
    myPort.write('c');
    println("3");
  } else if ((keyPressed == true)&&(key == '4')) {
    myPort.write('d');
    println("4");
  } else if ((keyPressed == true)&&(key == '5')) {
    myPort.write('e');
    println("5");
  } else
  {
    myPort.write('0');
  }
}

Here is the code showing the idea about the rectangle turning red I've used ellipse just to show you the idea.

void setup(){
          size(400,400);
          ellipse(20,20,20,20);



        }
        void draw(){
        if((keyPressed == true)&&(key == '1')){
          ellipse(20,20,20,20);
          fill(255,0,0);


        }





        }

Realtime plotting rate

$
0
0

HI may i know if there is any solution to plot data at a faster rate? i am getting data from a sensor and would like to plot my data realtime.

Please provide me with any source code or ideas to counter my problem.Thank You

Change colors when mouse is over forms

$
0
0

Hi, I want three squares and when I go over the first one, i want all of them to turn red and to send a letter to arduino, when I go over the second one, I want all of them to turn green and when I go over the third one with my mouse, I want all of them to turn blue. When I click outside the boxes, I want all of them to turn black. Ony the R, G and B color changing part isn't working. Can someone help me with this?

import processing.net.*;
import processing.serial.*;
Serial myPort;
int click =0;
int box =0;

void setup () {
  size ( 640, 200);
  background (130);
  String portName = "COM5";
  myPort = new Serial (this, portName, 9600);
}

void draw () {
  drawFigures();
}
void loop () {

  if (mouseOverRect1() == true) {  // If mouse is over square,
    fill(255, 20, 20);         // change color and
    drawFigures();
    myPort.write('R');              // send an R to indicate mouse is over square 1
  }
  if (mouseOverRect2() == true) {  // If mouse is over square,
    fill(20, 255, 20);           // change color and
    drawFigures();
    myPort.write('G');              // send an G to indicate mouse is over square 2
  }
  if (mouseOverRect3() == true) {  // If mouse is over square,
    fill(20, 20, 255);                    // change color and
    drawFigures();
    myPort.write('B');              // send an B to indicate mouse is over square 3
  }
}

boolean mouseOverRect1() { // Test if mouse is over square 1
  return ((mouseX >= 10) && (mouseX <= 190) && (mouseY >= 10) && (mouseY <= 190));
}
boolean mouseOverRect2() { // Test if mouse is over square 2
  return ((mouseX >= 230) && (mouseX <= 420) && (mouseY >= 10) && (mouseY <= 190));
}
boolean mouseOverRect3() { // Test if mouse is over square 3
  return ((mouseX >= 450) && (mouseX <= 630) && (mouseY >= 10) && (mouseY <= 190));
}


void mouseClicked() {
  if ((mouseOverRect1()== false)&&(mouseOverRect2()== false)&&(mouseOverRect3()== false)) { // if mouse is outside the box
    if  (click == 0) { // and mouse is pressed
      fill (0);
      drawFigures ();
      myPort.write ('N');
    }
  }
}

void drawFigures() {

  rect(10, 10, 180, 180);
  rect(230, 10, 180, 180);
  rect( 450, 10, 180, 180);
}

Here is my code. thanks a lot!

How can I print only the latest line from the arduino to a text file?

$
0
0

I have made a processing program which prints the information from the serial port into a txt file. I intend to use the text file as a database for a local website based on JavaScript. My problem is that I only want the latest data from the Arduino, the most recent string printed. How do I make the text-file store only the latest string?

All input is appreciatied, thanks.

7 Segment Up/Down Counter controlled by Processing Program

$
0
0

Hi! The activity involves me having to create an up/down counter using an Arduino and controlled by processing. My idea is that there are buttons in the processing program that when hovered over, sends a signal to the arduino program signifying a process. So hovering over the first square, makes it count down, the second square, stop, and the last square resets it. If it is not over any square, it sends a '0', making it continue counting up.

This is the working arduino code. I have pushbuttons that does the processes mentioned.

    `

    unsigned char digit_1 = 7;
    unsigned char digit_2 = 8;
    unsigned char digit_3 = 10;

    int num1 = 0;
    int num2 = 0;
    int num3 = 0;
    int state = 0;
    int halt = 0;
    char val; //data received from serial port
    void setup()
    {
      Serial.begin(9600);
      for (int x = 11; x < 19; x++)
      {
        pinMode (x, OUTPUT);
      }

      pinMode (digit_1, OUTPUT);
      pinMode (digit_2, OUTPUT);
      pinMode (digit_3, OUTPUT);
     //  attachInterrupt(0, s1_press, RISING);
     //  attachInterrupt(1, s2_press, RISING);

    }


    void loop()
    {
      while (Serial.available())
      { val = Serial.read();
      }
      if (val == 1)
      {
        state = 1;
      }
      else //if (val == 0)
      {
        state = 0;
        halt = 0;
      }
      if (val == 2)
      {
        halt = 1;
      }
      else
      {
        state = 0;
        halt = 0;
      }

      if (halt == 0) {
        if (state == 0) {
          num3++;
          if (num3 == 10) {
            num3 = 0;
            num2++;
          }
          if (num2 == 10) {
            num2 = 0;
            num1++;
          }
          if (num1 == 10) {
            num1 = 0;
            num2 = 0;
            num3 = 0;
          }
        }

        if (state == 1) {
          num3--;
          if (num3 == -1) {
            num3 = 9;
            num2--;
          }
          if (num2 == -1) {
            num2 = 9;
            num1--;
          }
          if (num1 == -1) {
            num3 = 9;
            num2 = 9;
            num1 = 9;
          }
        }
      }
      for (int x = 0; x < 80; x++) {
        digitalWrite (digit_3, HIGH);
        digitalWrite (digit_2, LOW);
        digitalWrite (digit_1, LOW);
       display_ (num1);
        delay(1);
        digitalWrite (digit_3, LOW);
        digitalWrite (digit_2, HIGH);
        digitalWrite (digit_1, LOW);
        display_ (num2);
        delay(1);
        digitalWrite (digit_3, LOW);
        digitalWrite (digit_2, LOW);
        digitalWrite (digit_1, HIGH);
        display_ (num3);
        delay(1);
      }

    }




    void display_ (unsigned char num)
    {
      switch (num)
      {
        case 0:
          {
            digitalWrite (11, HIGH);
            digitalWrite (12, HIGH);
            digitalWrite (13, HIGH);
            digitalWrite (14, HIGH);
            digitalWrite (15, HIGH);
            digitalWrite (16, HIGH);
            digitalWrite (17, LOW);
            digitalWrite (18, LOW);

            break;
          }
        case 1:
          {
            digitalWrite (11, LOW);
            digitalWrite (12, HIGH);
            digitalWrite (13, HIGH);
            digitalWrite (14, LOW);
            digitalWrite (15, LOW);
            digitalWrite (16, LOW);
            digitalWrite (17, LOW);
            digitalWrite (18, LOW);

            break;
          }
        case 2:
          {
            digitalWrite (11, HIGH);
            digitalWrite (12, HIGH);
            digitalWrite (13, LOW);
            digitalWrite (14, HIGH);
            digitalWrite (15, HIGH);
            digitalWrite (16, LOW);
            digitalWrite (17, HIGH);
            digitalWrite (18, LOW);
             break;
          }
        case 3:
          {
            digitalWrite (11, HIGH);
            digitalWrite (12, HIGH);
            digitalWrite (13, HIGH);
            digitalWrite (14, HIGH);
            digitalWrite (15, LOW);
            digitalWrite (16, LOW);
            digitalWrite (17, HIGH);
            digitalWrite (18, LOW);
           break;
          }
        case 4:
          {
            digitalWrite (11, LOW);
            digitalWrite (12, HIGH);
            digitalWrite (13, HIGH);
            digitalWrite (14, LOW);
            digitalWrite (15, LOW);
            digitalWrite (16, HIGH);
            digitalWrite (17, HIGH);
            digitalWrite (18, LOW);

            break;
          }
        case 5:
          {
            digitalWrite (11, HIGH);
            digitalWrite (12, LOW);
            digitalWrite (13, HIGH);
            digitalWrite (14, HIGH);
            digitalWrite (15, LOW);
            digitalWrite (16, HIGH);
            digitalWrite (17, HIGH);
            digitalWrite (18, LOW);

            break;
          }
        case 6:
          {
            digitalWrite (11, HIGH);
            digitalWrite (12, LOW);
            digitalWrite (13, HIGH);
            digitalWrite (14, HIGH);
            digitalWrite (15, HIGH);
            digitalWrite (16, HIGH);
            digitalWrite (17, HIGH);
            digitalWrite (18, LOW);

            break;
          }
        case 7:
          {
            digitalWrite (11, HIGH);
            digitalWrite (12, HIGH);
            digitalWrite (13, HIGH);
            digitalWrite (14, LOW);
            digitalWrite (15, LOW);
            digitalWrite (16, LOW);
            digitalWrite (17, LOW);
            digitalWrite (18, LOW);


            break;
          }
        case 8:
          {
            digitalWrite (11, HIGH);
            digitalWrite (12, HIGH);
            digitalWrite (13, HIGH);
            digitalWrite (14, HIGH);
            digitalWrite (15, HIGH);
            digitalWrite (16, HIGH);
            digitalWrite (17, HIGH);
            digitalWrite (18, LOW);

            break;
          }
        case 9:
          {
            digitalWrite (11, HIGH);
            digitalWrite (12, HIGH);
            digitalWrite (13, HIGH);
            digitalWrite (14, HIGH);
            digitalWrite (15, LOW);
            digitalWrite (16, HIGH);
            digitalWrite (17, HIGH);
            digitalWrite (18, LOW);

            break;
          }
      }
    }


    void s1_press() {
      if (state == 0)
        state = 1;
      else if (state == 1)
        state = 0;
      delay (100);
    }

    void s2_press() {
      if (halt == 0)
        halt = 1;
      else
        halt = 0;
      delay(100);
    }

Here is my intended implementation of the processing code based on the serial write example;

` import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;        // Data received from the serial port
color c1 = #75C58E;
color c2 = #75C5FF;
color c3 = #D07633;
void setup()
{
  size(420, 200);
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);
}

//0 - count up and start
//1 - count down
//2 - stop
//3 - reset

void draw() {
  background(255);
  if (mouseOverRect() == true) {  // If mouse is over square,
    fill(c1);                    // change color and
    myPort.write('1');              // send a '1' to indicate mouse is over square
  } else                          //will be equivalent to the count up/count down trigger
  {
    fill(0);
    myPort.write('0');
  }
  rect(50, 50, 100, 100);         // Draw a square

  if (mouseOverRect2() == true) {  // If mouse is over square,
    fill(c2);                    // change color and
    myPort.write('2');              // send a 2 to indicate mouse is over square
  } else                        //stop trigger
  {
    fill(0);
    myPort.write('0');
  }
  rect(160, 50, 100, 100);

    if (mouseOverRect3() == true) {  // If mouse is over square,
    fill(c3);                    // change color and
    myPort.write('3');              // send a '3' to indicate mouse is over square
  } else                      //reset
  {
    fill(0);
    myPort.write('0');
  }
  rect(270, 50, 100, 100);
}


boolean mouseOverRect() { // Test if mouse is over square
  return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}
boolean mouseOverRect2() { // Test if mouse is over square
  return ((mouseX >= 160) && (mouseX <= 260) && (mouseY >= 50) && (mouseY <= 150));
}
boolean mouseOverRect3() { // Test if mouse is over square
  return ((mouseX >= 270) && (mouseX <= 370) && (mouseY >= 50) && (mouseY <= 150));
}

`

Any tips on how this could be implemented? My implementation doesn't seem to affect the arduino program in any way.


How to work around "Error, disabling serialEvent()"?

$
0
0

Hello! I recently got my own Arduino and decided to use it to make a pulse sensor from a tutorial. The tutorial also suggested using Processing to display peaks of pulse. I used their code but after returning few values and a peak of the graph the process stops, encountering a null value and giving the "disabling serialEvent() for COM3" error. Does anyone know how to deal with this error? I would love to learn more about it!

The code looks like this:

// Based on examples from Arduino's Graphing Tutorial and OscP5 documentation import processing.serial.*; Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph float oldHeartrateHeight = 0; // for storing the previous reading

void setup () {
// set the window size:
size(600, 400);
frameRate(25);

// List available serial ports.
println(Serial.list());

// Setup which serial port to use.
// This line might change for different computers.
myPort = new Serial(this, Serial.list()[1], 9600);

// set inital background:
background(0);
}

void draw () {
}

void serialEvent (Serial myPort) {
// read the string from the serial port.
String inString = myPort.readStringUntil('\n');

if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int
println(inString);
int currentHeartrate = int(inString);

// draw the Heartrate BPM Graph.
float heartrateHeight = map(currentHeartrate, 0, 1023, 0, height);
stroke(0,255,0);
line(xPos - 1, height - oldHeartrateHeight, xPos, height - heartrateHeight);
oldHeartrateHeight = heartrateHeight;
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
} else {
// increment the horizontal position:
xPos++;

}
}
}

I need help to fix my code (No library found for ddf.minim)

$
0
0

I am a beginner in coding, This is the error message i keep getting and if you could also help me if will get any more error message to give me guidance to fix those as well. Could someone help me fix this code so i can get it working.

No library found for ddf.minim No library found for ddf.minim.analysis Libraries must be installed in a folder named 'libraries' inside the 'sketchbook' folder.

This is my code:

import cc.arduino.*;
import org.firmata.*;

import ddf.minim.*;
import ddf.minim.analysis.*;
import processing.serial.*;
import cc.arduino.*;**

Arduino arduino;

Minim minim;
AudioPlayer song;
FFT fft;

int redPin1 = 12;
int greenPin1 = 11;
int bluePin1 = 10;

int redPin2 = 9;
int greenPin2 = 7;
int bluePin2 = 8;

int redPin3 = 6;
int greenPin3 = 4;
int bluePin3 = 5;

int color_id = 0;

int common_cathode = 0;

void setup() {
    size(800, 600);

    arduino = new Arduino(this, "/dev/com5", 57600);
    for (int i = 0; i <= 13; i++) arduino.pinMode(i, Arduino.OUTPUT);
    for (int i = 0; i <= 13; i++) arduino.digitalWrite(i,arduino.HIGH);

    minim = new Minim(this);
    song = minim.loadFile("fugly.mp3");
    song.play();
    fft = new FFT(song.bufferSize(), song.sampleRate());
}

void draw() {
    background(#151515);

    fft.forward(song.mix);

    strokeWeight(1.3);
    stroke(#FFF700);

    // frequency
    pushMatrix();
      translate(250, 0);
      for(int i = 0; i < 0+fft.specSize(); i++) {
        line(i, height*4/5, i, height*4/5 - fft.getBand(i)*4);
        if(i%100==0) text(fft.getBand(i), i, height*4/5+20);
        if(i==200) {
          if(fft.getBand(i)>2) {
            setColor1(255,255,0);
            setColor3(255,255,0);
          }
          else if(fft.getBand(i)>1) {
            setColor1(255,0,255);
            setColor3(255,0,255);
          } else {
            setColor1(255,255,255);
            setColor3(255,255,255);
          }
        }
        if(i==50) {
          if(fft.getBand(i)>5) {
            color_id = (color_id+1)%4;
          } else if(fft.getBand(i)>3) {
            if(color_id==0) setColor2(0,255,0);
            else if(color_id==1) setColor2(0,255,255);
            else if(color_id==2) setColor2(0,0,255);
            else setColor2(255,0,0);
          }
          else {
            setColor2(255,255,255);
          }
        }
      }
    popMatrix();

    stroke(#FF0000);

    //waveform
    for(int i = 250; i < song.left.size() - 1; i++) {
      line(i, 50 + song.left.get(i)*50, i+1, 50 + song.left.get(i+1)*50);
      line(i, 150 + song.right.get(i)*50, i+1, 150 + song.right.get(i+1)*50);
      line(i, 250 + song.mix.get(i)*50, i+1, 250 + song.mix.get(i+1)*50);
    }

    noStroke();
    fill(#111111);
    rect(0, 0, 250, height);

    textSize(24);
    fill(#046700);
    text("left amplitude", 10, 50);
    text("right amplitude", 10, 150);
    text("mixed amplitude", 10, 250);
    text("frequency", 10, height*4/5);
}

void stop()
{
    for (int i = 0; i <= 13; i++) arduino.digitalWrite(i,arduino.HIGH);
    song.close();
    minim.stop();
    super.stop();
}
void setColor1(int red, int green, int blue)
{
  if(common_cathode==1) {
    red = 255-red;
    green = 255-green;
    blue = 255-blue;
  }
  arduino.digitalWrite(redPin1, red);
  arduino.digitalWrite(greenPin1, green);
  arduino.digitalWrite(bluePin1, blue);
}
void setColor2(int red, int green, int blue)
{
  if(common_cathode==1) {
    red = 255-red;
    green = 255-green;
    blue = 255-blue;
  }
  arduino.digitalWrite(redPin2, red);
  arduino.digitalWrite(greenPin2, green);
  arduino.digitalWrite(bluePin2, blue);
}
void setColor3(int red, int green, int blue)
{
  if(common_cathode==1) {
    red = 255-red;
    green = 255-green;
    blue = 255-blue;
  }
  arduino.digitalWrite(redPin3, red);
  arduino.digitalWrite(greenPin3, green);
  arduino.digitalWrite(bluePin3, blue);
}

Using interrupts in Processing

$
0
0

Hi, I just installed Processing 3.2 and it looks similar to Arduino so I expected similar functionality. As I understand it setup() is the same as in Arduino, draw() is as loop(). But if I understand it correctly "interrupts" get checked only between setup() and draw() and draw() calls. When it doesn't matter I like to use blocking code because it is easier. I used

int lastKey=0;
void setup () {
  size(400, 300);

  printArray(Serial.list());
  while(lastKey==0) {}
  println(lastKey);
  myPort = new Serial(this, Serial.list()[0], 115200);
}

void keyPressed() {
  lastKey=key;
}

The idea was to convert the keypress to selecting the right port. But as you know no keypress was registered. I can fix this easily but still - is there some way to register outside events (key press, mouse click, incoming data etc.) as interrupt?

Thank and sorry for noob question but I had no luck googling "processing interrupt" - got hundreds of links to description how different processors work with interrupts :-(

What port name do I use?

$
0
0

I have got his code of someone else as i am a beginner. I am using a windows computer. I not sure what the port name is. This is the line of my code that isn't working. ** arduino = new Arduino(this, "/dev/com5", 57600. Line 34 is the one i need help with.

import cc.arduino.*;
import org.firmata.*;

import ddf.minim.*;
import ddf.minim.analysis.*;
import processing.serial.*;
import cc.arduino.*;

Arduino arduino;

Minim minim;
AudioPlayer song;
FFT fft;

int redPin1 = 12;
int greenPin1 = 11;
int bluePin1 = 10;

int redPin2 = 9;
int greenPin2 = 7;
int bluePin2 = 8;

int redPin3 = 6;
int greenPin3 = 4;
int bluePin3 = 5;

int color_id = 0;

int common_cathode = 0;

void setup() {
    size(800, 600);

    arduino = new Arduino(this, "/dev/com5", 57600);
    for (int i = 0; i <= 13; i++) arduino.pinMode(i, Arduino.OUTPUT);
    for (int i = 0; i <= 13; i++) arduino.digitalWrite(i,arduino.HIGH);

    minim = new Minim(this);
    song = minim.loadFile("fugly.mp3");
    song.play();
    fft = new FFT(song.bufferSize(), song.sampleRate());
}

void draw() {
    background(#151515);

    fft.forward(song.mix);

    strokeWeight(1.3);
    stroke(#FFF700);

    // frequency
    pushMatrix();
      translate(250, 0);
      for(int i = 0; i < 0+fft.specSize(); i++) {
        line(i, height*4/5, i, height*4/5 - fft.getBand(i)*4);
        if(i%100==0) text(fft.getBand(i), i, height*4/5+20);
        if(i==200) {
          if(fft.getBand(i)>2) {
            setColor1(255,255,0);
            setColor3(255,255,0);
          }
          else if(fft.getBand(i)>1) {
            setColor1(255,0,255);
            setColor3(255,0,255);
          } else {
            setColor1(255,255,255);
            setColor3(255,255,255);
          }
        }
        if(i==50) {
          if(fft.getBand(i)>5) {
            color_id = (color_id+1)%4;
          } else if(fft.getBand(i)>3) {
            if(color_id==0) setColor2(0,255,0);
            else if(color_id==1) setColor2(0,255,255);
            else if(color_id==2) setColor2(0,0,255);
            else setColor2(255,0,0);
          }
          else {
            setColor2(255,255,255);
          }
        }
      }
    popMatrix();

    stroke(#FF0000);

    //waveform
    for(int i = 250; i < song.left.size() - 1; i++) {
      line(i, 50 + song.left.get(i)*50, i+1, 50 + song.left.get(i+1)*50);
      line(i, 150 + song.right.get(i)*50, i+1, 150 + song.right.get(i+1)*50);
      line(i, 250 + song.mix.get(i)*50, i+1, 250 + song.mix.get(i+1)*50);
    }

    noStroke();
    fill(#111111);
    rect(0, 0, 250, height);

    textSize(24);
    fill(#046700);
    text("left amplitude", 10, 50);
    text("right amplitude", 10, 150);
    text("mixed amplitude", 10, 250);
    text("frequency", 10, height*4/5);
}

void stop()
{
    for (int i = 0; i <= 13; i++) arduino.digitalWrite(i,arduino.HIGH);
    song.close();
    minim.stop();
    super.stop();
}
void setColor1(int red, int green, int blue)
{
  if(common_cathode==1) {
    red = 255-red;
    green = 255-green;
    blue = 255-blue;
  }
  arduino.digitalWrite(redPin1, red);
  arduino.digitalWrite(greenPin1, green);
  arduino.digitalWrite(bluePin1, blue);
}
void setColor2(int red, int green, int blue)
{
  if(common_cathode==1) {
    red = 255-red;
    green = 255-green;
    blue = 255-blue;
  }
  arduino.digitalWrite(redPin2, red);
  arduino.digitalWrite(greenPin2, green);
  arduino.digitalWrite(bluePin2, blue);
}
void setColor3(int red, int green, int blue)
{
  if(common_cathode==1) {
    red = 255-red;
    green = 255-green;
    blue = 255-blue;
  }
  arduino.digitalWrite(redPin3, red);
  arduino.digitalWrite(greenPin3, green);
  arduino.digitalWrite(bluePin3, blue);
}

The port name?

$
0
0
arduino = new Arduino(this, "/dev/name/COM3", 57600);

Presentation1222

What port do I use. I have tried COM1/2/3/4/5

Viewing all 747 articles
Browse latest View live