background preloader

Programming

Facebook Twitter

GitHub - googlesamples/android-BluetoothChat. Bluetooth/Client_Fragment.java at master · JimSeker/bluetooth. Wirsing SendingAndReceivingDataViaBluetoothWithAnAndroidDevice. Android Send/Receive data with Arduino using Bluetooth – Part 2 – Harry's Developer Blog. Package com.example.arduinosensors; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { Button btnOn, btnOff; TextView txtArduino, txtString, txtStringLength, sensorView0, sensorView1, sensorView2, sensorView3; Handler bluetoothIn; final int handlerState = 0; private BluetoothAdapter btAdapter = null; private BluetoothSocket btSocket = null; private StringBuilder recDataString = new StringBuilder(); private ConnectedThread mConnectedThread; private static String address; @Override super.onCreate(savedInstanceState); try {

All about opengl es 2x. OpenGL ES. Android includes support for high performance 2D and 3D graphics with the Open Graphics Library (OpenGL®), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware. OpenGL ES is a flavor of the OpenGL specification intended for embedded devices. Android supports several versions of the OpenGL ES API: OpenGL ES 1.0 and 1.1 - This API specification is supported by Android 1.0 and higher. OpenGL ES 2.0 - This API specification is supported by Android 2.2 (API level 8) and higher. Caution: Support of the OpenGL ES 3.0 API on a device requires an implementation of this graphics pipeline provided by the device manufacturer.

Note: The specific API provided by the Android framework is similar to the J2ME JSR239 OpenGL ES API, but is not identical. The Basics Android supports OpenGL both through its framework API and the Native Development Kit (NDK). GLSurfaceView GLSurfaceView.Renderer Figure 1. Android Lesson One: Getting Started | Learn OpenGL ES. This is the first tutorial on using OpenGL ES 2 on Android. In this lesson, we’re going to go over the code step-by-step, and look at how to create an OpenGL ES 2 context and draw to the screen.

We’ll also take a look at what shaders are and how they work, as well as how matrices are used to transform the scene into the image you see on the screen. Finally, we’ll look at what you need to add to the manifest to let the Android market know that you’re using OpenGL ES 2. Prerequisites Before we begin, you’ll want to make sure you have the following tools installed on your machine: Unfortunately, the Android emulator does not support OpenGL ES 2, so you’ll need access to an actual Android device in order to run the tutorial. Assumptions The reader should be familiar with Android and Java on a basic level. Getting started We’ll go over all of the code below and explain what each part does. Let’s take a look at the code: Visualizing a 3D world public void onDrawFrame(GL10 glUnused) Recap Whew!

Displaying Graphics with OpenGL ES. Dependencies and prerequisites Android 2.2 (API Level 8) or higher Experience building an Android app You should also read OpenGL Try it out The Android framework provides plenty of standard tools for creating attractive, functional graphical user interfaces. This class walks you through the basics of developing applications that use OpenGL, including setup, drawing objects, moving drawn elements and responding to touch input. The example code in this class uses the OpenGL ES 2.0 APIs, which is the recommended API version to use with current Android devices. Note: Be careful not to mix OpenGL ES 1.x API calls with OpenGL ES 2.0 methods! Lessons Building an OpenGL ES Environment Learn how to set up an Android application to be able to draw OpenGL graphics. Defining Shapes Learn how to define shapes and why you need to know about faces and winding.

Drawing Shapes Learn how to draw OpenGL shapes in your application. Applying Projection and Camera Views Adding Motion Responding to Touch Events. Design. Android Custom 2D Graphics & Games Programming. 1. Custom 2D Graphics Android support 2D graphics via its own library in packages android.graphics.drawable and android.view.animation. Take note that Android does not support JDK's AWT and Swing. [TODO] more 2. Let us illustrate custom 2D graphics with the classical bouncing ball. 2.1 Example 1a: Simple Bouncing Ball Create a project called "BouncingBall", with application name of "Bouncing Ball" and package "com.example.bouncingball". MainActivity.java package com.example.bouncingball; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.View; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View bouncingBallView = new BouncingBallView(this); setContentView(bouncingBallView); bouncingBallView.setBackgroundColor(Color.BLACK); } } Dissecting MainActivity.java BouncingBallView.java Create a new Java class for BouncingBallView.java: Modified as follows:

How to Draw a 2D Object in Android With a Canvas. There are two basic ways of drawing 2D objects in Android. Drawing to a View, as described in the last tutorial, is the best option only when your object is static. If your object is moving, or you otherwise regularly need to redraw, you're better off with a Canvas. Read on for more on drawing with a Canvas, and using a secondary thread to do so, for best user responsiveness. Drawing with a Canvas For a slowly-animating application, you can use a custom View as in the previous tutorial. If your object is moving, or you otherwise regularly need to redraw, you're better off with a Canvas. The other way to get a Canvas is by managing a SurfaceView in a separate thread. First create a new class which extends SurfaceView and implements SurfaceHolder.Callback: We set up the SurfaceView and get a SurfaceHolder, then add a SurfaceHolder.Callback.

SurfaceCreated() will be called when the surface is first created. To call this from the main Activity is easy: Two Threads Important note! Untitled. Android Canvas Example | Examples Java Code Geeks - 2016. Android provides a set of APIs for 2D-drawing that allow you to render your custom graphics on a canvas or modify the existing Views.

When drawing 2D graphics, you have two choices to work with: Draw your graphics or animations into a View object from your layout. In this way, the drawing of your graphics is handled by the system’s normal View hierarchy drawing process and you simply define the graphics to go inside the View.Draw your graphics directly to a Canvas. This way, you personally call the appropriate class’s onDraw() method (passing it Canvas), or one of the Canvas draw…() methods. In doing so, you are also in control of any animation. When we have an activity that uses 2d graphics, such a video game application, drawing to a Canvas, is the best way to work with, as our application will meet the need to regularly re-draw itself.

For our example will use the following tools in a Windows 64-bit or an OS X platform: JDK 1.7Eclipse 4.2 JunoAndroid SDK 4.4.2 Let’s take a closer look: Classroom. Custom Drawing. The most important part of a custom view is its appearance. Custom drawing can be easy or complex according to your application's needs. This lesson covers some of the most common operations. Override onDraw() Before you can call any drawing methods, though, it's necessary to create a Paint object. The next section discusses Paint in more detail. Create Drawing Objects The android.graphics framework divides drawing into two areas: What to draw, handled by CanvasHow to draw, handled by Paint. For instance, Canvas provides a method to draw a line, while Paint provides methods to define that line's color. So, before you draw anything, you need to create one or more Paint objects.

Private void init() { mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setColor(mTextColor); if (mTextHeight == 0) { mTextHeight = mTextPaint.getTextSize(); } else { mTextPaint.setTextSize(mTextHeight); } Handle Layout Events In order to properly draw your custom view, you need to know what size it is. Draw! Canvas. Class Overview The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing). Developer Guides For more information about how to use Canvas, read the Canvas and Drawables developer guide. Summary Constants public static final int ALL_SAVE_FLAG Restore everything when restore() is called (standard save flags).

Note: for performance reasons, it is strongly recommended to pass this - the complete set of flags - to any call to saveLayer() and saveLayerAlpha() variants. Constant Value: 31 (0x0000001f) public static final int CLIP_SAVE_FLAG Restore the current clip when restore() is called. Constant Value: 2 (0x00000002) public static final int CLIP_TO_LAYER_SAVE_FLAG Clip drawing to the bounds of the offscreen layer, omit at your own peril. Constant Value: 16 (0x00000010) Canvas. Bluetooth. The Android platform includes support for the Bluetooth network stack, which allows a device to wirelessly exchange data with other Bluetooth devices. The application framework provides access to the Bluetooth functionality through the Android Bluetooth APIs.

These APIs let applications wirelessly connect to other Bluetooth devices, enabling point-to-point and multipoint wireless features. Using the Bluetooth APIs, an Android application can perform the following: Scan for other Bluetooth devices Query the local Bluetooth adapter for paired Bluetooth devices Establish RFCOMM channels Connect to other devices through service discovery Transfer data to and from other devices Manage multiple connections This document describes how to use Classic Bluetooth.

Classic Bluetooth is the right choice for more battery-intensive operations such as streaming and communicating between Android devices. The Basics All of the Bluetooth APIs are available in the android.bluetooth package. BluetoothAdapter. Android Bluetooth Connection Demo. Objective Main objective of this post is to give you an idea about Bluetooth connection demo in Android Bluetooth:The Android platform supports Bluetooth connection, which allows exchanging data with other Bluetooth devices.

The application framework provides access to the Bluetooth functionality through the Android Bluetooth APIs connect to other Bluetooth devices. All of the Bluetooth APIs is available in the Android Bluetooth package. Here is a summary of the classes you will need to create as below. BluetoothAdapter: Represents the local Bluetooth adapter (Bluetooth radio). In our example we are going to create an application which get the information about the Bluetooth connections is activates and deactivates Bluetooth. You will get Final Output: Step 1 Check Bluetooth Connection First we need check Bluetooth connection.

Step 2 MainActivity.java file Now when we got the response from the Connections class in our Main Activity with BT in Off state we get dialog for On BT. Tejas Jasani. Create a Bluetooth Scanner With Android's Bluetooth API - Envato Tuts+ Code Tutorial. How to Develop Simple Bluetooth Android Application To Control A Robot Remote – Into Robotics. The wireless-networking standard technology called Bluetooth has quietly become a common way to replace the wires on short distances. With a gadget such as a smartphone or a tablet featured with a Bluetooth module, a wireless connection is the easiest way to send and receive information. And because this technology spread in the prototyping culture, it’s often used to control things wirelessly.

In this article, we explore a series of materials and resources so you can learn how to develop an Android application and control a robot wirelessly over the Bluetooth technology at the flick of a wrist. With an open architecture and a large community, Android allows anyone to build applications with simple tools and resources. In other words, anyone can build an application for a smartphone or a tablet with Android tools, and control a robot with simple movements of the device or at a touch of the screen.

Android Bluetooth Applications (image source) The Bluetooth Technology. PortManipulation. Reference Language | Libraries | Comparison | Changes Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Arduino board. The chips used on the Arduino board (the ATmega8 and ATmega168) have three ports: B (digital pin 8 to 13) C (analog input pins) D (digital pins 0 to 7) Each port is controlled by three registers, which are also defined variables in the arduino language. The DDR register, determines whether the pin is an INPUT or OUTPUT.

The PORT register controls whether the pin is HIGH or LOW, and the PIN register reads the state of INPUT pins set to input with pinMode(). DDR and PORT registers may be both written to, and read. PORTD maps to Arduino digital pins 0 to 7 DDRD - The Port D Data Direction Register - read/write PORTD - The Port D Data Register - read/write PIND - The Port D Input Pins Register - read only PORTB maps to Arduino digital pins 8 to 13 The two high bits (6 & 7) map to the crystal pins and are not usable Examples.

SPI Arduino Library, connecting SPI devices to Teensy. The SPI library allows you to communicate with one or more SPI (Serial Peripheral Interface) devices. Download: SPI is included with Arduino. Often SPI is used by other libraries (like Ethernet) which provide easy access to a specific SPI device. A faster SPI library for Teensy 3.0 is available. This page documents a newer SPI library, released in Arduino 1.0.6 and Teensyduino 1.20, with beginTransaction() and endTransaction(). These new transaction functions prevent SPI bus conflicts, so their use it recommended for all new projects. Hardware Requirements SPI has 4 signals: SS, SCK, MOSI, MISO. Multiple SPI devices use the same SPI SCK, MISO and MOSI signals but each device will need it's own SS pin.

Arduino automatically defines "SS", "SCK", "MOSI", and "MISO" as the pin numbers for the selected board. Basic Usage SPI.begin() Call this function first, to initialize the SPI hardware. SPI.usingInterrupt(interrupt) SPI.beginTransaction(SPISettings(clockspeed, MSBFIRST, SPI_MODE0)) Example Program.