Sponsored Content
Top Forums Programming Basic Arduino UNO Bluetooth Testing with the BLE 4.0 (CC2541, MLT-BT04 IC) Post 303043352 by Neo on Sunday 26th of January 2020 12:30:23 AM
Old 01-26-2020
To test Arduino BLE on the iPhone (my trusty 6S), I installed and tried a number of Arduino BLE apps from the Apple store, including these five apps:
  • BLE 101
  • LightBlue
  • ArduinoBlue
  • Blynk
  • Adafruit Bluefruit

Of all these IOS apps, I found ArduinoBlue to be the best, by far:

Code:
https://sites.google.com/stonybrook.edu/arduinoble/#h.p_Wf5FtzfPYJ9i

For example, in their basic sketch, with PIN setup as follows (TX, RX pins reversed from the first sketch above, FYI - which I changed to match the ArdunioBlue defaults):

Basic Arduino UNO Bluetooth Testing with the BLE 4.0 (CC2541, MLT-BT04 IC)-hc-10jpg



Code:
/*
  ArduinoBlue example code to demonstrate the features of the app.
*/

#include <SoftwareSerial.h>
#include <ArduinoBlue.h>

const unsigned long BAUD_RATE = 9600;

// The bluetooth tx and rx pins must be supported by software serial.
// Visit https://www.arduino.cc/en/Reference/SoftwareSerial for unsupported pins.
// Bluetooth TX -> Arduino D8
const int BLUETOOTH_TX = 8;
// Bluetooth RX -> Arduino D7
const int BLUETOOTH_RX = 7;

int prevThrottle = 49;
int prevSteering = 49;
int throttle, steering, sliderVal, button, sliderId;

SoftwareSerial bluetooth(BLUETOOTH_TX, BLUETOOTH_RX);
ArduinoBlue phone(bluetooth); // pass reference of bluetooth object to ArduinoBlue constructor

// Setup code runs once after program starts.
void setup() {
  // Start serial communications.
  // The baud rate must be the same for both the serial and the bluetooth.
  Serial.begin(BAUD_RATE);
  bluetooth.begin(BAUD_RATE);
  delay(100);

  Serial.println("setup complete");
}

// Put your main code here, to run repeatedly:
void loop() {
  // ID of the button pressed pressed.
  button = phone.getButton();

  // Returns the text data sent from the phone.
  // After it returns the latest data, empty string "" is sent in subsequent.
  // calls until text data is sent again.
  String str = phone.getText();

  // Throttle and steering values go from 0 to 99.
  // When throttle and steering values are at 99/2 = 49, the joystick is at center.
  throttle = phone.getThrottle();
  steering = phone.getSteering();

  // ID of the slider moved.
  sliderId = phone.getSliderId();

  // Slider value goes from 0 to 200.
  sliderVal = phone.getSliderVal();

  // Display button data whenever its pressed.
  if (button != -1) {
    Serial.print("Button: ");
    Serial.println(button);
  }

  // Display slider data when slider moves
  if (sliderId != -1) {
    Serial.print("Slider ID: ");
    Serial.print(sliderId);
    Serial.print("\tValue: ");
    Serial.println(sliderVal);
  }

  // Display throttle and steering data if steering or throttle value is changed
  if (prevThrottle != throttle || prevSteering != steering) {
    Serial.print("Throttle: "); Serial.print(throttle); Serial.print("\tSteering: "); Serial.println(steering);
    prevThrottle = throttle;
    prevSteering = steering;
  }

  // If a text from the phone was sent print it to the serial monitor
  if (str != "") {
    Serial.println(str);
  }

  // Send string from serial command line to the phone. This will alert the user.
  if (Serial.available()) {
    Serial.write("send: ");
    String str = Serial.readString();
    phone.sendMessage(str); // phone.sendMessage(str) sends the text to the phone.
    Serial.print(str);
    Serial.write('\n');
  }
}

I set up two buttons and two sliders just like in the instructions, and everything worked "out of the box" (much better than all the other IOS BLE Arduino apps I tested). For example, here is the Arduino serial monitor output:

Code:
12:10:25.812 -> setup complete
12:10:27.597 -> setup complete
12:10:41.352 -> Button: 0
12:10:44.463 -> Button: 1
12:10:45.769 -> Button: 0
12:10:46.402 -> Button: 1
12:10:47.034 -> Button: 0
12:10:47.555 -> Button: 1
12:10:48.108 -> Button: 0
12:10:49.002 -> Button: 0
12:10:49.631 -> Button: 0
12:10:50.620 -> Button: 1
12:10:50.953 -> Button: 0
12:10:52.105 -> Button: 0
12:10:52.326 -> Button: 0
12:10:52.546 -> Button: 0
12:10:52.732 -> Button: 0
12:10:52.946 -> Button: 0
12:10:53.870 -> Slider ID: 0	Value: 104
12:10:53.870 -> Slider ID: 0	Value: 113
12:10:53.904 -> Slider ID: 0	Value: 121
12:10:53.941 -> Slider ID: 0	Value: 130
12:10:53.979 -> Slider ID: 0	Value: 147
12:10:53.979 -> Slider ID: 0	Value: 154
12:10:54.017 -> Slider ID: 0	Value: 163
12:10:54.054 -> Slider ID: 0	Value: 167
12:10:54.092 -> Slider ID: 0	Value: 170
12:10:54.092 -> Slider ID: 0	Value: 172
12:10:54.092 -> Slider ID: 0	Value: 174
12:10:54.130 -> Slider ID: 0	Value: 177
12:10:54.166 -> Slider ID: 0	Value: 179
12:10:54.204 -> Slider ID: 0	Value: 180
12:10:54.204 -> Slider ID: 0	Value: 181
12:10:54.278 -> Slider ID: 0	Value: 179
12:10:54.278 -> Slider ID: 0	Value: 176
12:10:54.315 -> Slider ID: 0	Value: 168
12:10:54.350 -> Slider ID: 0	Value: 156
12:10:54.384 -> Slider ID: 0	Value: 130
12:10:54.384 -> Slider ID: 0	Value: 121
12:10:54.421 -> Slider ID: 0	Value: 111
12:10:54.459 -> Slider ID: 0	Value: 101
12:10:54.495 -> Slider ID: 0	Value: 91
12:10:54.532 -> Slider ID: 0	Value: 82
12:10:54.532 -> Slider ID: 0	Value: 70
12:10:54.570 -> Slider ID: 0	Value: 61
12:10:54.607 -> Slider ID: 0	Value: 58
12:10:54.645 -> Slider ID: 0	Value: 54
12:10:54.645 -> Slider ID: 0	Value: 53
12:10:54.645 -> Slider ID: 0	Value: 52
12:10:54.682 -> Slider ID: 0	Value: 50
12:10:54.720 -> Slider ID: 0	Value: 49
12:10:54.720 -> Slider ID: 0	Value: 47
12:10:54.758 -> Slider ID: 0	Value: 46
12:10:54.795 -> Slider ID: 0	Value: 46
12:10:54.833 -> Slider ID: 0	Value: 45
12:10:54.833 -> Slider ID: 0	Value: 44
12:10:54.870 -> Slider ID: 0	Value: 44
12:10:55.014 -> Slider ID: 0	Value: 49
12:10:55.014 -> Slider ID: 0	Value: 64
12:10:55.052 -> Slider ID: 0	Value: 79
12:10:55.090 -> Slider ID: 0	Value: 94
12:10:55.128 -> Slider ID: 0	Value: 106
12:10:55.128 -> Slider ID: 0	Value: 111
12:10:55.165 -> Slider ID: 0	Value: 119
12:10:55.203 -> Slider ID: 0	Value: 123
12:10:55.241 -> Slider ID: 0	Value: 127
12:10:55.241 -> Slider ID: 0	Value: 130
12:10:55.279 -> Slider ID: 0	Value: 133
12:10:55.316 -> Slider ID: 0	Value: 135
12:10:55.353 -> Slider ID: 0	Value: 136
12:10:55.425 -> Slider ID: 0	Value: 128
12:10:55.425 -> Slider ID: 0	Value: 120
12:10:55.425 -> Slider ID: 0	Value: 112
12:10:55.464 -> Slider ID: 0	Value: 105
12:10:55.501 -> Slider ID: 0	Value: 91
12:10:55.501 -> Slider ID: 0	Value: 81
12:10:55.537 -> Slider ID: 0	Value: 78
12:10:55.575 -> Slider ID: 0	Value: 75

Here is the actual setup using a $2 - $3 Chinese Arduino sensor shield from my toy box:

Basic Arduino UNO Bluetooth Testing with the BLE 4.0 (CC2541, MLT-BT04 IC)-img_9041jpg


Side Note: I'm starting too like all these cheap Chinese shields from AliExpress Smilie

Basic Arduino UNO Bluetooth Testing with the BLE 4.0 (CC2541, MLT-BT04 IC)-img_9042jpg


This is the ArduinoBlue test setup on the iPhone:

Basic Arduino UNO Bluetooth Testing with the BLE 4.0 (CC2541, MLT-BT04 IC)-arduino_blue_testjpg


With the basics out of the way on the iPhone (for now), next I think I will look for / find / modify or write a Python app so I can play Arduino BLE from my desktop MacPro. Also, in that search, I'll also check to see what kinds of macOS apps are good for this caper (so far, I've not found any suitable BLE app for macOS, so my guess is I'll end up writing or modifying a Python project for BLE on the Mac).
This User Gave Thanks to Neo For This Post:
 

7 More Discussions You Might Find Interesting

1. OS X (Apple)

Semi-Automatic Arduino Detection.

I am working on a semi-auto detection idea for Arduino for the Scope project. It does require a little user intervention but minimal. It works by just responding to two on screen prompts to unplug and plug Arduino into a USB port. There are two versions and both work perfectly well and give... (3 Replies)
Discussion started by: wisecracker
3 Replies

2. Programming

Very Basic Arduino Uno Board Testing

A very simple Arduino board test... LOL Here is some very easy code to test a cheap Arduino board I just got from China via Aliexpress. I am still waiting on a about 30 more orders from Aliexpress for more Arduino stuff. This was the first order which made it here. /* Arduino test-code... (18 Replies)
Discussion started by: Neo
18 Replies

3. Programming

Arduino-cli - Uploading to Unknown Chinese Arduino Boards using the Arduino Command Line Interface

In my further exploration of Arduino, today I decided to install the arduino-cli on my mac today. https://github.com/arduino/arduino-cli I followed the instructions for macOS but when I got to this part: arduino-cli board list I got the dreaded "Unknown" Fully Qualified Board Name... (1 Reply)
Discussion started by: Neo
1 Replies

4. Programming

More Arduino Stuff...

HI all... (Apologies for any typos.) To add to Neo's Arduino subject matter I have decided to upload this in ".zip" format. Ignore "*.info" files these are AMIGA icons only and also the "HAM" drawer as these are photos in ancient AMIGA HAM modes. I have noticed that there are current... (6 Replies)
Discussion started by: wisecracker
6 Replies

5. Programming

Chinese Arduino UNO Clones - The Wavgat versus the generic UNO R3 Clone - The Winner Is?

Waiting for more fun Ardunio parts from AliExpress, I decided to test two cheap Chinese Arduino UNO clones. The Arduino UNO R3 (CH340G) MEGA328P The Wavgat UNO R3 (CH340G) MEGA328P Both of these Chinese Ardunio clones sell for about $3 USD, delivered to your door. The bottom line is... (0 Replies)
Discussion started by: Neo
0 Replies

6. Programming

Arduino UNIX Time - Syncing Computer UNIX Time to Arduino Time with Python

Just finished a quick Python script to send the current unix time over to the Arduino from macOS, so in the absence of GPS or some other way to get the unix timestamp (epoch time) to the Arduino, I can get my macOS and Arduino UNO synced to within a second. Normally, when the Arduino starts... (9 Replies)
Discussion started by: Neo
9 Replies

7. Programming

Arduino Project: iPhone to HM-10 BLE to NB-IoT Shield to NB-IoT Network to Internet to Linux Server

This post describes a "work in progress" project I started today. Here is the High Level Overview: Currently, this project sits on my desk as an Arduino UNO (on the bottom), an NB-IoT Shield (sandwiched in the middle), a Sensor Shield (on top) with a HM-10 BLE Module (in the little... (13 Replies)
Discussion started by: Neo
13 Replies
All times are GMT -4. The time now is 01:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy