Hi fellow app inventors
I'm new to the world of BLE and app's so first off all thank you MIT for making this possible and creating an amazing online tool.
I'm having the following issues i'm kind of stuck with to continue my project. I'm building a machine which can shoot tennis balls using 4 motors controlled over PWM.
2 motors that determine the speed and spin of the ball and a linear actuator to determine the height it needs to shoot the ball. Later there will also be a feeding system which supplies balls at variable speeds.
This is the first part, I drew and build it completely myself and had the aluminium CNC cut. I also changed the inlet on this picture later because I was having some trouble letting the balls go through fluently.
This is the actuator I'll be using, most of the parts are salvaged, this one is from and old hairdressers chair.
This is my arduino code:
#include <ArduinoBLE.h>
//declare I/O pins (these are not correct anymore and need to be changed)
const int led = LED_BUILTIN;
const int upper_motor_pwm = 16; //pwm output speed of upper motor
const int upper_motor_dir = 17; //digital output direction of upper motor
const int upper_motor_pot = A1; //analog value input to control upper motor speed
const int lower_motor_pwm = 18; //pwm output speed of lower motor
const int lower_motor_dir = 19; //digital output direction of lower motor
const int lower_motor_pot = A2; //analog value input to control lower motor speed
const int feed_motor_pwm = 20; //pwm output speed of feed motor
const int feed_motor_dir = 23; //digital output direction of feed motor
const int feed_motor_pot = A0; //analog value intput to control feed motor speed
const int angle_motor_pwm = 22; //pwm output speed of actuator motor
const int angle_motor_dir = 21; //digital output direction of actuator motor
const int angle_motor_up = 0; //button input actuator extend
const int angle_motor_down = 1; //button input actuator retract
const int angle_motor_speed = 5; //button input half speed of the actuator
//variables to store speed in
byte var_upper_motor;
BLEService volley_vendor_service("68743AD1-BABE-4EBE-BD6B-E7AFA8BAD20F"); //create service
BLEByteCharacteristic upper_motor_speed_characteristic("931D4446-F7BC-49B1-BB95-328F6936FE33", BLEWrite | BLERead | BLENotify);
BLEByteCharacteristic upper_motor_speed_status("23028CF2-6C30-4378-AA77-476BE3649250", BLEWrite | BLERead | BLENotify);
void setup() {
pinMode(upper_motor_pwm, OUTPUT);
pinMode(upper_motor_dir, OUTPUT);
pinMode(upper_motor_pot, INPUT);
pinMode(lower_motor_pwm, OUTPUT);
pinMode(lower_motor_dir, OUTPUT);
pinMode(lower_motor_pot, INPUT);
pinMode(feed_motor_pwm, OUTPUT);
pinMode(feed_motor_dir, OUTPUT);
pinMode(feed_motor_pot, INPUT);
pinMode(angle_motor_pwm, OUTPUT);
pinMode(angle_motor_dir, OUTPUT);
pinMode(angle_motor_up, INPUT);
pinMode(angle_motor_down, INPUT);
pinMode(angle_motor_speed, INPUT);
pinMode(led, OUTPUT);
// begin initialization
if (!BLE.begin()) {
Serial.println("BLE Module boot fail...");
while (1)
;
}
// set the local name peripheral advertises
BLE.setLocalName("Volley Vendor Machine");
// set the UUID for the service this peripheral advertises:
BLE.setAdvertisedService(volley_vendor_service);
// add the characteristics to the service
volley_vendor_service.addCharacteristic(upper_motor_speed_characteristic); //slider
volley_vendor_service.addCharacteristic(upper_motor_speed_status); //feedback return value
// add the service
BLE.addService(volley_vendor_service);
//set everything to zero to start
upper_motor_speed_characteristic.writeValue(0);
// start advertising
BLE.advertise();
// Initialize Serial communication
Serial.begin(9600);
Serial.println("Volley Vendor Machine started");
Serial.println("Connect phone using the app");
}
void loop() {
BLEDevice central = BLE.central();
if (central) {
digitalWrite(led, HIGH);
}
while (central.connected()) {
upper_motor_speed_characteristic.readValue(var_upper_motor);
if (var_upper_motor > 100) {
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
Serial.println(var_upper_motor);
}
Serial.println(var_upper_motor);
upper_motor_speed_status.writeValue(var_upper_motor);
delay(50);
}
digitalWrite(led, LOW);
}
So to get to my problem:
I've been trying to get the BLE set up but only for one motor at first and I want to control it using a slider right now. If I manually set a random value in my code from my arduino to my phone, I can receive it and see it in my label. (both in the variable and the .writeValue) so this works.
So I guess the problem lies within sending the value from the slider towards my arduino.
This is the MITAI block code i'm using now:
So to continue this problem further, the app won't fully start anymore.
I can get to the start scanning screen, see the list of devices and select my arduino, when connected the builtin led comes on like programmed in the code, but then completely crashes and the led goes out.
I'm using an arduino R4 wifi/bluetooth if it is any help.
Thank you in advance