Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MR-DONI · Aug 25, 2016 at 05:44 PM · bluetoothcontrollers

Send text via bluetooth

Please help me How to make android app to send texts via bluetooth ? This application will be used to control the arduino through hc06 module

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Seg_fault_ · Sep 01, 2016 at 08:36 AM

Hi,

I think the best way is to use the SerialPort Class from the .Net 2.0 framwork : https://msdn.microsoft.com/en-us/library/system.io.ports.serialport(v=vs.110).aspx

I use that for the communication between a Arduino like and a Unity app. It's a PC app but I guess it should work the same way in Android app.

You should need a code like that :

     using System.IO.Ports;
 
     public SerialPort sp;
     public string port = "COM5";                //communication port
     public int speed = 115200;                    //speed of the communication (baud)

     //open bluetooth communication 
     public void openConnection() 
     {
         if(sp == null)
         {
             sp = new SerialPort(port, speed, Parity.None, 8, StopBits.One);
         }
         if (sp != null) 
         {
             if (!sp.IsOpen)
             {
                 try
                 {
                     sp.Open();  // opens the connection
                     sp.ReadTimeout = 100;  // sets the timeout value before reporting error
                     Debug.Log("Port Open!";);
                 }catch(System.Exception e)
                 {
                     Debug.LogWarning(e.ToString());
                 }
             }
         }
     }
     //close connexion
    public void closeConnection() 
     {
         if(sp != null && sp.IsOpen)
         {
             try
             {
                 sp.Close();
             }
             catch(System.Exception e)
             {
                 Debug.LogWarning(e.ToString());
             }
         }
     }
     //Send commande to the controller
     public void sendCommand(string cmd)
     {
         try
         {
             sp.Write(cmd);
         }catch(System.Exception e)
         {    
             Debug.LogWarning(e.ToString());
         }
     }


Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fasmilano · Feb 05, 2020 at 10:32 AM 0
Share

Hi, I was wondering if this could work if I'm sending the 'text' to another android device or would I still need to change things in this code.

avatar image Seg_fault_ fasmilano · Feb 06, 2020 at 08:06 AM 0
Share

Well, I guess it should be the same for the sending side, but you need to add the reading function to the other android device. But I don’t know how you dot get the good port name on android… You can also look at this pluggin, it’s maybe easier (I didn’t test it so can say if it’s good or not) https://github.com/seiji/unity-bluetooth

avatar image fasmilano Seg_fault_ · Feb 06, 2020 at 12:58 PM 0
Share

I've read here that Android uses Linux CO$$anonymous$$ Ports so maybe it would work if I just replaced the port CO$$anonymous$$5 with its Linux equivalent? Also, can you give me a sample code/function that can read sent text via Bluetooth? Thank, in advance!!!

avatar image
0

Answer by Volstn1 · Jan 25, 2019 at 05:27 PM

Hi I am trying to use Unity on my PC to connect to an HC-05 module on an Arduino. Can I use my computer's built in bluetooth or should I set up a bluetooth dongle and connect that to a COM port? Thanks @Seg_fault_,Hi I am trying to use Unity on my PC to connect to an HC-05 module and an Arduino. Will I be able to use the computer's Bluetooth adapter or do I need to set up a Bluetooth dongle and attach that to the COM port? Thanks!@Seg_fault_

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Seg_fault_ · Jan 26, 2019 at 03:09 PM 0
Share

Hi Volstn1, You should be able to use the build in Bluetooth device of your computer. Normally it allows to do the same things that you could do with a Bluetooth dongle. You have to start your arduino in associating mode, then you should be able to see it on your computer (whatever you are using a dongle or the build in device), associate the Arduino Bluetooth device with your computer, it will create a CO$$anonymous$$ port. Then you can connect using this CO$$anonymous$$ Port in unity using the SerialPort Class.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity3D and Android Controller Support 1 Answer

How to get first person controller 2 Answers

Third Person Controller: Animates correctly, but can't move 5 Answers

How do I move the Camera using HTC VIVE trigger button 0 Answers

VR hands in floor when built,Oculus hands in wrong position when built 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges