Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
Here is my latest test sketch for the ArduinoBlue example app with the added message examples back to the iPhone.
Note that earlier I missed the method in the example sketch (see highlight in red below) to send a message back to the iPhone:
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");
phone.sendMessage("Arduino 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);
phone.sendMessage("Button: " + String(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');
}
}
ArduinoBlue is the "clear winner" of this round of BLE testing with the Arduino UNO and the iPhone.
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)
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)
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)
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)
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)
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)
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)