Android Bluetooth to Arduino and vice versa


Now grafica library run on APDE

1 Like

if or when you have time adapt this code for me work with bluetooth in order to make ways for handling data TX/RX via bt

// import require libraries
import grafica.*;
import processing.serial.*;

// create plot instance
GPlot plot;

// initialise global variables
int i = 0; // variable that changes for point calculation
int points = 450; // number of points to display at a time
int totalPoints = 500; // number of points on x axis
float noise = 0.1; // added noise
float period = 0.35;
long previousMillis = 0;
int duration = 20;

// Serial
Serial myPort; // Create object from Serial class

void setup(){
// set size of the window
size (900,450);

// set up serial connection
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 115200);

// initialise graph points object
GPointsArray points1 = new GPointsArray(points);

// calculate initial display points
for (i = 0; i < points; i++) {

// Create the plot
plot = new GPlot(this);
plot.setPos(25, 25); // set the position of to left corner of plot
plot.setDim(750, 300); // set plot size

// Set the plot limits (this will fix them)
plot.setXLim(0, totalPoints); // set x limits
plot.setYLim(0, 300); // set y limits

// Set the plot title and the axis labels
plot.setTitleText(“Distance Sensor Example”); // set plot title
plot.getXAxis().setAxisLabelText(“x axis”); // set x axis label
plot.getYAxis().setAxisLabelText(“Distance”); // set y axis label

// Add the two set of points to the plot


void draw() {
// set window background

// draw the plot

// check if i has exceeded the plot size
if (i > totalPoints){
i=0; // reset to zero if it has

// get new value from serial port
if ( millis() > previousMillis + duration) { // If data is available,
println(“Sensor request sent”);
while (myPort.available() < 0){};
int val =*256 +; // read it and store it in val
// Add the point at the end of the array

// Remove the first point

previousMillis = previousMillis + duration;



At the moment no, but you could make it a new topic since isn’t Android related.

my point handling data via bluetooth not the grafica libaray

I will look into this later on. In the meantime, I’ve written a better native code (without Ketai) to better handle receiving data. You can find it in the Gallery category here.

1 Like



Thank you for your interest, it seems to be a special work. I will study the code in detail and then apply it … and I will inform you of what is new

Bless you


what libraries need in APDE??

None. The imports are native libraries; no third-party lib required.

1 Like

i see

i understand thank you

Did you build the extra grafica.dex file needed to make it functional on APDE?

yes i did i think i run all the examples also

Could you explain what data you are going to use and at what speed,
I mean, more details, to make a simple example sketch.

It would be easier if you had something working on the PC to give the idea.

i did some on pc with arduino when i test it again i well post it

hi noel

this is nice if can run via bluetooth

import processing.serial.*;

 int adcValue = 0;        // value received from Serial 
 // String Unit="mA";
 // String Unit="kΩ";
 // String Unit="°C";     // We can use Unicode chars directly
String Unit="ANALOG READ";  
String Unit1="VALUE";   

// Unicode codes may be entered as well
 Serial myPort;
 PFont Segment, Units; 

 void setup() {
                          // Setup the display window 
  size(666, 280);         // Size of the window
  Segment = createFont("Segment7", 150);  // Assign fonts and size 
  Units = createFont("Arial", 40);
  textAlign(RIGHT);        // Text align 
  fill(250,250,0);         // Font color is yellow = red + green

 // println(Serial.list());    // List all the available serial ports
  // Then open the port  you're using, my is the first, i.e. '0'
myPort = new Serial(this,"COM3", 9600); 
 //  myPort = new Serial(this, Serial.list()[], 9600);
 // don't generate a serialEvent() unless you get a newline character:

void draw()
{                      // Let's start to display
  background(0,0,0);   // set the background color black

  text(adcValue, 311, 250);


void serialEvent(Serial myPort) 
 String inString = myPort.readStringUntil('\n');    // get the ASCII string:
 if (inString != null) 
     inString = trim(inString);     // trim off any whitespace
     adcValue = int(inString);      // convert into an integer
     adcValue =int(map(adcValue, 0, 1023, 0, 1023));  // possible range adjusting


#include <SoftwareSerial.h>

SoftwareSerial LEDdisplej(2, 3); //RX pin, TX pin

int adcValue = 0;

void setup() {


  LEDdisplej.begin(9600);  // Talk to the Serial7Segment at 9600 bps
  LEDdisplej.write('v');   // Reset the display - this forces the cursor to return to the beginning of the display

void loop() 
  adcValue = 0;                           // Filter - average from 16 values 
  for (int i = 1; i<=16; i++)
    adcValue = adcValue + analogRead(0);
  adcValue = adcValue/16;

  char tempString[10];                     // Used for sprintf
  sprintf(tempString, "%4d",adcValue);     // Convert into a string that is right adjusted
  //sprintf(tempString, "%d", adcValue);   // Convert into a string that is left adjusted (requires digit 1 command)
  //sprintf(tempString, "%04d", adcValue); // Convert into a string with leading zeros
  //sprintf(tempString, "%4X", adcValue);  // Convert int  HEX, right adjusted
  LEDdisplej.print(tempString);            // Send serial string out the soft serial port to the S7S
  Serial.println(tempString);           // Works too, but we don't need trailing spaces ' ' in the front
  // Serial.println(adcValue);


hi noel

The Arduino handles all the operations in my project … and which originally depends on the timing generated through the integrated circuit 4017 … I replaced the integrated with the Arduino automatic, the device became digital … because the resistors that change the timing in the integrated circuit 4017 were dispensed with Arduino

Meaning as follows

All digital operations that have been added to the device are a matter of controlling how to operate, such as replacing the variable resistors with buttons

The final outputs are a signals with a frequency not exceeding 5 kilohertz

this is the timing section of the device all replaced with arduino and works as the original device as can you see 6 variable resistors become sliders instead and working great

all this schematic include ics diodes transistors caps etc… replaced with arduino

here the 4017 timing out range from 2us to 350us the arduino now acts as 4017 exactly

the timing just for the internal use of the device

My problem is as follows

Firstly, since last month I only used the processing program, and before that, I never used it


I learned what I want and built the code in separate parts and stages according to each outcome of each stage


I did not know that the serial is completely different from the Android Bluetooth, especially the touch problem in the controlP5 library

I am trying overcome the touch problem of Android and ControlP5
I made good steps

hi noel

I posted a summary of what I am doing and did not mean to give you a headache :innocent: :innocent: :heart: :heart:

The help I want from you is that I can deal with the Bluetooth same as I can use the serial

I will study the code you posted . I applied the first sending code from Android to the Arduino it is working and sent to the serial monitor number 255