Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Programs >> multiple wiring boards with bluetooth
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1181373371

Message started by nooodles on 06/09/07 at 07:16:10

Title: multiple wiring boards with bluetooth
Post by nooodles on 06/09/07 at 07:16:10
hi,

i've got one unit (a wiring board with bluesmirf, 3 leds, and a range sensor) working with a audio stream program in processing. what i would like to do is set up 2 other units to work similarly - sending different values to processing to change audio streams. also, if the sensor value is a certain number on each of the boards, i would like one of LED on each of the units to turn on.

i've looked at the TWI (Two Wire Interface) library - however, i can't seem to figure out how to set up the adresses for the devices.

http://wiring.org.co/reference/libraries/Wire/index.html

the following is the wiring code i currently have:

//
int val=0;
int i=16;


void turn_all_off()            // function to turn off all the lights
{                              
 int i;
 for(i=16; i<24; i++)            //LEDS connected to digital pins 16 to 23
 {
   digitalWrite(i, HIGH);
 }
}


void setup() {
 Serial1.begin(9600);      // sets the serial port to 9600
 for (i=16; i<24; i++){
   pinMode(i, OUTPUT);
 }
}


void loop() {
 turn_all_off();            // turns all lights off
 val = analogRead(0);          // read it and store it in 'val'


 if((val<1000)){
   digitalWrite(16, LOW);   // sets the current light on
 }
 
  if((val>80)){
   digitalWrite(19, LOW);   // sets the current light on
   Serial1.print(val/2, BYTE);      // Send the value
 }


 if((val>250)){
   digitalWrite(19, LOW);   // sets the current light on
   Serial1.print(val/2, BYTE);      // Send the value
 }


 if((val>450)){
  digitalWrite(23, LOW);   // to set the all lights on in this position on each unit
  Serial1.print(val/2, BYTE);      // Send the value
 }
 

 delay(500);
}
//

thanks in advance.

Title: Re: multiple wiring boards with bluetooth
Post by barragan on 06/10/07 at 05:24:42
Hi, I don't understand your question very well, does the code you sent works for you? I guess yes it simply receives data on Serial1 serial port (Wiring pins 2 and 3)
But I am not sure about your question regarding Wire.
In any case here is an example of using a TWI ranger sensor (Wire library). It is possible to add several of these sensors using the same bus available on Wiring pins 0 and 1. In order for each sensor to have its own address it has to be manually configured for each of them. Check http://wiring.org.co/learning/examples/SFRRanger_reader.html
There is a function in comments changeAddress that changes the address as you wish for each sensor.
When using the library to connect multiple wiring boards together (another possibility)
one board has to be set as a master and the others as slaves and in that case you can assign the addresses yourself as in the examples Master reader, Master writer. Slave receiver, Slave sender.

Title: Re: multiple wiring boards with bluetooth
Post by nooodles on 06/13/07 at 02:14:04
thanks for the suggestions. for a range finder (the infrared - not the ultrasonic), how would the addresses be named? i would like 3 units (bluetooth, sensor, 7 LEDs on each board) to be able to receive and send data to each other when each of the range finders reach a certain numeric value. would this be possible?

i am having trouble trying to modify the code found in my initial post above. i would appreciate any suggestions. thanks in advance.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.