Two Bluetooth Arduino Input - Possible?

edited June 2016 in Arduino

Hi there,

I'm looking to have a total of 32 force sensors values being sent via Bluetooth from two separate Arduino's to my processing sketch.

Is this possible? Can I have two Bluetooth connections receiving data simultaneously?

Thanks in advance, Charles

Answers

  • I never tried with two at once, but everything I read on the subject leads me to believe that new serial COM ports are opened as needed when new Bluetooth devices are paired to the computer (If not, people couldn't use their bluetooth mouse along with their bluetooth keyboard and speakers at the same time which would be stupid). It all depends whether your computer is recent enough/has the right drivers to connect to multiple Bluetooth devices at once. If your computer can connect to them, Processing can access the ports using the Serial library.

    import processing.serial.*;
    
    Serial mySerial1, mySerial2;
    int port1 = 5 //your port 1 here
      , port2 = 7;//your port 2 here
    void setup(){
      mySerial1 = new Serial(this, Serial.list()[port1], 9600);
      mySerial2 = new Serial(this, Serial.list()[port2], 9600);
    }
    void draw(){
      if(mySerial1.available() > 0){
        //Your code here
        
        
      }
      if(mySerial2.available() > 0){
        //Your code here
        
        
      }
    }
    

    or use serialEvent(Serial p){}

    Hope this helped!

  • Thanks for the input, according to Apple seven is the maximum number of Bluetooth connections. Hopefully on that side I won't have any problems :)

    The official Bluetooth specifications say seven is the maximum number of Bluetooth devices that can be connected to your Mac at once.

    If anyone has any tips in regards to optimising for speed then please share. Ideally, I'd like to receive 32 bytes every 40ms.

  • edited June 2016

    @GoToLoop I'm sending all the values as ASCII text ( Arduino - Serial.print() ). How can I work out how many bytes I need to set the buffer to?

  • edited June 2016 Answer ✓

    You can't! When you said "I'd like to receive 32 bytes every 40 ms." I've erroneously assumed you were sending out fixed number of bytes.

    ASCII text by nature is dynamically-sized. For example, a short value is always 2 bytes. But sending it as ASCII the actual number of bytes varies according to the number of characters instead.

    If you're sending out a group of values at once rather than just 1, follow the approach from this thread:
    https://forum.Processing.org/two/discussion/14988/drawing-of-graphs-from-i2c-imu#Item_3

    In short, send those values as if they were TSV (Tab-Separated Values).
    And receive them w/ splitTokens() inside serialEvent().

  • edited June 2016

    Hi everyone..i am new here and as per my experience with my projects new serial COM ports are opened as needed when new Bluetooth devices are paired to the computer. It all depends whether your computer is recent enough has the right drivers to connect to multiple Bluetooth devices at once.

    printed circuit board fabrication

  • edited June 2016

    @GoToLoop Once again, thank you very much! @ChicShaw Thanks!

Sign In or Register to comment.