Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Very, very strange bug! on: September 19, 2013, 01:22:31 pm
Ok guys, I think I found the reason. Actually, the code I wrote on the forums is a short version of some code that I'm using. I had declared time along with some other variables, like this:

int time, x, y = 10;

I don't think that this works in Arduino. I re-wrote the code like this:

int time = 10;
int x = 10;
int y =  10;

Now it all works.
2  Using Arduino / Programming Questions / Re: Very, very strange bug! on: September 19, 2013, 01:11:48 pm
I think you need to assign the initial value of time in the setup () function. Otherwise each time the Arduino is reset, the value of time will revert to zero, as will those other variables, I expect.

Paul

Hi and thanks for your answer.
Well, I've never had to do this before, however it did work in this case. The question remains, why?
3  Using Arduino / Programming Questions / Very, very strange bug! on: September 19, 2013, 12:24:39 pm
Hello. I have a strange bug and I just can't find it.


Code:
void setup(){
  Serial.begin(9600);
  pinMode(12, INPUT);
}


int time = 10;
int interval = 1000;
unsigned long previousMillis = 0;
boolean startButton = false;
bool ledOnce = true;

void loop(){
  startButton = digitalRead(12);
  unsigned long currentMillis = millis();

  if(startButton == HIGH){
    ledOnce = false;
  }
 
  if(ledOnce == false){         
    if(currentMillis - previousMillis > interval){
      time++;
      previousMillis = currentMillis;
      Serial.println(time);
    }
  }
 
}


For each iteration, time should increase by one( 11, 12, 13...). However, time starts at 0 and goes 1..2..3..4... Actually, no matter which value I give time when declaring the variable, it will start at 0.

Does anyone know why?

Please help,
Thanks in advance!

PS: I just noticed that this is not in the "Programming Questions" section, sorry for that. Could an admin move this thread perhaps? Thanks.
4  Using Arduino / Interfacing w/ Software on the Computer / Re: My first encounter with Processing! on: June 30, 2013, 02:20:50 pm
Of course I can't understand the write() values. I changed the code up in order to make sure the potentiometer is working as intended, and then changed it back so that it can communicate with Processing.


I am supposed to change the amount of bytes in the buffer with the Serial.write() right? Because I still can't change that.


************EDIT************

FINALLY! I solved my issues. I simply increased the delay in the Arduino sketch, so instead of a 1 ms delay after each write(), I changed it to 100 ms!

However, I'm still interested about how this communication really works. Where can I read about this?

THANKS PaulS!
5  Using Arduino / Interfacing w/ Software on the Computer / Re: My first encounter with Processing! on: June 29, 2013, 02:09:28 pm
I know the values are good because I looked at them in Arduino. However, they are uncontrollable in Processing.

1. The read() values work well with the background() function, the colours change and so on. The problem is, I can't change the read() values myself by twisting the potentiometer. I can only change them in the Arduino IDE, but when I twist the potentiometer, I see no chance in Processing.
6  Using Arduino / Interfacing w/ Software on the Computer / Re: My first encounter with Processing! on: June 29, 2013, 12:14:12 pm
Hey and thanks again for your quick answer. I am using a .png image, which has transparent areas. It's the correct image type to use. 

I already did the tests you recommended and everything worked fine. I get correct values from the potentiometer. 

My code is pretty much identical to the code in the book. By the way, I'm using the 32-bit version of Processing (simply because Serial does not work on the 64-bit version). Could that affect communication?
7  Using Arduino / Interfacing w/ Software on the Computer / Re: My first encounter with Processing! on: June 29, 2013, 11:37:52 am
Sorry, didn't mean to make a smiley face, it was just part of the code.

I'll post the arduino code:
Code:
void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.write(analogRead(A1) / 4);
  delay(1);
}

I got the values to go between 0 and 255 now (as it should), however I can't change the colors myself. Basically, I have no control over the myPort.read() values. At the moment it's sitting on 70, but in a few seconds it'll probably bounce up to 255 or something.

8  Using Arduino / Interfacing w/ Software on the Computer / Re: My first encounter with Processing! on: June 29, 2013, 10:02:04 am
I feel that I have no control over the buffer. Maybe I shouldn't? But if I shouldn't, how can I possibly control the colours with the amount of bytes in the buffer?

This whole project is fishy!
9  Using Arduino / Interfacing w/ Software on the Computer / Re: My first encounter with Processing! on: June 29, 2013, 07:31:28 am
Thx for your quick reply!

Which sending code is it that you are talking about? The code from my arduino? ( Serial.write(analogRead((A1)/4))smiley-wink

Thank you for informing me about serialEvent(), I'll definately read up on it. However, the code I posted is pretty much identical to the code that was provided in the book, so at the very least it ought to work, dont u think?

10  Using Arduino / Interfacing w/ Software on the Computer / My first encounter with Processing! on: June 29, 2013, 06:55:31 am
Hello.

I'm fairly new to Arduino & even greener when it comes to Processing, and I've encountered a problem.

I'm trying to do project 14 in the "Arduino projects book". Basically, I want to change the background color of an image using a potentiometer.

Here is my code (including some comments to help myself keep track of things, correct me if they are wrong):

Code:
import processing.serial.*;
Serial myPort;

PImage logo;

int bgcolor = 0;

void setup() {

  colorMode(HSB, 255);

  logo = loadImage("http://www.userlogos.org/files/logos/jumpordie/teamliquid-iphone.png");
  size(logo.width, logo.height);

  println("Avilable serial ports");
  println(Serial.list());

  myPort = new Serial(this, Serial.list()[1], 9600); // parameters : which application, which port & what speed
}

void draw() {
  if (myPort.available() > 0) { // if(there is something in the buffer)
    bgcolor = myPort.read();
    println(bgcolor);
  }

  background(bgcolor, 255, 255); // hue, brightness, saturation. max value 255
  image(logo, 0, 0); // image() is used to draw. --- what to draw , x-coordiante to start, y-coordiante to start ---
}

I don't really understand the values I get from myPort.read(). They bounce between 100 and -1, barely depending on how I position the potentiometer. Basically, this results in the background colors shifting constantly, leaving me unable to control them.

So, how can I fix this?

Can someone explain this myPort.read() for me please? I thought that it just took the values from the port I connected my potentiometer to on the Arduino (which is basically just analogRead((A1) / 4); )

Secondly, can I use any image for this, or does it have to be a specific image type?

This image shows the values! http://oi43.tinypic.com/f4iaaa.jpg

Thanks for taking your time to read this, please help!
11  Products / The Arduino Starter Kit / Re: Project 14 (Tweak the Arduino Logo) on: June 27, 2013, 09:49:06 am
I've run into some trouble on this project again.

I can change the background color but it keep's flashing. I think it's because of my port.read() values. They pretty much always bounce between 55 and 10, hardly taking notice of how much I've turned the potentiometer.

I have no experience dealing with serial communication, so I'm a bit lost at the moment.

My code:

Code:
import processing.serial.*;
Serial myPort;

PImage logo;

int bgcolor = 0;

void setup() {

  colorMode(HSB, 255);

  logo = loadImage("http://www.userlogos.org/files/logos/jumpordie/teamliquid-iphone.png");
  size(logo.width, logo.height);

  println("Avilable serial ports");
  println(Serial.list());

  myPort = new Serial(this, Serial.list()[1], 9600); // parameters : which application, which port & what speed
}

void draw() {
  if (myPort.available() > 0) { // if(there is something in the buffer)
    bgcolor = myPort.read();
    print("     ");
    println(myPort.read());
    println(bgcolor);
  }

  background(bgcolor, 255, 255); // hue, brightness, saturation. max value 255
  image(logo, 0, 0); // image() is used to draw. --- what to draw , x-coordiante to start, y-coordiante to start ---
}

1. Does anyone know what I should do in order to get proper readings?

2. What type of images can I use? Any image, or does it have to be a .jpg, .png etc...?

Thanks in advance!!
12  Products / The Arduino Starter Kit / Re: Project 14 (Tweak the Arduino Logo) on: June 27, 2013, 05:50:08 am
EDIT**
I restarted my PC n no it work's just as intended.
13  Products / The Arduino Starter Kit / Re: Project 13, library error! on: June 26, 2013, 06:27:23 am
Thx!
14  Products / The Arduino Starter Kit / Re: Project 14 (Tweak the Arduino Logo) on: June 26, 2013, 06:27:09 am
Hello.

I downloaded the 32-bit version but I still can't compile. I get the same error that I got on the 64-bit version,

"serial is only compatibl wit the 32-bit download of Processing."

.

Someone pls help!
15  Products / The Arduino Starter Kit / Re: New user on: June 24, 2013, 11:52:55 am
Welcome! Post again if you need help with anything!
Pages: [1] 2