Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Re: sending multiple values in port.write in processing on: February 25, 2011, 06:41:59 am
hehe its me again.Thx alot Paul for the guidance. I finally got it all working smoothly!!!!. only thing i did was to start reading the serial port after 4 bytes.

 
Code:
if (Serial.available() >= 4)
      { //  Check if there is a new message
     dirA= Serial.read();    //  Put the serial input into the message
     dirB= Serial.read();    //  Put the serial input into the message         
     pwmMotorA = Serial.read();
     pwmMotorB = Serial.read();
2  Using Arduino / Interfacing w/ Software on the Computer / Re: sending multiple values in port.write in processing on: February 25, 2011, 03:52:40 am
Quote
What is going to happen when you try to read the 3rd and 4th values?

I dont really get what you are trying to tell me? I think its just going to put a zeros in the 3rd & 4th serial.read line?

Greetings
ELOLEDBALL

3  Using Arduino / Interfacing w/ Software on the Computer / Re: sending multiple values in port.write in processing on: February 24, 2011, 07:16:36 pm
the 2nd part...

Processing sketch
Code:
/*
// importeer de volgende libraries serial,oscP5 en arduino classes voor communicatie met de arduino,IPOD en seriele verbinding.
import oscP5.*;
import netP5.*;
import processing.serial.*;
import cc.arduino.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
Serial arduinoPort;
Arduino arduino;


int [] Toggle1 = new int [8];
int [] Toggle2 = new int [8];
int [] sliderStrip = new int [5];
float [] fader1 = new float [8];
float [] fader2 = new float [8];
boolean sliderNeedsRedraw = true;



int pwmMotorA,pwmMotorB = 0 ;
int EN1 = 12;
int EN2 = 11;  //PWM uitgangen
int IN1 = 10;
int IN2 = 9;  //Draairichting

int dirA,dirB=  0;


int laag =0;
int hoog =255;
int myMessage1 = 0;
int myMessage2 = 0;
int myMessage3 = 0;
int myMessage4 = 0;
int myMessage5 = 0;
int myMessage6 = 0;

void setup() {
  size(290,360);
  frameRate(25);
  background(0);
   fader1[1] = 0.5;
   fader2[1] = 0.5;

  /* start oscP5, listening for incoming messages at port 8000 */
  oscP5 = new OscP5(this,8000);
  myRemoteLocation = new NetAddress("192.168.62.55",9000); //IP address for outgoing data
    
   arduinoPort = new Serial(this, "COM4", 9600);    // Set arduino to 9600 baud
}

void oscEvent(OscMessage theOscMessage)
{
                     OscMessage myMessage1 = new OscMessage("/1/led1");  //used to store status of the motor
                     OscMessage myMessage2 = new OscMessage("/1/led2");
                     OscMessage myMessage3 = new OscMessage("/1/led3");
                     OscMessage myMessage4 = new OscMessage("/2/led1");
                     OscMessage myMessage5 = new OscMessage("/2/led2");
                     OscMessage myMessage6 = new OscMessage("/2/led3");
                    
   String addr = theOscMessage.addrPattern();
    // println(addr);   // uncomment for seeing the raw meshsage
   //float  val  = theOscMessage.get(0).floatValue();
if(addr.indexOf("/1/fader") !=-1)
{ // one of the faders
String list[] = split(addr,'/');
int  xfader = int(list[2].charAt(5) - 0x30);
fader1[xfader]  = theOscMessage.get(0).floatValue();
// println(" x = "+fader[xfader]);  // uncomment to see x values
sliderNeedsRedraw = true;
                        
                        pwmMotorA=int(255*(fader1[1]));
                      
                      
        
}
                        if(addr.indexOf("/2/fader") !=-1)
{ // one of the faders
  String list[] = split(addr,'/');
int  xfader = int(list[2].charAt(5) - 0x30);
fader2[xfader]  = theOscMessage.get(0).floatValue();
  // println(" x = "+fader[xfader]);  // uncomment to see x values
sliderNeedsRedraw = true;
                               pwmMotorB= int((255*(fader2[1])));
                              
                                
        
}
                                  

                         if(addr.indexOf("/1/toggle") !=-1)// the strip at the bottom
{  
int i = int((addr.charAt(9) )) - 0x30;   // retrns the ASCII number so convert into a real number by subtracting 0x30
String list[] = split(addr,'/');
Toggle1[i]  = int(theOscMessage.get(0).floatValue());
// println(" i = "+i);   // uncomment to see index value
sliderNeedsRedraw = true;
                        }
                        
                     if(addr.indexOf("/2/toggle") !=-1)// the strip at the bottom
{  
int i = int((addr.charAt(9) )) - 0x30;   // retrns the ASCII number so convert into a real number by subtracting 0x30
String list[] = split(addr,'/');
Toggle2[i]  = int(theOscMessage.get(0).floatValue());
// println(" i = "+i);   // uncomment to see index value
sliderNeedsRedraw = true;
                        }

//bestuderen van de druktoetsen
if (Toggle1[2]==1)
{                  
                     dirA= '3';
                      
                     myMessage1.add(0); /* add an int to the osc message */
                     myMessage2.add(0); /* add an int to the osc message */
                     myMessage3.add(1); /* add an int to the osc message */
                    
                                        
                      /* send the message */
                      oscP5.send(myMessage1, myRemoteLocation);
                      oscP5.send(myMessage2, myRemoteLocation);
                      oscP5.send(myMessage3, myRemoteLocation);
                        
                      
}
else {
  if(Toggle1[1] == 1)
{
   dirA = '2';    

                    myMessage1.add(0); /* add an int to the osc message */
                    myMessage2.add(1); /* add an int to the osc message */
                    myMessage3.add(0); /* add an int to the osc message */
                    

                    /* send the message */
                    oscP5.send(myMessage1, myRemoteLocation);
                    oscP5.send(myMessage2, myRemoteLocation);
                    oscP5.send(myMessage3, myRemoteLocation);
                    
                    
}
else

{
   dirA= '1';
                          
                    
                     myMessage1.add(1); /* add an int to the osc message */
                     myMessage2.add(0); /* add an int to the osc message */
                     myMessage3.add(0); /* add an int to the osc message */
    
                    /* send the message */
                    oscP5.send(myMessage1, myRemoteLocation);
                    oscP5.send(myMessage2, myRemoteLocation);
                    oscP5.send(myMessage3, myRemoteLocation);
                      
                      
}
}


if (Toggle2[2]==1)
{                  
   dirB= '3';
       
                                  
                    myMessage4.add(0); /* add an int to the osc message */
                    myMessage5.add(0); /* add an int to the osc message */
                    myMessage6.add(1); /* add an int to the osc message */
                    
                                        
                    /* send the message */
                    oscP5.send(myMessage4, myRemoteLocation);
                    oscP5.send(myMessage5, myRemoteLocation);
                    oscP5.send(myMessage6, myRemoteLocation);
                        
                      
}
else {
  if(Toggle2[1] == 1)
{
                    dirB= '2';
                        
                    myMessage4.add(0); /* add an int to the osc message */
                    myMessage5.add(1); /* add an int to the osc message */
                    myMessage6.add(0); /* add an int to the osc message */
                    

                    /* send the message */
                    oscP5.send(myMessage4, myRemoteLocation);
                    oscP5.send(myMessage5, myRemoteLocation);
                    oscP5.send(myMessage6, myRemoteLocation);
                    
                    
}
else

{

                     dirB= '1';
                  
                     myMessage4.add(1); /* add an int to the osc message */
                     myMessage5.add(0); /* add an int to the osc message */
                     myMessage6.add(0); /* add an int to the osc message */
    
                      /* send the message */
                      oscP5.send(myMessage4, myRemoteLocation);
                      oscP5.send(myMessage5, myRemoteLocation);
                      oscP5.send(myMessage6, myRemoteLocation);
                      
                      
}
}
arduinoPort.write(dirA);  //send direction onto serialport
arduinoPort.write(dirB);
arduinoPort.write(pwmMotorA);
arduinoPort.write(pwmMotorB);




}



//here follows the code for drawing the slider and toggle buttons on the screen but i deleted it else couldnt post the sketch




4  Using Arduino / Interfacing w/ Software on the Computer / Re: sending multiple values in port.write in processing on: February 24, 2011, 07:12:35 pm
hey guys, sry to say i still havent figured it out.I ll just go ahead and repost the code of what u v got so far :p

Arduino sketch
Quote

int EN1 = 8; //pwm motorA
int EN2 = 9; //pwm motorB
int IN1 = 10; //direction motorA
int IN2 = 11; //direction motorB


int laag = 0;
int hoog= 255;
int pwmMotorA=0;
int pwmMotorB=0;
int dirA,dirB=0 ;


void setup()

Serial.begin(9600);





void loop()




      if (Serial.available() > 0) { //  Check if there is a new message
      dirA= Serial.read();    //  Put the serial input into the message
      dirB= Serial.read();    //  Put the serial input into the message
      pwmMotorA = Serial.read();
      pwmMotorB = Serial.read();
      }                    
       switch(dirA)
                    
               {
                                     
               case '1': //Move ahead M1
                        Motor1(pwmMotorA,true);  //You can change the speed, such as Motor(50,true)  
                        break;
               case '2': //move back M1
                        Motor1(pwmMotorA,false);
                        break;
               case '3': //stop M1
                        Motor1(0,false);
                        break;
               
                                        default:
                                        Motor1(pwmMotorA,true);
                                        break;
                                            
                           
               }  
 switch(dirB)
                    
               {
                                     
               
               case '1': //Move ahead M2
                        Motor2(pwmMotorB,true);//You can change the speed, such as Motor(50,true)
                        break;
               case '2': //move back M2
                        Motor2(pwmMotorB,false);
                        break;
               case '3': //stop M2
                        Motor2(0,false);
                        break;
                                        default:
                                        Motor2(pwmMotorB,true);
               break;
                                            
                           
               }    
        
      

   
   
}

void Motor1(int pwmMotorA, boolean reverse) //handelen van motorA
   {
             analogWrite(EN1,pwmMotorA); //set pwm control, 0 for stop, and 255 for maximum speed
             if(reverse)
             {
              analogWrite(IN1,hoog);  
             }
            else
            {
             analogWrite(IN1,laag);  
            }
        } 
         
void Motor2(int pwmMotorB, boolean reverse)//handelen van motorB
        {
          analogWrite(EN2,pwmMotorB);
          if(reverse)
          {
           analogWrite(IN2,hoog);
          }
         else
         {
          analogWrite(IN2,laag);  
          }
       } 




5  Using Arduino / Interfacing w/ Software on the Computer / Re: sending multiple values in port.write in processing on: February 23, 2011, 07:06:21 am
thx for the fast reply Paul. But it still isnt working. I tried your code:
Quote
port.write('1');
port.write(pwmMotorA);
port.write('2');
port.write(pwmMotorB);
by sending my variables one by one.To slow reaction on the arduino.The first line port.write('1') is actually a variabele i use to detect in arduino in which mode the motor is in(like forward/back/stop). Am considering is using seperators like i read somewhere. ie a
Quote
port.write(<variabele,pwmMotorA>);
Isnt this going to send all of them as a string? Thx in advance.
6  Using Arduino / Interfacing w/ Software on the Computer / sending multiple values in port.write in processing on: February 22, 2011, 07:00:29 am
Hey guys,
   I am making a project for school as a thesis. The idea is to use the TouchOsc App op my ipod to control the speed and direction of the two dc motors with the arduino Mega.Basically processing receives the data from touchosc app and sends for example port.write('1'). In my arduino code i have made a switchcase whereby i do a serial.read and uses this decide where button was pushed(like move forward/backwards). Which is working smoothly. My main problem is i have to send in addition to the port.write('1') also my pwmMotorA with is an integer from one the sliders on my touchOsc app.Is there a way to send them both in like port.write( '1',pwmMotorA)? when i do that arduino just sees it as an ASCII code..I have searched almost whole google for this..with no results. I have included my arduino and processing sketch.
Pages: [1]