/ Arduino

How to stream data from Arduino to Android with the JDY-08.

What is it?

This is a description of how to set up the JDY-08 to stream data from Arduino to Android.

Why is it cool?

The JDY-08 is a tiny Bluetooth module that is really cheap and comes with everything on board. It is a easy and quick addition to existing Arduino projects to give them a little wireless magic. It is better than the HM-11 boards because it uses BLE, which has lower energy consumption, takes up less space, and is still able to stream data transparently.

Introduction

In this post I will describe how to use the JDY-08 module to work in Serial transparent mode with Arduino and Android. This means that you can stream data from the MCU directly into your Android phone. This post continues on from my JDY-08 breakout board post.

Arduino

Getting this device to work was not an easy feat. But I finally did it, and it is documented here for your convenience. The firmware is default. Excellent references are the JDY-08 datasheet. It is very important that you only use 3.3V to power the device otherwise it will not work or might even be damaged. Because it is powered by 3.3V, a standard Arduino powered by 5V will not work. I am using a Arduino Pro Mini that is clocked to 3.3V and 8Mhz.

Firstly, because the baud rate is too high for SoftwareSerial to work reliably, we have to lower the default 115200 baud rate to 9600. The only way is to use RX0 and TX1 on the Arduino, which also happens to be the programming port of the Arduino. But no worries! We only have to do this once. While doing AT commands, be sure to ground the P00 line and turn off any Bluetooth connections, as recommended in the datasheet.


#include <SoftwareSerial.h>

// Swap RX/TX connections on bluetooth chip
//   Pin 10 --> Bluetooth TX
//   Pin 11 --> Bluetooth RX
SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Init complete!");
  mySerial.begin(115200);
  Serial.write("AT+BOUD4");
   
  mySerial.write("AT+BOUD4");
  delay(1000);
  while (mySerial.available()) {
      Serial.write(mySerial.read());
   }
}
void loop() {}

Once this code is uploaded we can use the baud rate 9600 and we can switch the TX and RX lines to pins 2 and 3 on the Arduino, which we will use SoftwareSerial to communicate with the Bluetooth board.

Now since we just want the Bluetooth module to transparently transmit data to an Android device, so we will use the APP mode of the device. Here the following Arduino code uses sprintf to create a string with a variable that updates every one second. Note that you have to remove P00 once all AT commands have been completed.

#include <SoftwareSerial.h>

// Swap RX/TX connections on bluetooth chip
//   Pin 2 --> Bluetooth TX (P03)
//   Pin 3 --> Bluetooth RX (P02)
SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Init complete!");
  mySerial.begin(9600);

  Serial.write("AT+BOUD4");
   
  mySerial.write("AT+BOUD4");
  delay(1000);
  while (mySerial.available()) {
      Serial.write(mySerial.read());
   }
     Serial.write("AT+HOSTEN0");
  mySerial.write("AT+HOSTEN0");
  delay(1000);
  while (mySerial.available()) {
      Serial.write(mySerial.read());
   }
  Serial.write("AT+GETSTAT");
  mySerial.write("AT+GETSTAT");
  delay(1000);
  while (mySerial.available()) {
      Serial.write(mySerial.read());
   }

  Serial.println("Complete!");
  delay(10000); // delay, pull out or otherwise disconnect P00 from ground
}

int i = 0;
char mybuffer[50];
void loop() {

  sprintf(mybuffer,"This number is: %d",i);
  mySerial.write(mybuffer);
  Serial.println(mybuffer);
  i++;
  delay(1000);
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

Android

On your Android phone, download the excellent nRF Connect for Mobile by Nordic Semiconductor and scan for a device named JDY-08. Once connected, open the first unknown service and the first unknown characteristic. Under value, you should see a string saying The number is: xxx, and it updates over time.

Now you can stream data from Arduino to your phone. With a little Android magic, you can then set values and even plot the live data on your phone from your Arduino.

Conclusion

Getting here has taken quite a bit of time and I documented as much of the process as possible. This would not have been possible without those who found the datasheet and translated it into English. The next steps are to create an app that reads this value and processes it into something useful.