Giter Club home page Giter Club logo

duino's Introduction



Duino v0.0.4

Control an Arduino using your phone's Bluetooth. Duino is available on both iOS and android featuring buttons, d-pad, joystick, and tilt pad to control your Arduino. The possibilities of these features are limited by your imagination. Duino was created as a project using a cross platform development framework, Flutter. One of the main goals of this project was to create a simple and modern user interface. Enjoy!



     

Getting Started

Requirements

Similar configurations and devices may work. Please read your device's documentation before continuing. The setup used in this guide includes an iPhone XR, an Arduino Uno, and a HM-10 Bluetooth module from DSD Tech. For more information, please see Limitations.

Setup

Download the iOS or android app.

Wire your Arduino Uno and HM-10 bluetooth module. See the circuit diagram below.

Circuit Diagram

  • The RX and TX pins are used for serial communication. The Arduino Uno (device to the left) features several pins that can be used for serial communiation through the SoftwareSerial Library. Pins 0 and 1 on the Arduino have built-in support for serial communication; however, these ports can interfere with the native serial communication. As a result, pins 10 and 11 are used in the diagram above, where pin 10 acts as RX and pin 11 acts as TX.

  • The HM-10 Bluetooth module (device to the right) has a working voltage support of 3.3V to 6V, but the logic level is 3.3V. If the logic level of your board is 5V, it is recommended that you use a voltage divider. In the diagram above, a 3.3V power source is used to power the Bluetooth module.

Power your Arduino and a LED on the Bluetooth module should start to blink, indicating an unpaired state.

Open the Duino app and tap the 'Connect' button. Then tap 'Scan' in the connect screen. Tap on the Bluetooth device, 'DSD TECH' in this case, and then tap 'Yes' to connect. The LED on the Bluetooth module should stop blinking and maintain a solid glow, indicating your devices have successfully paired.

  • Make sure you agree to allow Duino to access the bluetooth permission. For android users, you may need to allow Duino to access the location permission in order to successfully complete scans. For more information on why this permission is required, please read the android documentation. For information on why iOS does not require the location permission, read this. Duino does not collect or transmit personal data.

Hello World

Let's create a program for the Arduino to read the raw data coming from Duino. Upload the following code to your Arduino. Make sure you use the correct RX and TX pins. This example program is following the circuit diagram above.

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
  while (!Serial);
  Serial.println("DUINO: <ARDUINO READY>");
}

void loop() {
  if (BTSerial.available()) {
    Serial.write(BTSerial.read());
  }
}

Use the different features of Duino to see how the program reacts in the serial monitor.

You should see a long line of characters, after DUINO: <ARDUINO READY>. I will explain the bounds for the data received for each feature under Features.

Here is a simple program to turn the Arduino built in LED on and off by pressing 1 and 0 on the keypad.

Features

I've included example parsers for each feature in the Duino folder here. The Duino.ino file contains all the parsers. Uncomment the parser you would like to use in the main loop.

Data received by Duino are ASCII characters delimited by a #.

Keypad

Keypad inputs from Duino are digit characters ranging from 0 to 9 inclusive.

Duino registers keypad releases as a valid input. Long presses or canceled presses will not be registered. See D-pad for long press inputs.

D-pad

D-pad inputs from Duino are alpha characters, either N S E or W.

Duino will emit one of the values while pressing a d-pad key, and then emit the delimiter on release.

Joystick

Joystick inputs from Duino are characters that can be visualized as degreedistance#. The degree is the joystick angle, and the distance is the distance from the center. Both degree and distance contain three-digit characters. For instance, you may get a stream of data like 000000#150255#355002#, which is interpreted as (0 degrees, 0 units), (150 degrees, 255 units), and (355 degrees, 2 units). Degrees range from 0 to 360 inclusive, while the units range from 0 to 255 inclusive.

Duino will emit a joystick value at least every 75ms if the joystick changes position. You could change this here.

Tilt Pad

Tilt pad inputs from Duino are characters that can be visualized as rollpitch#. The roll is the device rotation around the front-to-back axis in degrees, and the pitch is the device rotation around the side-to-side axis in degrees. Both roll and pitch contain four characters. These characters are digits and/or -. For instance, you may get a stream of data like -0010090#01500072#-117-012#, which is interpreted as (-1 degrees, 90 degrees), (150 degrees, 72 degrees), and (-117 degrees, -12 degrees). The roll ranges from -180 to 180 degrees inclusive, while the pitch ranges from -90 to 90 inclusive.

Duino will emit a tilt pad value at least every 75ms. You could change this here.

For more information on how to read and parse serial data, see this.

Limitations

Duino does not support tablets or large screen devices. You can change and compile the code for these devices, but for design reasons, I decided not to include these devices.

Android devices that do not support bluetooth low energy will not be able to download Duino.

The Bluetooth library used in the application only supports Bluetooth low energy devices. There are other Bluetooth libraries, ones that support Bluetooth classic, though Duino focuses on relatively modern devices and protocols.

Bluetooth LE devices have a list services and each service has a list of characteristics. There is a lot more going on and you can read more about it here. Duino only connects to Bluetooth devices with service UUID: FFE0 and characteristic UUID: FFE1, as specified by the HM-10 Bluetooth module from DSD Tech. Code here.

The Arduino Uno has a limited buffer size to temporarily store serial data. For the joystick and tilt pad, I have set it to emit data at least every 75ms. Even at 50ms, the Arduino is able to successfully capture all the incoming data. A program you write may take processing time that could overflow the buffer, and as a result you will miss data points. This is more of a concern for the joystick, as it does not continuously emit data. There are several ways this can be minimized or overcame. That's up to you. Currently, there is no way to adjust the delay in the app.

There may be a time (probably not if I did my job well) where the Bluetooth module may be in the connected state, but Duino says that no device is connected. Simply, restart the application and/or Duino, so that both devices disconnect and then pair again.

Development

Flutter is used as the framework to develop both the iOS and android app. Flutter version 1.17.0 was used at the time of development. If you decide to continue development and use a different version, you may need to migrate some files. You may also encounter some errors if flutter decides to download a third party version that has errors or is incompatible. A workaround would be to use the exact versions I used, so in pubspec.yaml, where the third party libraries are defined, you could write something like this provider: 4.0.5 instead of this provider: ^4.0.5, though this is not recommended.

App Architecture (Barebones)

  • lib/: Where all the action happens.
  • lib/components/: Contains reusable components or widgets used throughout the application.
  • lib/models/: Data models.
  • lib/providers/: Scoped state management solution using provider. Used throughout the app.
  • lib/views/: Code for each screen of the app.
  • lib/main.dart: Entry point.
  • lib/routes.dart: Navigation manager. Navigating between different screens.
  • lib/styles.dart: Where all the dynamic and consistent colors and styles are defined.

My main focus for this application was to create a simple and easy-to-use interface. Flutter, being a UI-first framework, made the development process significantly faster, where most of my efforts were focused on the design. I had prior experience using Flutter, so setting up the project as an expandable architecture was simple. My design process for the app went something like this:

  • Research Bluetooth devices, similar apps and ideas, connectivity interfaces
  • Sketch a mockup design with pencil and paper.
  • Attempt to build it.
  • Realizing the engineering effort may be a bit much - Sketch again
  • Attempt to build it.
  • Realizing...
  • Attempt to build it.
  • Realizing...
  • Attempt to build it.
  • Test, publish, and document. (There was a lot of testing, fixing, testing, fixing...)

The app was intended to act more like virtual hardware that an Arduino could use. That is why there isn't much feedback in the app when it comes to the emitted data from the application. For instance, when you use the tilt pad, there is no start or stop button and there is no way to see the data being sent on your mobile device. I was aiming for a plug and play interaction, where a user would focus their efforts on using the app as a tool and spend most of their time creating programs for the Arduino. Additionally, when it comes to similar applications, Duino aims to be as transparent as possible. Duino does not rely on third party software on the Arduino and Duino is open source. This gives users absolute control on how to interpret the data and make desired modifications.

Some complications I encountered was with the math to interpret the roll and pitch from the acceleration data of the accelerometer. I still don't quite understand what's going on, but the values were consistent as I rotated my device. You can see the equations here. I got them off of stackoverflow. Another difficulty was parsing the data for the Arduino. I was unfamiliar with C++ and their use of arrays. My parsers may have some naive approaches in parsing a stream of characters.

Contribute

Duino was developed as an academic project and I intend for this project to be more as an educational resource, learn by open sourcing. I am very open for feedback and contribution.

Adobe XD files and resources used to make the visual content are here.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

To learn more about the HM-10 Bluetooth module, see this.


App Store® and Apple® logo are registered trademarks of Apple Inc.

Google Play and the Google Play logo are trademarks of Google LLC.

duino's People

Contributors

davebaraka avatar

Stargazers

Biruk Mesfin avatar  avatar  avatar Mohamed Ali Ebaid avatar Agastya Pawate avatar  avatar Wiseman Lim avatar Jack Armitage avatar

Watchers

 avatar

duino's Issues

implementing read function

Hello,

i just want to implement read Bluetooth feature using your code. Can you please help me to figure out how to do it 😄

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.