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):
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:
Side Note: I'm starting too like all these cheap Chinese shields from AliExpress
This is the ArduinoBlue test setup on the iPhone:
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).
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)
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)
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)
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)
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)
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)
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)