Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by lindsay · Oct 23, 2011 at 09:33 PM · dataserial

Unity to Arduino

Is there a way to send data from Unity to Arduino and back?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by adellelin · Aug 16, 2014 at 03:04 PM

COM4 is for windows. For Mac - change " COM4" to the full serial port name for mac. Mine is "/dev/tty.usbmodem1421"

Comment
Add comment · 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
2

Answer by ellens · Jun 01, 2012 at 11:48 PM

If you are on a Mac you can use the following example will oscP5 to send and recieve data between Arduino and Unity: http://www.sundh.com/blog/2012/05/unity-processing-arduino/

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 Grey_Wolf9 · Aug 15, 2018 at 05:09 AM 0
Share

Hello, I cannot seem to find your arduino unity processing tutorial with the force sensor. I urgently need that tutorial

avatar image
1

Answer by LastTemplar · Oct 29, 2011 at 07:39 AM

Here is an example I've been working with. This is an example C# code for Unity:

 using UnityEngine;
 using System.Collections;
 using System.IO.Ports;
 using System.Threading;
 
 public class SerialPortTest : MonoBehaviour 
 {
     //Setup parameters to connect to Arduino
     public static SerialPort sp = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
     public static string strIn;        
     
     // Use this for initialization
     void Start () 
     {
     OpenConnection();
     }
 
     void Update()
     {
             //Read incoming data
         strIn = sp.ReadLine();
     print(strIn);

            //You can also send data like this
            //sp.Write("1");

 
     }
     
     //Function connecting to Arduino
     public void OpenConnection() 
     {
         if (sp != null) 
         {
             if (sp.IsOpen) 
             {
                 sp.Close();
                 message = "Closing port, because it was already open!";
             }
             else 
             {
                 sp.Open();  // opens the connection
                 sp.ReadTimeout = 50;  // sets the timeout value before reporting error
                 message = "Port Opened!";
             }
         }
         else 
         {
             if (sp.IsOpen)
             {
                 print("Port is already open");
             }
             else 
             {
                 print("Port == null");
             }
         }
     }
 
     void OnApplicationQuit() 
     {
         sp.Close();
     }
 }

This is an example code for the Arduino:

 void setup() 
 {
   Serial.begin(9600);
 }
 
 void loop() {
  int val = 2;
 
 //Sending value
  Serial.write(val);
  delay(1000);
 
 //Receiving value
  if (Serial.available() > 0) {
         // read the incoming byte:
         incomingByte = Serial.read();
 
         // say what you got:
         Serial.print("I received: ");
                 Serial.println(incomingByte, DEC);
 
 }


Hope this helps ;)

Comment
Add comment · Show 5 · 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 lindsay · Nov 04, 2011 at 07:32 PM 0
Share

Hey this didn't really work out. I got an error trying to run the script: " Assets/NewBehaviourScript.cs(3,17): error CS0234: The type or namespace name Ports' does not exist in the namespace System.IO'. Are you missing an assembly reference?"

I am using Unity 3 on $$anonymous$$ac OS 10.7.

avatar image DaveA · Nov 04, 2011 at 07:33 PM 0
Share

You should use 'comment' rather than 'answer' unless you found an answer

avatar image LastTemplar · Nov 04, 2011 at 10:17 PM 1
Share

In Unity go to File -> Build Settings -> Player Settings, you will see new options will open in the right side of the screen, there, for the API Comp. Level choose .NET 2.0 (at the moment I think its something like >NET 2.0 subset)

avatar image ikriz · Dec 04, 2011 at 02:04 PM 0
Share

System.IO.Ports cannot be used on $$anonymous$$ac's currently therefore this won't work on a $$anonymous$$ac has something to do with Serial Ports and the $$anonymous$$ono version implemented in Unity

avatar image haukesand · May 01, 2015 at 01:47 PM 0
Share

Change as said to NET 2.0 but what is the "message" supposed to be? "The name `message' does not exist in the current context"

avatar image
0

Answer by HandHGraphics · Jul 18, 2013 at 06:57 AM

The Kinect2Arduino Package does just that; it can send serial messages to and from the Arduino and Unity. It's available in the asset store here: https://www.assetstore.unity3d.com/#/content/9680

Comment
Add comment · 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

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

9 People are following this question.

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

Related Questions

Write Data From List To CSV File 0 Answers

Serializing Dictionary with Vector3 keys 1 Answer

How to receive data from serial port via USB in Unity (able to send but not receive) 0 Answers

How can i get cpu id or motherboard id? 1 Answer

Audio Analysis? 1 Answer


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