Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Troubleshooting / Re: error when trying to merge two pieces of code on: May 20, 2009, 06:05:18 am
 smiley thanks for that, i'll check it out tonight and see if it works or if any more errors occur

thanks again
2  Forum 2005-2010 (read only) / Troubleshooting / error when trying to merge two pieces of code on: May 19, 2009, 04:09:13 pm
hi there

i hope someone can please help me, i have posted this in the syntax and programs part of the forum but maybe here is a better place

i have two pieces of code and i need to merge them together and i am a bit stuck.

the first bit of code is arduino2max code which has been changed a little so that it reads values from 6 distance sensors on a wall which are chained together so that it repeatedly reads the values from the sensors in a loop and sends them to the arduino analogue pins and from there into max msp

i am trying to incorporate some code for a pir sensor that is connected to a digital pin so that when the pir sensor detects motion it then turns on sound in max msp and if no motion is detected it turns the sound off.  

hopefully this will solve a problem that i am having with the distance sensors which sometimes give false readings when no one is present and therefore make unwanted sounds

this is the arduino2max code
Code:
int x = 0;                              // a place to hold pin values
int ledpin = 13;


void setup()
{
  Serial.begin(115200);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(13,INPUT);

  delay(500);
  digitalWrite(12,HIGH);              // this part is the code to send the first pin in the                                      
  delay(20);                               //  chain high so that the sensors then give continuous reading                                        
  digitalWrite(12,LOW);            //    one after the other          
  pinMode(12, INPUT);    
  }    
          

and this is the pir sensor code, from elsewhere on this site
Code:
int ledPin = 13; // led connected to control pin 13
int PIRSensor = 2; // the PIR sensor will be plugged at digital pin 2
int state = 0; // variable to store the value read from the sensor pin
int statePin = LOW; // variable used to store the last LED status, to toggle the light

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
pinMode(PIRSensor, INPUT); // declare the PIRSensor as as OUTPUT
Serial.begin(9600); // use the serial port
}

void loop() {
state = digitalRead(PIRSensor); // read the sensor and store it in "state"

if (state != 0)
{
digitalWrite(LED1, HIGH);
Serial.println("Motion Detected!"); // send the string "Motion Detected!" back // to the computer
}
else
digitalWrite(LED1, LOW); // turns light off if motion is not detected

delay(100); // we have to make a delay to avoid overloading the serial port

i have tried to merge the two so that the arduino first checks the pir sensor then goes through a loop of the distance sensors then goes back to check the pir sensor again, this is what i have managed so far
Code:
int x = 0;                              // a place to hold pin values
int ledpin = 13;
int PIRSensor = 2; // the PIR sensor will be plugged at digital pin 2 -
int state = 0; // variable to store the value read from the sensor pin -
int statePin = LOW; // variable used to store the last LED status, to toggle the light -

void setup()
{
 pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT -
 pinMode(PIRSensor, INPUT); // declare the PIRSensor as as OUTPUT -
  Serial.begin(115200);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(13,INPUT);

  delay(500);
  digitalWrite(12,HIGH);              // this part is the code to send the first pin in the                                      
  delay(20);                               //  chain high so that the sensors then give continuous reading                                        
  digitalWrite(12,LOW);            //    one after the other          
  pinMode(12, INPUT);    
  }    
          
                                  
                                          



void loop()
{
state = digitalRead(PIRSensor); // read the sensor and store it in "state" -
if (state != 0)
{
digitalWrite(LED1, HIGH);
Serial.println("Motion Detected!"); // send the string "Motion Detected!" back // to the computer
}
else
digitalWrite(LED1, LOW); // turns light off if motion is not detected

delay(100); // we have to make a delay to avoid overloading the serial port
}

if (Serial.available() > 0){         // Check serial buffer for characters
        
    if (Serial.read() == 'r') {       // If an 'r' is received then read the pins
    
    for (int pin= 0; pin<=5; pin++){      // Read and send analog pins 0-5
    x = analogRead(pin);
    sendValue (x);
    }

    for (int pin= 2; pin<=13; pin++){     // Read and send digital pins 2-13
    x = digitalRead(pin);
    sendValue (x);
    }
  
    Serial.println();                 // Send a carriage returnt to mark end of pin data.
    delay (5);                        // add a delay to prevent crashing/overloading of the serial port
  
  }

 }
}

void sendValue (int x){              // function to send the pin value followed by a "space".
 Serial.print(x);
 Serial.print(32, BYTE);
}



 

but when i try and compile it i get an error "ledPin was not declared in this scope in function void loop".  
this is quite beyond my newbieness and i am struggling to understand.

can anyone help me out please?

many thanks
3  Forum 2005-2010 (read only) / Syntax & Programs / help required with changing arduino2max code on: April 14, 2009, 02:33:21 pm
hi
i am trying to get six sensors chained together so they constantly loop and send their readings into maxmsp using the arduino2max code, as i discovered the other day that they cant all just 'free run' like i had them set originally as they give inaccurate readings

i have spent most of the day doing the rewiring as is detailed on the maxbotix site here :

http://www.maxbotix.com/uploads/Chaining_Application_Notes__AN_Output_Constantly_Looping_.pdf

but now i am having trouble with adapting the arduino2max code which is where my knowledge lets me down smiley-sad

it says on the page "you will have to "kick start" them, (at least 250mS or more after power is applied to the sensors to give the sensors this time to boot-up). To do this, pull the RX pin high on the first sensor for at least 20uS. Then the micro controller will have to return it's pin to a high impedance state so that the next time around the TX output from the last sensor will make it's way to the RX of the first sensor. Then all of the sensors in the chain will run in sequence." but i am having trouble turning this in the required code

can anyone help me with writing this bit of code? as you see in the example i have tried to use the digital pin 12 to do the 'kick starting' but i just keep getting error messages and i get stuck

many thanks for any help in advance


Code:
int x = 0;                              // a place to hold pin values
int ledpin = 13;
int kickstart = 12;

void setup()
{
  Serial.begin(115200);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(13,INPUT);
  }
  {
  digitalWrite(12,HIGH);             /// this is the code i have managed so far but i am a bit stuck
  delay(20);
  digitalWrite(12,LOW);
  }



void loop()
{

if (Serial.available() > 0){         // Check serial buffer for characters
        
    if (Serial.read() == 'r') {       // If an 'r' is received then read the pins
    
for (int pin= 0; pin<=5; pin++){      // Read and send analog pins 0-5
    x = analogRead(pin);
    sendValue (x);
    }

for (int pin= 2; pin<=13; pin++){     // Read and send digital pins 2-13
    x = digitalRead(pin);
    sendValue (x);
    }
  
    Serial.println();                 // Send a carriage returnt to mark end of pin data.
    delay (5);                        // add a delay to prevent crashing/overloading of the serial port
  
  }

 }
}

void sendValue (int x){              // function to send the pin value followed by a "space".
 Serial.print(x);
 Serial.print(32, BYTE);
}



4  Forum 2005-2010 (read only) / Syntax & Programs / Re: please help - merging 2 pieces of code on: May 20, 2009, 12:45:38 am
im sorry, i wasnt sure i had posted in the relevant forum
5  Forum 2005-2010 (read only) / Syntax & Programs / please help - merging 2 pieces of code on: May 19, 2009, 12:21:52 pm
hi there

i hope someone can please help me

i have two pieces of code and i need to merge them together and i am a bit stuck.

the first bit of code is arduino2max code which has been changed a little so that it reads values from 6 distance sensors on a wall which are chained together so that it repeatedly reads the values from the sensors in a loop and sends them to the arduino analogue pins

i am trying to incorporate some code for a pir sensor that is connected to a digital pin so that when the pir sensor detects motion it then turns on sound in max msp and if no motion is detected it turns the sound off.  

hopefully this will solve a problem that i am having with the distance sensors which sometimes give false readings when no one is present and therefore make unwanted sounds

this is the arduino2max code :
Code:
int x = 0;                              // a place to hold pin values
int ledpin = 13;


void setup()
{
  Serial.begin(115200);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(13,INPUT);

  delay(500);
  digitalWrite(12,HIGH);              // this part is the code to send the first pin in the                                      
  delay(20);                               //  chain high so that the sensors then give continuous reading                                        
  digitalWrite(12,LOW);            //    one after the other          
  pinMode(12, INPUT);    
  }    
          
                                  
                                          



void loop()
{

if (Serial.available() > 0){         // Check serial buffer for characters
        
    if (Serial.read() == 'r') {       // If an 'r' is received then read the pins
    
    for (int pin= 0; pin<=5; pin++){      // Read and send analog pins 0-5
    x = analogRead(pin);
    sendValue (x);
    }

    for (int pin= 2; pin<=13; pin++){     // Read and send digital pins 2-13
    x = digitalRead(pin);
    sendValue (x);
    }
  
    Serial.println();                 // Send a carriage returnt to mark end of pin data.
    delay (5);                        // add a delay to prevent crashing/overloading of the serial port
  
  }

 }
}

void sendValue (int x){              // function to send the pin value followed by a "space".
 Serial.print(x);
 Serial.print(32, BYTE);
}



 

and this is the pir sensor code, from elsewhere on this site
Code:
int ledPin = 13; // led connected to control pin 13
int PIRSensor = 2; // the PIR sensor will be plugged at digital pin 2
int state = 0; // variable to store the value read from the sensor pin
int statePin = LOW; // variable used to store the last LED status, to toggle the light

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
pinMode(PIRSensor, INPUT); // declare the PIRSensor as as OUTPUT
Serial.begin(9600); // use the serial port
}

void loop() {
state = digitalRead(PIRSensor); // read the sensor and store it in "state"

if (state != 0)
{
digitalWrite(LED1, HIGH);
Serial.println("Motion Detected!"); // send the string "Motion Detected!" back // to the computer
}
else
digitalWrite(LED1, LOW); // turns light off if motion is not detected

delay(100); // we have to make a delay to avoid overloading the serial port
}

i hope that this is clear and someone can help me out as i am desperately trying to get this sorted out for an impending show

many thanks in advance for any advice

 smiley
6  Forum 2005-2010 (read only) / Interfacing / help required with changing arduino2max code on: April 15, 2009, 11:29:16 am
hi

i posted this in the syntax and programs forum but on second thoughts maybe this is a better place to post it


i am trying to get six sensors chained together so they constantly loop and send their readings into maxmsp using the arduino2max code, as i discovered the other day that they cant all just 'free run' like i had them set originally as they give inaccurate readings

i have spent most of the day doing the rewiring as is detailed on the maxbotix site here :

http://www.maxbotix.com/uploads/Chaining_Application_Notes__AN_Output_Constantly...

but now i am having trouble with adapting the arduino2max code which is where my knowledge lets me down

it says on the page "you will have to "kick start" them, (at least 250mS or more after power is applied to the sensors to give the sensors this time to boot-up). To do this, pull the RX pin high on the first sensor for at least 20uS. Then the micro controller will have to return it's pin to a high impedance state so that the next time around the TX output from the last sensor will make it's way to the RX of the first sensor. Then all of the sensors in the chain will run in sequence." but i am having trouble turning this in the required code

can anyone help me with writing this bit of code? as you see in the example i have tried to use the digital pin 12 to do the 'kick starting' but i just keep getting error messages and i get stuck

many thanks for any help in advance

Code:
int x = 0;                              // a place to hold pin values
int ledpin = 13;
int kickstart = 12;

void setup()
{
  Serial.begin(115200);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(13,INPUT);
  }
  {
  digitalWrite(12,HIGH);             /// this is the code i have managed so far but i am a bit stuck
  delay(20);
  digitalWrite(12,LOW);
  }



void loop()
{

if (Serial.available() > 0){         // Check serial buffer for characters
        
    if (Serial.read() == 'r') {       // If an 'r' is received then read the pins
    
for (int pin= 0; pin<=5; pin++){      // Read and send analog pins 0-5
    x = analogRead(pin);
    sendValue (x);
    }

for (int pin= 2; pin<=13; pin++){     // Read and send digital pins 2-13
    x = digitalRead(pin);
    sendValue (x);
    }
  
    Serial.println();                 // Send a carriage returnt to mark end of pin data.
    delay (5);                        // add a delay to prevent crashing/overloading of the serial port
  
  }

 }
}

void sendValue (int x){              // function to send the pin value followed by a "space".
 Serial.print(x);
 Serial.print(32, BYTE);
}



 

 
Back to top      
7  Forum 2005-2010 (read only) / Interfacing / Re: advice on running 6 maxbotix ez4 sensors on: April 14, 2009, 10:44:52 am
thanks for the replies

ive been in contact with maxbotix over the last few days and am in the process of rewiring them now to chain them together so they constantly loop

i think i just have to add a little bit of code into the arduino2max code :
can anyone give me a hand with that?  smiley

thanks again
8  Forum 2005-2010 (read only) / Interfacing / advice on running 6 maxbotix ez4 sensors on: April 12, 2009, 02:35:03 pm
hi

i am nearing the end of my degree project and i have hit a (hopefully) little problem which i didnt anticipate, mainly due to my lack of knowledge.

i have made a large (3metre x 2 metre) interactive painting which contains 6 maxbotix ez4 sensors spaced about a metre apart.  

each sensor goes into an analogue pin on the arduino and from there i pick up the results in maxmsp using the arduino2max code.

they work ok when i run one at a time but when i plug them all in the results go really erratic and pretty unusable.  i thought i could sort the problem out with max msp but from doing a bit of research from the maxbotix website it appears that i may need to either reprogram the arduino and/or do some rewiring.

i emailed maxbotix and got a good reply but im a little in the dark about some of the knowhow.

i think i need to have the sensors chained together so they give readings one after another and not all at the same time as they do at the moment.  this will involve connecting the tx to the rx of each sensor, which i think i can do.

then the guy from maxbotix said -"Then you must use your uC to bring the first RX high for a short time, (say >20uS but less than 50mS what I have called "strobe")."  which i dont understand but i assume it means i have to put some more code into the arduino.  can anyone advise me on this?

i'll ask him about this tomorrow but i thought i would ask here too so i can get as much advice as possible

-does anyone have any experience with these sensors or similar?

-can anyone give me any advice as regards chaining them together?
(is this necessary or is there another way to get them to give accurate reading when running six at once?)

-can i add extra code to the arduino2max code that will enable me to read the first rx high? or is there another way?

i hope this all makes sense and someone can give me a hand smiley

many thanks in advance



9  Forum 2005-2010 (read only) / Frequently-Asked Questions / ping sensor and serial object in max msp on: August 22, 2008, 08:49:08 am
hi again

i have set up a ping sensor with my diecimila and am using this code from the site :

http://www.arduino.cc/playground/Main/UltrasonicSensor

it seems to work ok and i can see good numbers reflecting distance in the serial monitor.  i am trying to get these distance numbers into max msp using the serial object.  i am using a print data object out of the serial objects left outlet but the numbers that are showing up in the max window are not the same distance numbers and are only two digits, though they do change when i move my hand in front of the sensor.

can anyone help me please and tell me what i am doing wrong (or what i dont understand) and give me an idea how i can get the distance numbers which are in the serial monitor to show up in max



many thanks smiley
10  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: ping sensors, simple message system and max ms on: August 18, 2008, 06:15:42 pm
hi again, i am sorry but i am getting confused, more than usual.  i have just been using one ping sensor set up with this code here http://little-scale.blogspot.com/2008/04/ping-time.html and i have managed to sort out the com port problem (i think i have to upload the code and then switch the port).
though the only value recognised in the max window is 0 - why is this as the ping sensor seems to be quickly flashing?

if i upload the simple message system to the board and open that patch in maxmsp then nothing seems to work, and i still cant work out what to do about the itoa missing object. is there anything else around which will do the job the same?

forgive my lack of knowledge but it is coming very slowly so if anyone can give my any information or advice then it would be much appreciated


many thanks
11  Forum 2005-2010 (read only) / Frequently-Asked Questions / ping sensors, simple message system and max msp on: August 13, 2008, 05:09:35 pm
hi again

following on from this thread of a few months ago:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210244089/13#13

i have now got a couple of ping sensors and have got as far as wiring one up to my diecimila and getting numeric responses in the arduino window, aside from doing numerous other learning examples

as i want to get max msp to read these numbers and then do things with them i have started looking into the simple message system library here on the arduino website. it seems to have installed ok but there are a few things on the max msp side which i am unsure about, so hopefully someone can give me some advice :

- how do i make sure that max msp is reading from the correct com port?

- i am using an old version of max (4.3) and it doesnt recognise the itoa object, i have tried to download an external object for it from the ircam site but i get a bin file named EllisonFAT.sea.bin which i have no idea what to do with. any ideas?

- as i want to hopefully use 6 (or maybe smiley-cool sensors then is this simple message system the right way to go? or is there another method to send sensor values from arduino to max which i am so far unaware of?

i am using windows xp by the way

many thanks for any advice



12  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: question about distance sensors on: June 12, 2008, 07:46:26 am
ive been scouring the web looking for a supplier of the parallax ping sensor in the uk but havent been able to find one, i emailed parallax too but so far they havent replied.
 
does anyone know of a uk supplier for them or am i going to have to order direct from parallax? or i may look around for a similar sensor from a different company, though the parallax one seems to suit my requirements most

continued thanks
13  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: question about distance sensors on: June 10, 2008, 12:25:03 pm
hi again

i see here http://www.arduino.cc/en/Tutorial/UltrasoundSensor that someone has written code for one of those ping sensors.  what is the maximum i can use on one diecimila without using one of those multiplexor things? 6?

ive now got a diecimila and am working through the tutorials, turning leds on and off and suchlike.  still plenty to learn, fun though

thanks
14  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: question about distance sensors on: May 27, 2008, 10:53:10 am
hi again

thanks again for the advice

can i ask : if i go for the Diecimila, will it be able to support maybe 8 or 10 of the PING))) Ultrasonic Sensors or the SRF08 - High Performance Ultrasonic Range Finders, for example.

if so, then i think i will get started with a Diecimila and one sensor and begin my learning from there as it sounds like i have plenty way to go yet. smiley

any other hints and tips most welcome
15  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: question about distance sensors on: May 21, 2008, 09:38:15 am
hi again

thanks for the replies

that ping distance sensor looks possibly like the way to go for my needs.  2 cm to 3m is pretty much the distance i'm after

can i ask : what would i need to buy if i wanted to connect 8 or 10 to an arduino board?  which board would you recommend for this purpose? would they all fit into the one board or would i need some kind of adaptor?  

and then i guess i can link the board to a computer with max msp using usb?

again, many thanks
Pages: [1] 2