<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #processing - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23processing</link>
      <pubDate>Sun, 08 Aug 2021 18:32:24 +0000</pubDate>
         <description>Tagged with #processing - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23processing/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Help please! ARDUINO and PROCESSING temperature sensor code</title>
      <link>https://forum.processing.org/two/discussion/26534/help-please-arduino-and-processing-temperature-sensor-code</link>
      <pubDate>Mon, 26 Feb 2018 12:26:51 +0000</pubDate>
      <dc:creator>sandouk24</dc:creator>
      <guid isPermaLink="false">26534@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>so for a project with school i had created a temperature sensor using an arduino and breadboard circuit i will leave my code below for the arduino. My issue is that i cannot receive the data from the arduino using processing. I want to create a temperature graph to show on processing.</p>

<p>Arduino code:</p>

<pre><code>#include &lt;LiquidCrystal.h&gt;

int tempPin = 0;
int lightPin = 1;

/*const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);*/

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int value=0;            
float volts=0.0;      
float temp=0.0;      
float tempF=0.0;
int sensorPin = A0;

void setup() 
{
  pinMode(3,INPUT);      //setting arduino pin3 as input
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop()
{
Serial.println(analogRead(0));
 delay(50); 

  //tempReading = analogRead(tempPin);

  int tempReading = analogRead(A0);
  Serial.write(tempReading);
  float tempVolts = tempReading * 5.0 / 1024.0;
  float tempC = (tempVolts - 0.5) * 100.0;
  float tempF = tempC * 9.0 / 5.0 + 32.0;

  lcd.print("TempC             ");
  lcd.setCursor(6, 0);
  lcd.print(tempC);

  int lightReading = analogRead(lightPin);
  lcd.setCursor(0, 1);

  lcd.print("TempF              ");  
  lcd.setCursor(6, 1);
  lcd.print(tempF);
  Serial.print(tempC);
  Serial.println(tempF);
  delay(500);

}


Processing code:
import processing.serial.*;
//import cc.arduino.*;
//Arduino arduino;



//init variables
Serial commPort;
int val;
float tempC;
float tempF;
//float tempVolts;
int yDist;
float[] tempHistory = new float[100];

void setup()
{
 //setup fonts for use throughout the application
//set the size of the window
 size(900,450);
//init serial communication port
 commPort = new Serial(this, Serial.list()[0], 9600);

//fill tempHistory with default temps
 for(int index = 0; index&lt;100; index++)
 tempHistory[index] = 0;
}

void draw()
{
 //get the temp from the serial port
 while (commPort.available() &gt; 0) 
 {
 tempC = commPort.read();
//refresh the background to clear old data
 background(123);

 //draw the temp rectangle
 colorMode(RGB, 100);  //use color mode sized for fading
 stroke (0);
 rect (49,19,22,162);
 //fade red and blue within the rectangle
 for (int colorIndex = 0; colorIndex &lt;= 160; colorIndex++) 
 {
 stroke(160 - colorIndex, 0, colorIndex);
 line(50, colorIndex + 20, 70, colorIndex + 20);
 }
//draw graph
 stroke(0);
 fill(255,255,255);
 rect(90,80,100,100);
 for (int index = 0; index&lt;100; index++)
 { 
 if(index == 99)
 tempHistory[index] = tempC;
 else
 tempHistory[index] = tempHistory[index + 1];
 point(90 + index, 180 - tempHistory[index]); 
 }
//write reference values
 fill(10,10,10);
textAlign(RIGHT);
 text("100 C", 45, 25); 
 text("0 C", 45, 187);
//draw triangle pointer
 yDist = int(160 - (160 * (tempC * 0.01)));
 stroke(0);
 triangle(75, yDist + 20, 85, yDist + 15, 85, yDist + 25);
//write the temp in C and F
 fill(0,0,0);
textAlign(LEFT);
 text(str((tempC)) + " C", 115, 37);
</code></pre>

<p>tempF = ((tempC*9)/5) + 32;
 text(str((tempF)) + " F", 115, 65);
 }
}</p>
]]></description>
   </item>
   <item>
      <title>real time graph plotting using processing</title>
      <link>https://forum.processing.org/two/discussion/23083/real-time-graph-plotting-using-processing</link>
      <pubDate>Fri, 16 Jun 2017 05:34:48 +0000</pubDate>
      <dc:creator>drocobeth</dc:creator>
      <guid isPermaLink="false">23083@/two/discussions</guid>
      <description><![CDATA[<p><img src="" alt="" /><img src="" alt="" />i have to plot a graph in processing by the feedback from encoder motors of the bot. so i have two variables basically left motor encoder and right motor encoder. i planned to vary on in x-axis and another in y-axis. while i went through some of the codes on internet i found that, almost everyone has written the graph part code in serial event itself? so my first doubt is why do they write it in serial event() function rather than void draw()? another thing is when i tried to write my code for graph in void draw() it had a pseudo code something like this:</p>

<pre><code>           xpos1=0,ypos1=height;
        void draw():
         line(xpos1,ypos1,xpos,height-ypos);// obviously the data(xpos,ypos) is mapped with the width and height of the processing ide window.
            xpos1=xpos;
            ypos1=height-ypos;
            if(xpos1&gt;=width)
            {
              xpos1=0;
            }
            if(ypos1&gt;=height)
            {
              ypos1=0;
            }
</code></pre>

<p>so i get to see only a small dot traversing on processing ide window and i cannot see the older path that my line has travelled which in the case of the sites which i described when wrote the similar piece of code in serial event() they had a whole graph getting made on the processing window. where am i getting wrong? please help me also is there any alternative to  plot the graph using void draw()?i want to vary both xpos as well as ypos as i get two feedbacks form left motor and right motor. please help with the detailed answers.
<img src="https://forum.processing.org/two/uploads/imageupload/672/ZJ3Y2V4V3SLH.png" alt="graph" title="graph" />
screenshot of my attempted graph in different frames<img src="https://arduining.files.wordpress.com/2013/08/graph_example.jpg?w=768&amp;h=529" alt="" />
screenshot of one of the graphs made by somewhat the similar code displayed above but written in the serial event() available on the internet:</p>
]]></description>
   </item>
   <item>
      <title>Issue when displaying data from a text file to a 8x8 led matrix</title>
      <link>https://forum.processing.org/two/discussion/22677/issue-when-displaying-data-from-a-text-file-to-a-8x8-led-matrix</link>
      <pubDate>Sat, 20 May 2017 08:56:06 +0000</pubDate>
      <dc:creator>Taalik</dc:creator>
      <guid isPermaLink="false">22677@/two/discussions</guid>
      <description><![CDATA[<p>So i'm actually making a little project with arduino and processing. Basically i'm using a C++ program to draw on a 8x8 matrix. This program saves your drawing into a text file in this format :</p>

<pre><code>  00000000
  00111000
  00010000
  00111000
  00000000
  00000000
  00000000
  00000000
</code></pre>

<p>And displays it to a led 8x8 matrix connected to an arduino.</p>

<p>So first in processing, I load this file into a string and then send it to the serial port line by line.
Then in arduino i read the serial port and store the data into a string, i convert each line of this string to decimal for exemple if the value of string[0] is "00111100" the conversion will return 60. And then i store each decimals into the led matrix and display it.</p>

<p>The content of the text file is successfully displayed on the LED matrix but the issue is that after a few seconds, my entire drawing is shifting before returning to its place, it does not stay at the same place it should be. For exemple if i display the letter A this is the result (links to the pictures) : <a rel="nofollow" href="https://i.stack.imgur.com/SgQF3.jpg"><strong>'A' displayed</strong></a> | <a rel="nofollow" href="https://i.stack.imgur.com/p4oOt.jpg"><strong>'A' shifting</strong></a></p>

<p>I think the issue is a synchronization problem between arduino and processing, processing sends the data in the text file continously and arduino doesn't read the correct data in time. But honestly i have no clue on how to fix that so i'm asking you guys help.</p>

<p>I might have to send only new data in Processing, for example we read the file if there is no new data we don't send anything to the serial port, if there is new data we send the new data to the serial port. I tried to create a second array that takes data from the string lines to compare it but it doesn't work because at each loop, the second array always equals to the first ...</p>

<p>Thank you for your time !</p>

<p>Here is my code :</p>

<p><strong>Processing :</strong></p>

<pre><code>import processing.serial.*;
import java.io.*;
Serial myPort;

void setup() {
  //Make sure the COM port is correct
  myPort = new Serial(this, "COM5", 9600);
  myPort.bufferUntil('\n');
}

void draw() {
  String[] lines = loadStrings("matrice.txt");
  for (int a = 0 ; a &lt; (lines.length) ; a++) {
    myPort.write(lines[a]);
    //println(lines.length);
  }
  delay(1000);
} 
</code></pre>

<p><strong>Arduino :</strong></p>

<pre><code>unsigned char j;
unsigned char i;
unsigned char k;
unsigned char l;

String inChar[8];
String inCharTemp[8];
int ligne[8];

//Cablage du module (gnd et +V) utilise 3 pins
int Max7219_pinCLK = 10;
int Max7219_pinCS = 9;
int Max7219_pinDIN = 8;

//Définition des pixels a eclairer
//0-9 puis A-Z soit 10+26 = 36 caractères
char disp1[38][8];

//Autre exemple, caracteres speciaux (a definir soi meme)
//Voir explications sur <a href="http://tiptopboards.com/arduino_tutoriel/posting.php?mode=edit&amp;f=2&amp;p=6" target="_blank" rel="nofollow">http://tiptopboards.com/arduino_tutoriel/posting.php?mode=edit&amp;f=2&amp;p=6</a>
//{0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55},  //damier1
// {0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA},  //damier2

//Ecriture d'un caractere 8x8
void Write_Max7219_byte(unsigned char DATA)
{
  unsigned char i;
  digitalWrite(Max7219_pinCS, LOW);
  for (i = 8; i &gt;= 1; i--)
  {
    digitalWrite(Max7219_pinCLK, LOW);
    digitalWrite(Max7219_pinDIN, DATA &amp; 0x80); // Extracting a bit data
    DATA = DATA &lt;&lt; 1;
    digitalWrite(Max7219_pinCLK, HIGH);
  }
}

//Ecriture elementaire d une seule rangee
void Write_Max7219(unsigned char address, unsigned char dat)
{
  digitalWrite(Max7219_pinCS, LOW);
  Write_Max7219_byte(address);           //address，code of LED
  Write_Max7219_byte(dat);               //data，figure on LED
  digitalWrite(Max7219_pinCS, HIGH);
}

//Initialisation du module Max 7219
void Init_MAX7219(void)
{
  Write_Max7219(0x09, 0x00);       //decoding ：BCD
  Write_Max7219(0x0a, 0x03);       //brightness
  Write_Max7219(0x0b, 0x07);       //scanlimit；8 LEDs
  Write_Max7219(0x0c, 0x01);       //power-down mode：0，normal mode：1
  Write_Max7219(0x0f, 0x00);       //test display：1；EOT，display：0
}

int convertir(String ligne)
{
  String sample_str = ligne;
  uint32_t result = 0;
  for (unsigned int i = 0; i &lt; sample_str.length(); ++i)
  {
    result = result &lt;&lt; 1;
    result = result | (sample_str[i] &amp; 1);
  }
  return result;
}

//Le programme d affichage
void setup()
{
  //Pins a utiliser
  pinMode(Max7219_pinCLK, OUTPUT);
  pinMode(Max7219_pinCS, OUTPUT);
  pinMode(Max7219_pinDIN, OUTPUT);
  delay(50);  //Initialiser
  Serial.begin(9600);
  Init_MAX7219();
  for (int i = 0; i &lt; 8; i++)
  {
    ligne[i] = 0;
  }
}

void loop()
{
  for (int a = 0; a &lt; 8; a++)
  {
    for (int b = 0; b &lt; 8; ++b)
    {
      if (Serial.available())
      {
        inChar[a] += Serial.read() - 48;

        ligne[a] = convertir(inChar[a]);
        Serial.println(ligne[a]);
      }
    }
  }

  // Boucle for qui assigne a chaque case de disp la ligne en décimal
  for (int a = 0; a &lt; 38; a++)
  {
    for (int b = 0; b &lt; 8; b++)
    {
      disp1[a][b] = ligne[b];
      inChar[b] = "";
    }
  }

  for (j = 0; j &lt; 38; j++)
  {
    for ( i = 0; i &lt; 9; i++)
    {
      Write_Max7219(i, disp1[j][i - 1]); // Affiche la matrice
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Capacitive Sensor Within Processing</title>
      <link>https://forum.processing.org/two/discussion/21205/capacitive-sensor-within-processing</link>
      <pubDate>Mon, 06 Mar 2017 18:44:13 +0000</pubDate>
      <dc:creator>harrisonh555</dc:creator>
      <guid isPermaLink="false">21205@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I'm novice at using Processing.</p>

<p>In my code I want to change the background to white when the capacitive sensor is held down, and then back to black when the sensor is released.</p>

<p>I have attempted at writing this code in both capacitive sensor code in Arduino, however when I run my code in Processing nothing is shown or changes.</p>

<p>Any help would be greatly appreciated.</p>

<p>MY ARDUINO CODE IS BELLOW</p>

<pre><code>#include &lt;CapacitiveSensor.h&gt;

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);             

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);

  Serial.println(total1); 
  Serial.print(",");                

  delay(10);                              
}
</code></pre>

<p>MY PROCESSING CODE IS BELLOW</p>

<pre><code>import processing.serial.*;

int touch1Value = 0;

int threshold = 30;

Serial myPort;

void setup(){

  size (500,500);

  myPort = new Serial(this, Serial.list()[1], 9600);

  myPort.bufferUntil('\n');
}

void draw(){

  background (0);

  println("touch1Value:"+touch1Value);

  if (touch1Value == 1){

    background (255,255,255);
  }
}

void serialEvent(Serial myPort){

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

  if (inString != null){

    inString = trim (inString);

    float[] touches = float (split(inString, ","));

    if (touches.length &gt;=1){

      touch1Value = touches[0] &gt;= threshold ? 1: 0;
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>I have code from Rapid-Android-Developmen book</title>
      <link>https://forum.processing.org/two/discussion/20167/i-have-code-from-rapid-android-developmen-book</link>
      <pubDate>Mon, 09 Jan 2017 18:08:03 +0000</pubDate>
      <dc:creator>saha</dc:creator>
      <guid isPermaLink="false">20167@/two/discussions</guid>
      <description><![CDATA[<pre><code>import ketai.camera.*;

KetaiCamera cam;
PImage bg, snapshot, mux;`

void setup() {
  fullScreen();
  orientation(LANDSCAPE);
  cam = new KetaiCamera(this, 1280, 768, 30);
  cam.setCameraID(1);  //(1)
  imageMode(CENTER);
  stroke(255);
  textSize(48);
  snapshot = createImage(1280, 768, RGB);
  bg = loadImage("rover.jpg");  //(2)
  bg.resize(1280, 768);
  bg.loadPixels();
  mux = new PImage(1280, 768);
}

void draw() 
{
  background(0);

  if (cam.isStarted()) {   
    cam.loadPixels();  //(3)
    snapshot.loadPixels();  //(4)
    mux.loadPixels();  //(5)

    for (int i= 0; i &lt; cam.pixels.length; i++)
    {  
      color currColor = cam.pixels[i];  //(6)
      float currR = abs(red(cam.pixels[i]) - red(snapshot.pixels[i]) );  //(7)
      float currG = abs(green(cam.pixels[i]) - green(snapshot.pixels[i]));
      float currB = abs(blue(cam.pixels[i]) - blue(snapshot.pixels[i]));      
      float total = currR+currG+currB;  //(8)

      if (total &lt; 128)
        mux.pixels[i] = bg.pixels[i];  //(9)   
      else
        mux.pixels[i] = cam.pixels[i];  //(10)

    }

    mux.updatePixels();  //(11)
    image(mux, width/2, height/2, width, height);  //(12)
  } 
  drawUI();
}

void drawUI()
{
  fill(0, 128);
  rect(0, 0, width/4, 100);
  rect(width/4, 0, width/4, 100);
  rect(2*(width/4), 0, width/4, 100);
  rect(3*(width/4), 0, width/4-1, 100);
  fill(255);

  if (cam.isStarted())
    text("stop", 20, 70);
  else
    text("start", 20, 70);

  text("camera", (width/4)+20, 70);
  text("snapshot", 2*(width/4)+20, 70);
}

void mousePressed()
{
  if (mouseY &lt;= 100) {
    //start/stop the camera
    if (mouseX &gt; 0 &amp;&amp; mouseX &lt; width/4)
    {
      if (cam.isStarted())
      {
        cam.stop();
      }
      else
      {
        if (!cam.start())
          println("Failed to start camera.");

        bg.resize(cam.width, cam.height);
      }
    }
    //switch cameras
    else if (mouseX &gt; width/4 &amp;&amp; mouseX &lt; 2*(width/4))
    {
      int cameraID = 0;

      if (cam.getCameraID() == 0)
        cameraID = 1;
      else
        cameraID = 0;

      cam.stop();
      cam.setCameraID(cameraID);
      cam.start();
    }

    //take snapshot
    else if (mouseX &gt; 2*(width/4) &amp;&amp; mouseX &lt; 3*(width/4))
    {
      cam.manualSettings(); //(1)   
      snapshot.copy(cam, 0, 0, cam.width, cam.height,0, 0, snapshot.width, snapshot.height);  //(2)
      mux.resize(cam.width, cam.height);
    }
  }
}

void onCameraPreviewEvent()
{  
  cam.read();
}

void exit() 
{
  cam.stop();
}
</code></pre>

<p>I have problem is</p>

<p>java.lang.RuntimeException: Camera is being used after Camera.release() was called
    at android.hardware.Camera.native_getParameters(Native Method)
    at android.hardware.Camera.getParameters(Camera.java:2007)
    at ketai.camera.KetaiCamera.start(KetaiCamera.java:480)
    at processing.test.cameraphotobooth.CameraPhotobooth.mousePressed(CameraPhotobooth.java:96)
    at processing.core.PApplet.mousePressed(Unknown Source)
    at processing.core.PApplet.handleMouseEvent(Unknown Source)
    at processing.core.PApplet.dequeueEvents(Unknown Source)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:818)</p>

<p>Thank you.</p>
]]></description>
   </item>
   <item>
      <title>NoClassDefFoundError:javax/bluetooth/DiscoveryListener   bluecove processing</title>
      <link>https://forum.processing.org/two/discussion/19327/noclassdeffounderror-javax-bluetooth-discoverylistener-bluecove-processing</link>
      <pubDate>Sun, 27 Nov 2016 11:43:58 +0000</pubDate>
      <dc:creator>MarkoO</dc:creator>
      <guid isPermaLink="false">19327@/two/discussions</guid>
      <description><![CDATA[<p>Hi, Do you maybe know what is the appropriate bluecove to download and use for processing 2.2.1? I have one instance of the class that is giving me the error (NoClassDefFoundError:javax/bluetooth/DiscoveryListener). I am having a .jar file (and I extracted it also) in sketcbook/libraries and when I open the file THERE IS a path javax/bluetooth/Disco..., maybe I am just using a wrong bluecove or I do not need bluecove at all? I downloaded 2.0.0.jar.zip bluecove.</p>

<p>This is the line that has error: NXTInfo[] nxtInfo = connect.search(null, null, NXTCommFactory.BLUETOOTH);
I imported lejos.pc.comm.*; as well.</p>

<p>I am using Ubuntu 16.04 LTS Intel 64bit.</p>

<p>If anyone can help me, I would really appreciate it. Thank you, Marko.</p>
]]></description>
   </item>
   <item>
      <title>OpenCV with OpenKinect and Xbox Kinect V2</title>
      <link>https://forum.processing.org/two/discussion/18149/opencv-with-openkinect-and-xbox-kinect-v2</link>
      <pubDate>Mon, 12 Sep 2016 13:20:32 +0000</pubDate>
      <dc:creator>mindcraft</dc:creator>
      <guid isPermaLink="false">18149@/two/discussions</guid>
      <description><![CDATA[<p>hi everyone,</p>

<p>i am trying build a face detection with the opencv and openkinect libraries. for the image input i want to use the xbox kinect v2. i am basing my code on the face detection example.</p>

<p>this is my code so far:</p>

<pre>
import gab.opencv.*;
import java.awt.Rectangle;

/* KINECT */
import org.openkinect.freenect.*;
import org.openkinect.freenect2.*;
import org.openkinect.processing.*;

OpenCV opencv;
Kinect2 kinect2;

Rectangle[] faces;

void setup() {
  opencv = new OpenCV(this, 640/2, 480/2);
  size(640, 480);
  // Kinectv2
  kinect2 = new Kinect2(this);
  kinect2.initVideo();
  kinect2.initDevice();
  
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  
  faces = opencv.detect();
}

void draw() {
  opencv.loadImage(kinect2.getVideoImage());
  image(kinect2.getVideoImage(), 0, 0, 640, 480);

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  for (int i = 0; i &lt; faces.length; i++) {
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  }
}
</pre>

<p>the problem seems to be in the line "opencv.loadImage(kinect2.getVideoImage());" since the detection does not work.
when working with the isight camera (using the build-in function "capture" and "video"-add-on) instead of kinect everything works perfectly fine.</p>

<p>can anyone help?</p>
]]></description>
   </item>
   </channel>
</rss>