Connecting to a Dsd tech hm-19 module

Newbie question...I've got a Dsd tech hm-19 bluetooth 5.0 module all connected up. I can send and recieve via the dsd tech app. Can someone point me in the right direction to connect it via the mit app inventor app I put together already? Android phone only sees the module thru dsd tech app.

Start here: http://iot.appinventor.mit.edu/
You will have to figure out what the Characteristics, UUID's etc. are. I took a short look at their website, but it is mainly Chinese to me.
The big question is, what are you going to use this Dsd tech hm-19 for? And what should the App Inventor app do?

You must use the Bluetooth BLE extension as the built-in components do not support ble.

1 Like

Its really only going to be used to turn on and off 2 different motors. I have it connected thru arduino.

The ble extension looks like it will do the trick. Now I just need to figure out how to use it. The blocks are very different from the regular bluetooth.

Ok, now that I have it connecting to the module...which blocks are needed to send a characters to the module.
A = Turn motor one on
B = Turn motor one off
C = Turn motor two on
D = Turn motor two off

Only you have the module so this generic advice might help https://community.appinventor.mit.edu/search?q=ble

If you still need help, share some code and someone might be able to provide specific advice.

Here is what I have so far...


Here is the Arduino code...
/*
Connections are like this

  • **TB6600
    Stepper Motor 1
    DIR+ -> Pin 2
    PUL+ -> Pin 3
    PUL- and DIR- -> GND

    Stepper Motor 2
    DIR+ -> Pin 4
    PUL+ -> Pin 5
    PUL- and DIR- -> GND

    Stepper Motor 3
    DIR+ -> Pin 6
    PUL+ -> Pin 7
    PUL- and DIR- -> GND

Stepper Motor 4
DIR+ -> Pin 8
PUL+ -> Pin 9
PUL- and DIR- -> GND

Stepper Motor 5
DIR+ -> Pin 10
PUL+ -> Pin 11
PUL- and DIR- -> GND

Relay1(Sig Pin) -> 12
Relay2(Sig Pin) -> 13
LED -> 15

  • **Bluetooth
    TX -> 51
    RX -> 50 //With a Pull up resistor configuration as soon in circuit diagram

*/

#include <SoftwareSerial.h>

//================================================Stepper Motor Pin Definitions
//#define motorInterfaceType 1 //For motor drivers it is 1
#define Step 50 //As its a 200 Step motor. In case the angle is not proper tweak this value
#define dirPin_1 2
#define stepPin_1 3

#define dirPin_2 4
#define stepPin_2 5

#define dirPin_3 6
#define stepPin_3 7

#define dirPin_4 8
#define stepPin_4 9

#define dirPin_5 10
#define stepPin_5 11
//================================================================================

#define Relay_1 12
#define Relay_2 13

#define LED 15

#define RX 51
#define TX 50

#define ButtonPin_1 18 //Interupt Pins
#define ButtonPin_2 19
#define ButtonPin_1_Red 20
#define ButtonPin_1_GREEN 21

#define ButtonPin_2_Red 22
#define ButtonPin_2_GREEN 23

volatile byte state_1 = LOW;
volatile byte state_2 = LOW;
int BLE_state = 0;
int flag = 0;
uint32_t seconds = 1; //Measuring time
int i = 0;
boolean toggle0 =0;
unsigned int temp =0;
int speed_1 =0;
//================================================================================

SoftwareSerial Config_Bluetooth(RX, TX); // RX, TX

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

cli();//stop interrupts
TCCR0A = 0; // set entire TCCR0A register to 0
TCCR0B = 0; // same for TCCR0B
TCNT0 = 0; // initialize counter value to 0
// set compare match register for 1000 Hz increments
OCR0A = 249; // = 16000000 / (64 * 1000) - 1 (must be <256)
// turn on CTC mode
TCCR0B |= (1 << WGM01);
// Set CS02, CS01 and CS00 bits for 64 prescaler
TCCR0B |= (0 << CS02) | (1 << CS01) | (1 << CS00);
// enable timer compare interrupt
TIMSK0 |= (1 << OCIE0A);
//-----------------------------------------------------------------------
// TIMER 1 for interrupt frequency 100 Hz:
cli(); // stop interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // initialize counter value to 0
// set compare match register for 100 Hz increments
OCR1A = 19999; // = 16000000 / (8 * 100) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12, CS11 and CS10 bits for 8 prescaler
TCCR1B |= (0 << CS12) | (1 << CS11) | (0 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei(); // allow interrupts
//-----------------------------------------------------------------------
sei();//allow interrupts

Config_Bluetooth.begin(9600); //Default Baud rate of your Bluetooth Module Serial Monitor
pinMode(TX, OUTPUT);
pinMode(RX, INPUT);

pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);

pinMode(LED, OUTPUT);
pinMode(ButtonPin_1, INPUT_PULLUP);
pinMode(ButtonPin_2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonPin_1), Motor_1, CHANGE);
attachInterrupt(digitalPinToInterrupt(ButtonPin_2), Motor_2, CHANGE);

//===========================================================================
pinMode(stepPin_1, OUTPUT);
pinMode(dirPin_1, OUTPUT);
digitalWrite(dirPin_1, HIGH); //Setting the rotation of stepper 1 to always move clockwise.

pinMode(stepPin_2, OUTPUT);
pinMode(dirPin_2, OUTPUT);

pinMode(stepPin_3, OUTPUT);
pinMode(dirPin_3, OUTPUT);

pinMode(stepPin_4, OUTPUT);
pinMode(dirPin_4, OUTPUT);

pinMode(stepPin_5, OUTPUT);
pinMode(dirPin_5, OUTPUT);

pinMode(ButtonPin_1_Red, OUTPUT);
pinMode(ButtonPin_1_GREEN, OUTPUT);
pinMode(ButtonPin_2_Red, OUTPUT);
pinMode(ButtonPin_2_GREEN, OUTPUT);
digitalWrite(ButtonPin_2_Red, HIGH); //Starting Both Motors off
digitalWrite(ButtonPin_1_Red, HIGH);
digitalWrite(Relay_1, LOW);
digitalWrite(Relay_2, LOW);
}

void loop() {
// put your main code here, to run repeatedly:
if (Config_Bluetooth.available() > 0)
{
BLE_state = Config_Bluetooth.read();
Serial.print("Bluetooth Command Received : "); Serial.println(BLE_state);
}

BLE_Check();

// Stepper_1();

if ((seconds % 30 == 0) && flag == 0) //Run at seconds at 0
{
Stepper_2();
flag = 1;
}
if ((seconds % 31 == 0) && flag == 1) //Runs at seconds at 30 +2 seconds of delay so after 32 secs of board switch on
{
Stepper_3();
flag = 2;
}

if ((seconds % 31 == 0) && flag == 2) //Runs at seconds at 60 + 2(from before) +2(current) seconds of delay so after 64 secs of board switch on
{
Stepper_4();
flag = 3;
}

if ((seconds % 31 == 0) && flag == 3) //Runs at seconds at 96
{
Stepper_5();
flag = 4;
}
if ((seconds % 31 == 0) && flag == 4) //Resets at seconds at 128 to intial conditions to run back loop
{
seconds = 0;
flag = 0;
}

}

void Stepper_1()
{
Serial.println("Running the Stepper 1 Countinously");
// _Step(stepPin_1);
}

void Stepper_2()
{
Serial.println("Taking 1/4 turn for Stepper 2 and pausing for 2 secs");
digitalWrite(LED, HIGH);

digitalWrite(dirPin_2, HIGH);
for (i = 0; i < Step; i++) {
_Step(stepPin_2);
// _Step(stepPin_1);
}

for (i = 0; i < 2000; i++) //2s blocking function but keep running stepper 1 during this time.
{
delay(1);
// _Step(stepPin_1);

}

Serial.println("Moving back 1/4 for Stepper 2.");
digitalWrite(dirPin_2, LOW);
for (i = 0; i < Step; i++) {
_Step(stepPin_2);
// _Step(stepPin_1);
}
digitalWrite(LED, LOW);
}

void Stepper_3()
{
Serial.println("Taking 1/4 turn for Stepper 3 and pausing for 2 secs");
digitalWrite(LED, HIGH);

digitalWrite(dirPin_3, HIGH);

for (i = 0; i < Step; i++) {
_Step(stepPin_3);
// _Step(stepPin_1);
}

for (i = 0; i < 2000; i++) //2s blocking function but keep running stepper 1 during this time.
{
delay(1);
// _Step(stepPin_1);

}
Serial.println("Moving back 1/4 for Stepper 3.");

digitalWrite(dirPin_3, LOW);
for (i = 0; i < Step; i++) {
_Step(stepPin_3);
// _Step(stepPin_1);
}
digitalWrite(LED, LOW);
}

void Stepper_4()
{
Serial.println("Taking 1/4 turn for Stepper 4 and pausing for 2 secs");
digitalWrite(LED, HIGH);

digitalWrite(dirPin_4, HIGH);
for (i = 0; i < Step; i++) {
_Step(stepPin_4);
// _Step(stepPin_1);
}

for (i = 0; i < 2000; i++) //2s blocking function but keep running stepper 1 during this time.
{
delay(1);
// _Step(stepPin_1);

}

Serial.println("Moving back 1/4 for Stepper 4.");

digitalWrite(dirPin_4, LOW);
for (i = 0; i < Step; i++) {
_Step(stepPin_4);
// _Step(stepPin_1);
}
digitalWrite(LED, LOW);
}

void Stepper_5()
{
Serial.println("Taking 1/4 turn for Stepper 5 and pausing for 2 secs");
digitalWrite(LED, HIGH);

digitalWrite(dirPin_5, HIGH);
for (i = 0; i < Step; i++) {
_Step(stepPin_5);
// _Step(stepPin_1);
}

for (i = 0; i < 2000; i++) //2s blocking function but keep running stepper 1 during this time.
{
delay(1);
// _Step(stepPin_1);

}

Serial.println("Moving back 1/4 for Stepper 5.");

digitalWrite(dirPin_5, LOW);
for (i = 0; i < Step; i++) {
_Step(stepPin_5);
// _Step(stepPin_1);
}
digitalWrite(LED, LOW);
}

void Motor_1()
{
Serial.println("Switch for Motor 1 pressed.");
// state_1 = !state_1; //Changing state i.e. if motor on switch it off and vice versa.
//
if(digitalRead(ButtonPin_1) == LOW)
{
digitalWrite(ButtonPin_1_GREEN, HIGH);
digitalWrite(ButtonPin_1_Red, LOW);
digitalWrite(Relay_1, HIGH);
}
else
{
digitalWrite(ButtonPin_1_GREEN, LOW);
digitalWrite(ButtonPin_1_Red, HIGH);
digitalWrite(Relay_1, LOW);
}
}

void Motor_2()
{
Serial.println("Switch for Motor 2 pressed.");
// state_2 = !state_2; //Changing state i.e. if motor on switch it off and vice versa.
// digitalWrite(Relay_2, state_2);
if(digitalRead(ButtonPin_2) == LOW)
{
digitalWrite(ButtonPin_2_GREEN, HIGH);
digitalWrite(ButtonPin_2_Red, LOW);
digitalWrite(Relay_2, HIGH);
}
else
{
digitalWrite(ButtonPin_2_GREEN, LOW);
digitalWrite(ButtonPin_2_Red, HIGH);
digitalWrite(Relay_2, LOW);
}
}

void BLE_Check()
{
if (BLE_state == 'A') //A : The ON state command to program in app so that when it is pressed motor 1 turns ON
{
Serial.println("Bluetooth Motor 1 turned On.");
digitalWrite(Relay_1, HIGH);
{
digitalWrite(ButtonPin_1_GREEN, HIGH);
digitalWrite(ButtonPin_1_Red, LOW);
}
}

else if (BLE_state == 'B') //B : The OFF state command to program in app so that when it is pressed motor 1 turns OFF
{
Serial.println("Bluetooth Motor 1 turned OFF.");
digitalWrite(Relay_1, LOW);
{
digitalWrite(ButtonPin_1_GREEN, LOW);
digitalWrite(ButtonPin_1_Red, HIGH);
}
}

else if (BLE_state == 'C') //C : The ON state command to program in app so that when it is pressed motor 2 turns ON
{
Serial.println("Bluetooth Motor 2 turned ON.");
digitalWrite(Relay_2, HIGH);
digitalWrite(ButtonPin_2_GREEN, HIGH);
digitalWrite(ButtonPin_2_Red, LOW);
}
else if (BLE_state == 'D') //D : The OFF state command to program in app so that when it is pressed motor 2 turns OFF
{
Serial.println("Bluetooth Motor 2 turned OFF.");
digitalWrite(Relay_2, LOW);
digitalWrite(ButtonPin_2_GREEN, LOW);
digitalWrite(ButtonPin_2_Red, HIGH);
}
}

//-------------------------------------------------
void _Step(int stepPin)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
ISR(TIMER0_COMPA_vect) {
//generates pulse wave of frequency 1Hz/2 = 0.5kHz (takes two cycles for full wave- toggle high then toggle low)
temp=temp+1;
if (temp >=1000)
{
temp =0;
seconds++;
Serial.println(seconds);
}
}

ISR(TIMER1_COMPA_vect){//timer0 interrupt 100Hz
//generates pulse wave of frequency 100Hz/2 = 250Hz (takes two cycles for full wave- toggle high then toggle low)
if (speed_1 == 50)
{
speed_1 = 0;
digitalWrite(stepPin_1, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin_1, LOW);
delayMicroseconds(500);
}
speed_1 = speed_1 + 1;
}