Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: Potentiomter/ RFID values going wrong when I run processing ? on: May 28, 2013, 04:02:10 pm
On OS yeah, Arduino talking to processing.

Yeah its a lot of bluetooth crap, my main problem that I am trying to solve is getting the potentiometer to scroll left and right through an image. This is the only part that I can't get working, all the RFID tags are working fine, they load the image and the music. It's just when the image is loaded, I can't get the potentiometer to scroll through the image?

I have tried different things, but it still wont work?
2  Using Arduino / Programming Questions / Re: Potentiomter/ RFID values going wrong when I run processing ? on: May 28, 2013, 03:33:10 pm
I had both serial monitor in arduino and running the processing sketch at the same time. The Arduino sketch above reads the Potentiometer Values and then I have this code below for the processing sketch; The sketch loads an image and then I want to use the potentiometer to scroll across the x pos, like a panoramic image.

Code:
import processing.serial.*;
import ddf.minim.*;//declare
AudioPlayer player;
Minim minim;
int x, moveSpeed = 5;

Serial portOne;    // the first serial port
Serial portTwo;    // the second serial port

boolean showImage;  // whether or not to show the image
// the list of names
String[] tags = {
  "5100C2F495F2","5100C2EB6F17","59003206E68B","59003219B7C5","590031BDCE1B","590031C48B4"};
 
  String tag="";
 
  float sensorFloat;

// the list of people
PImage thisImage;
PImage bg;

int maxPics =1;

int pictureNumber = 1;

void setup() {
  size(1000, 664);
  showImage = false;
  // list the serial ports
  println(Serial.list());
  // open the serial ports:
  portOne = new Serial(this, Serial.list()[16], 9600);
  // set both ports to buffer information until you get 0x03:
  //portOne.bufferUntil('\n');
   minim=new Minim(this);
   bg = loadImage("backimage.jpg");

 
 }
 

 void draw() {
 background(bg);
 if(tag!="")
  {
    getImage(tag,pictureNumber);
    image(thisImage, 0, 0);
  }
  // if there's an image to show, show it:
  if (showImage) {
  image(thisImage, 0, 0);
   float potentiometer = sensorFloat;
   float movement = map(potentiometer, 0, 1023, -moveSpeed, moveSpeed); // map from range (0, 1023) to (-moveSpeed, moveSpeed)
   x += movement; // add movement to location
   x = constrain(x, -(thisImage.width-width), 0); // constrain image by 0 (at the beginning) and -600 (aka a remaining visible image width of 1000 equal to the canvas width).
   image(thisImage, x, 0); // draw the image
   fill(0);
   frame.setTitle(x + ""); // see the x in the top-left
  }
}

void serialEvent(Serial thisPort) {
  // read the incoming serial data:

  String potString = thisPort.readStringUntil(',');
  String rfidString = thisPort.readStringUntil('\n');

 
  if(potString != null && potString.length()>2)
  {
    potString = trim(potString);
    sensorFloat = float(potString);
  }

  // if the string is not empty, do stuff with it:
  if (rfidString != null && rfidString.length()>2) {
    // if the string came from serial port one:
    if (thisPort == portOne) {
      print ("Data from port one: ");
    }
    // if the string came from serial port two:
    if (thisPort == portTwo) {
      print ("Data from port two: ");
    }
    // print the string:
    println(rfidString);
   
    println(rfidString.substring(1,13)+".jpg");
   // images[i] = loadImage(rfidString.substring(1,13)+ "/" + i + ".jpg" );
   
    println(rfidString.substring(1,13)+"/music.mp3");
    if(player!=null)
    {
      player.pause();
      player.close();
    }
    player=minim.loadFile(rfidString.substring(1,13)+"/music.mp3");//locate file
    println(player);
     player.play();//when opened play this

    // the tag ID is only bytes 1 through 13. Get it:
    tag = rfidString.substring(1, 13);
  }
}




// Get random image from the folder filelist array
void getImage(String tag,int picture) {
  String filenames[];

  try{
    // open the directory:
    File directory = new File(sketchPath("data")+"/"+tag);
   
    // list the files in the directory:
    filenames = directory.list();

    int picCounter=0;
    for(int thisFile = 0; thisFile<filenames.length; thisFile++){
      // if the file is a .jpg:
      if (filenames[thisFile].endsWith(".jpg")) {
        picCounter++;
        if(picCounter==picture)
        {
        // get the filename without the .jpg extension:
        String thisName = filenames[thisFile].substring(0, filenames[thisFile].length() -4);
        //if the filename matches the name of the person:
          // load the image from the file:
          thisImage = loadImage("data/"+tag+"/"+filenames[thisFile]);
          // show it:
          showImage = true;
        }
       }
    }
  }
  catch(Exception f){
    //  if there was a problem reading the directory:
    println("Image import error - missing thisFile or folder");
  }
}
3  Using Arduino / Programming Questions / Re: Potentiomter/ RFID values going wrong when I run processing ? on: May 27, 2013, 11:42:30 am
The reason why the numbers were going like that, was because I had both Processing and Arduino at the same time. But I have copied the code that I need for the potentiometer, but its still not responding.
4  Using Arduino / Programming Questions / Re: Potentiomter/ RFID values going wrong when I run processing ? on: May 26, 2013, 05:22:01 pm
This is the Arduino Code;
Code:

/* RFID ID12
*/

char val = 0; // variable to store the data from the serial port

void setup() {
Serial.begin(9600); // connect to the serial port
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
}

void loop () {
// read the serial port
int sensorValue = analogRead(A0);
Serial.print(sensorValue);
Serial.print(",");
if(Serial.available() > 15) {
  for(int byte=0;byte<=15;byte++)
  {
    val = Serial.read();
    if(byte<=12) Serial.print(val, BYTE);
  }
}
Serial.println();
delay(50);


}

And this is the Processing code;

Code:
import processing.serial.*;
import ddf.minim.*;//declare
AudioPlayer player;
Minim minim;

Serial portOne;    // the first serial port
Serial portTwo;    // the second serial port

boolean showImage;  // whether or not to show the image
// the list of names
String[] tags = {
  "5100C2F495F2","5100C2EB6F17","59003206E68B","59003219B7C5","590031BDCE1B","590031C48B4"};
 
  String tag="";
 
  float sensorFloat;

// the list of people
PImage thisImage;
PImage bg;

int maxPics =1;

int pictureNumber = 1;

void setup() {
  size(1000, 664);
  showImage = false;
  // list the serial ports
  println(Serial.list());
  // open the serial ports:
  portOne = new Serial(this, Serial.list()[16], 9600);
  // set both ports to buffer information until you get 0x03:
  //portOne.bufferUntil('\n');
   minim=new Minim(this);
   bg = loadImage("backimage.jpg");

 
 }
 

 void draw() {
 background(bg);
 if(tag!="")
  {
    getImage(tag,pictureNumber);
    image(thisImage, 0, 0);
  }
  // if there's an image to show, show it:
  if (showImage) {
  image(thisImage, 0, 0);
  }
}

void serialEvent(Serial thisPort) {
  // read the incoming serial data:

  String potString = thisPort.readStringUntil(',');
  String rfidString = thisPort.readStringUntil('\n');

 
  if(potString != null && potString.length()>2)
  {
    potString = trim(potString);
    sensorFloat = float(potString);
  }

  // if the string is not empty, do stuff with it:
  if (rfidString != null && rfidString.length()>2) {
    // if the string came from serial port one:
    if (thisPort == portOne) {
      print ("Data from port one: ");
    }
    // if the string came from serial port two:
    if (thisPort == portTwo) {
      print ("Data from port two: ");
    }
    // print the string:
    println(rfidString);
   
    println(rfidString.substring(1,13)+".jpg");
   // images[i] = loadImage(rfidString.substring(1,13)+ "/" + i + ".jpg" );
   
    println(rfidString.substring(1,13)+"/music.mp3");
    if(player!=null)
    {
      player.pause();
      player.close();
    }
    player=minim.loadFile(rfidString.substring(1,13)+"/music.mp3");//locate file
    println(player);
     player.play();//when opened play this

    // the tag ID is only bytes 1 through 13. Get it:
    tag = rfidString.substring(1, 13);
  }
}




// Get random image from the folder filelist array
void getImage(String tag,int picture) {
  String filenames[];

  try{
    // open the directory:
    File directory = new File(sketchPath("data")+"/"+tag);
   
    // list the files in the directory:
    filenames = directory.list();

    int picCounter=0;
    for(int thisFile = 0; thisFile<filenames.length; thisFile++){
      // if the file is a .jpg:
      if (filenames[thisFile].endsWith(".jpg")) {
        picCounter++;
        if(picCounter==picture)
        {
        // get the filename without the .jpg extension:
        String thisName = filenames[thisFile].substring(0, filenames[thisFile].length() -4);
        //if the filename matches the name of the person:
          // load the image from the file:
          thisImage = loadImage("data/"+tag+"/"+filenames[thisFile]);
          // show it:
          showImage = true;
        }
       }
    }
  }
  catch(Exception f){
    //  if there was a problem reading the directory:
    println("Image import error - missing thisFile or folder");
  }
}


Thanks
5  Using Arduino / Programming Questions / Potentiomter/ RFID values going wrong when I run processing ? on: May 26, 2013, 10:46:19 am
Hi, I am looking to use RFID to load a panorama like image and then use the potentiometer to scroll from left and right? But I am having a few problems processing reading the values.

When I look at the arduino code in the arduino serial monitor the potentiometer values and the RFID tag number run fine and I get reading like;
958,
955,
951,
953,
957,5100C2EB6F17
954,
958,
957,
951,

But when I run my processing code I get readings like these;
944,
950,
942,
9439543,
942,959
9,46,
940,948949
947949
94599,
9
49441,
3,9509
942,9,
94941,,
95,
9

What do I need to change, is it the processing code or the arduino ?

Thanks
6  Using Arduino / Programming Questions / Re: Arduino, Processing, potentiometer left and right values. on: April 26, 2013, 08:49:21 am
Hey, thanks for getting back again. I've been doing research, and trying different things and I still can't get my head around it, to get it working. Is there any chance that you might be able to point me in the right direction that does something similar? Just so I can see how its structured to read the numerical values for it to scroll right and left?

Many thanks
7  Using Arduino / Programming Questions / Re: Arduino, Processing, potentiometer left and right values. on: April 25, 2013, 12:05:25 pm
I apologise, I was just trying different things to see if I stumble onto anything. I know it's probably really simple to do, but I really don't what to change that value to?

Code:
import processing.serial.*;
Serial myPort;
String sensorReading="";

Do I need to add anything else here, for the code to read the values from the potentiometer ?

Cheers
8  Using Arduino / Programming Questions / Re: Arduino, Processing, potentiometer left and right values. on: April 25, 2013, 08:56:03 am
I've got to this part where i'm copying over from the code from the code where it reads the values from the potentiometer, but i'm struggling with the mapping part ? I'm not sure what needs to go into the '\n' part?
Code:
PImage img;
int x, moveSpeed = '10';
import processing.serial.*;
Serial myPort;
String sensorReading="";


 
void setup() {
  size(1000, 664);
    img = loadImage("imagescroll.jpg");
  for (int i=0; i<img.pixels.length; i++) {
    //img.pixels[i] = color(i%img.width%255,i/img.width%255,random(255));
  }
  x = -(img.width-width)/6; // start in middle
 
      myPort = new Serial(this, Serial.list()[16], 9600);
  myPort.bufferUntil('\n');


}
 
void draw() {
  float potentiometer = map('\n', 0, width, 0, 1023); // incoming 0 to 1023
  float movement = map('\n', 0, 1023, -moveSpeed, moveSpeed); // map from range (0, 1023) to (-moveSpeed, moveSpeed)
  x += movement; // add movement to location
  x = constrain(x, -(img.width-width), 0); // constrain image by 0 (at the beginning) and -600 (aka a remaining visible image width of 1000 equal to the canvas width).
  image(img, x, 0); // draw the image
  frame.setTitle(x + ""); // see the x in the top-lefta
}

void serialEvent (Serial myPort){
 sensorReading = myPort.readStringUntil('\n');
  if(sensorReading != null){
    sensorReading=trim(sensorReading);
  }
}

Cheers
9  Using Arduino / Programming Questions / Re: Arduino, Processing, potentiometer left and right values. on: April 25, 2013, 06:50:31 am
I've managed to get the slideshow to the movement of the mouse, How would I change it so it reads the values of the potentiometer to go left and right ?

Code:
PImage img;
int x, moveSpeed = 4;

 
void setup() {
  size(1000, 664);
  img = loadImage("imagescroll.jpg");
 

  for (int i=0; i<img.pixels.length; i++) {
    //img.pixels[i] = color(i%img.width%255,i/img.width%255,random(255));
  }
  x = -(img.width-width)/2; // start in middle
 
}

void draw() {
  float potentiometer = map(mouseX, 0, width, 0, 1023); // incoming 0 to 1023
  float movement = map(potentiometer, 0, 1023, -moveSpeed, moveSpeed); // map from range (0, 1023) to (-moveSpeed, moveSpeed)
  x += movement; // add movement to location
  x = constrain(x, -(img.width-width), 0); // constrain image by 0 (at the beginning) and -600 (aka a remaining visible image width of 1000 equal to the canvas width).
  image(img, x, 0); // draw the image
  frame.setTitle(x + ""); // see the x in the top-left
}
10  Using Arduino / Programming Questions / Re: Arduino, Processing, potentiometer left and right values. on: April 24, 2013, 12:40:34 pm
Would you be able to give an example on how I would structure the if statments for left, right and stop, specific to this code? I'm a little unfamiliar with if statements.

Many thanks
11  Using Arduino / Programming Questions / Re: Arduino, Processing, potentiometer left and right values. on: April 24, 2013, 10:28:11 am
I have used this code to find out if I'm getting serial data; Which works.

Code:
import processing.serial.*;
Serial myPort;
String sensorReading="";
PFont font;


void setup() {
  size(400,200);
  myPort = new Serial(this, Serial.list()[16], 9600);
  myPort.bufferUntil('\n');
  font = createFont(PFont.list()[2],32);
  textFont(font);
}

void draw() {
  //The serialEvent controls the display


void serialEvent (Serial myPort){
 sensorReading = myPort.readStringUntil('\n');
  if(sensorReading != null){
    sensorReading=trim(sensorReading);
  }

  writeText("Sensor Reading: " + sensorReading);
}


void writeText(String textToWrite){
  background(255);
  fill(0);
  text(textToWrite, width/20, height/2);   
}

I have started copying it over to my other code, but unsure how to write the code that tells it to go right, left or stop?
Would it be if Statements ?

Code:
import processing.serial.*;
Serial myPort;
String sensorReading="";
PImage img;
int x,y;
void setup()
  {
    size(1000,664); 
    img = loadImage("imagescroll.jpg"); // image is 1600 x 600
    myPort = new Serial(this, Serial.list()[16], 9600);
    myPort.bufferUntil('\n');
  }


void serialEvent (Serial myPort){
 sensorReading = myPort.readStringUntil('\n');
  if(sensorReading != null){
    sensorReading=trim(sensorReading);
  }

}

void draw()
{
  //  background(0);
      // not needed as image is bigger than size
     // and thus overwrites all areas
  x = constrain(x, 0, img.width - width);   
     // ensures that "scrolling" stops at right end of image
  // y = constrain(y, 0, img.height - height);
     // Not needed here, as scolling only in x
  image(img, -x, 0); 
     // overwrites the whole screen with the "shifted" image
  x = frameCount;     
     // advances the image with each new frame
     // do whatever is wanted from here on
     // like after a call of background();
  stroke(0,0,0);
  ellipse(mouseX,mouseY,15,15);
 
}
12  Using Arduino / Programming Questions / Re: Arduino, Processing, potentiometer left and right values. on: April 24, 2013, 09:56:51 am
No there's no code that reads serial data yet, thats what I'm looking to add to this code. Once I start running this code, its start an automatic scroll through the image (the one image that you see in the code, the width of the image is 5000, so when it loads in the 1000px frame, it scrolls through). I want to try and add a potentiometer that allows me to scroll left, right and stop the scroll through the image?
13  Using Arduino / Programming Questions / Arduino, Processing, potentiometer left and right values. on: April 24, 2013, 09:39:32 am
I'm working with Arduino and Processing, and I want to send serail data from arduino to processing and use the potentiometer to scroll left and right on an image. The code below is the processing code, which loads an image and is on a constant horizontal scroll. What I want to do is add code which reads values from the potentiometer, values near 512 would stop the scroll, anything below would scroll left and higher to the right. but I am unsure how to write this into the code ?

Code:
PImage img;
int x,y;
void setup()
  {
    size(1000,664); 
    img = loadImage("imagescroll.jpg"); // image is 1600 x 600
  }
void draw()
{
  //  background(0);
      // not needed as image is bigger than size
     // and thus overwrites all areas
  x = constrain(x, 0, img.width - width);   
     // ensures that "scrolling" stops at right end of image
  // y = constrain(y, 0, img.height - height);
     // Not needed here, as scolling only in x
  image(img, -x, 0); 
     // overwrites the whole screen with the "shifted" image
  x = frameCount;     
     // advances the image with each new frame
     // do whatever is wanted from here on
     // like after a call of background();
  //stroke(0,0,0);
  //ellipse(mouseX,mouseY,15,15);
}


thanks
14  Using Arduino / Programming Questions / RFID and Potentiometer code as one ? on: April 23, 2013, 09:49:46 am
Hi, I'm currently working on some code in processing which allows me to use RFID tags to load multiple images. I have the code that sends data from the RFID in Arduino to processing working, but I also want to send data for the potentiometer values over to processing but unsure how to code this, I have tried some attempts but no success.

Code for RFID

Code:
/* RFID ID12
*/

char val = 0; // variable to store the data from the serial port

void setup() {
Serial.begin(9600); // connect to the serial port
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
}

void loop () {
// read the serial port

if(Serial.available() > 0) {
val = Serial.read();
Serial.print(val, BYTE);

}
}

and code for the potentiometer;

Code:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}

If you want to see me processing code, i'll happily post it.

Thanks
15  Using Arduino / Project Guidance / Animating image sequence with button? on: April 18, 2013, 04:31:43 am
Over the past couple of months I have been working on getting RFID to load multiple images with music, I have that working. Now I just want a way to go through the images, and I was looking at using a button to do this. I'm not sure how I would include it in my arduino code that is sending serial data to the RFID and also adding the code into the processing code?

Thanks
Pages: [1] 2 3