Skip to content

ArduSensor Plugin is a Unity plugin that receives sensor values from an Arduino board via serial communication with Android.

License

Notifications You must be signed in to change notification settings

zzanyoung/Unity-ArduSensorPlugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Youtube_Thumb_1750

https://www.youtube.com/watch?app=desktop&v=AEGZW-BuSjw&ab_channel=ChanyoungKim

Unity-ArduSensorPlugin

ArduSensor Plugin is a Unity plugin that receives sensor values from an Arduino board(Uno) communicating with Android via serial communication. The plugin is implemented using Android native code, and the call takes place in Unity. The supported sensors include BME680(BME688) and SGP30, which detect temperature, humidity, pressure, gas resistance, altitude, CO2, and TVOC. The sensor values are updated every 4 seconds.

01

How to use

To open a completed project, select the Unity directory in the Unity hub. If you want to modify the code related to the Arduino sensor, edit the ino file in the Arduino directory. If you want to modify the android native method, edit the java file in the Android directory. Note that the Android project is built as a library.

When you open a Unity project, you should get the plugin package and build the demo scene to ensure that the AAR plugin is properly imported. If not, refer to Unity's official documentation* to properly import the plugin. All implementations are written in the AarBridge.cs file. Create a Java instance to communicate with Arduino through the default method of Android.

Hardware Configuration

Ardu

Technical Details

  • The code for implementing USB serial communication in Android is included in the aar plugin.
  • The aar plugin contains library and Android Activity for USB serial connection.
  • It opens the port and retrieves the vendor ID and device ID of the sensor connected to the Arduino.
  • It receives sensor data measured from the device.
  • It implements a method for transmitting the measured sensor data to Unity. In Unity, the measured values from the Arduino sensor are displayed.
  • Corresponding C# scripts are implemented for the methods in the aar plugin. Android Java Object and Android Java Instance have been used.
  • The implementation of the UI connected to this C# script is also included. It can be customized by assigning to button events.

Reference Project

@mik3y https://github.com/mik3y/usb-serial-for-android

If you'd like to learn more about the serial connection library or are interested in related discussions, please refer to the repository below.

MIT License

MIT License

Copyright (c) 2011-2013 Google Inc.

Copyright (c) 2013 Mike Wakerly

Copyright (c) 2023 Chanyoung Kim

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

ArduSensor Plugin is a Unity plugin that receives sensor values from an Arduino board via serial communication with Android.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published