Error 507 hc 05 bluetooth module continuation

Hi, I have a question on the topic where I need to send data from arduino to mit app inventor app, and I am curious what blocks are needed on the app to change a text on the app display based on the number I receive from arduino
Thanks in advance.

Maybe you can explain what you are trying to do. What is the Arduino you are using?
Do you have already (part of) an app? If yes show your blocks, if no, where does the error come from?

Hi,
So I use arduino uno and Ibasically have to send ones and zeros to the phone. One is send if microswitch isn't pressed and then I have to set the label text to "open" and zero if it is pressed and set the label to "closed".



First photo shows my app screen where "položaj vrata" is the label that should say whether it is open or closed and second picture shows my blocks in clock timer in order to change the text and third one shows the initial blocks I was given that are not related to this open-closed status

The second set of blocks would work if you would end each message from the Arduino with a println() but it seems that you are sending bytes only. How do you know how many bytes are sent? Can you also show the relevant part of your .ino file? And last question, when does the error exactly occur?

Hi,
So I basically use digital read function with serial.print(via bluetooth)[ would that worl with serial.printIn?] where I receive ones and zeros. Everything in the app works fine except that I don't receive any change in label text based on the digital read state

Dear @Bruno_Dragas,
just to make it clear (to me): the first "clock1" block that you have posted is not the one we are talking about, but the second one (the one with the receivetext) ?

So I basically use digital read function with serial.print(via bluetooth)[ would that work with serial.printIn?]
The answer is yes, as @Ghica has already said, to use the -1 in the receive text you shall terminate the BT transmission from Arduino with a LineFeed character (ASCII character 10-decimal or 0x0A-hexadecimal). This is obtained by using a BTserial.println('0') [or ('1')].
Please note that in this case you shall send characters, and not bytes (numbers): for this reason you have to send '1' or '0'.

Everything in the app works fine except that I don't receive any change in label text based on the digital read state
This means that in the label L_DataBT you cannot show what you are sending from Arduino ? And what is it shown, instead ?

If you indeed want to use the delimeter byte concept by sending println, the make sure that you put in the delimiter byte value:

DelimiterByte
Returns the delimiter byte to use when passing a negative number for the numberOfBytes parameter when calling ReceiveText, ReceiveSignedBytes, or ReceiveUnsignedBytes.

(when using println() that value should be 10 in the delimiterbyte, set that in the design).
Your first picture of blocks is really strange. As you said, you send only one byte at the time, for your first block that would not work, because you are receiving first one byte, and in your current setup that should be all, so, there should be nothing left. Then you are reading again, to see if the byte is 1, but there will be no byte.
In the first call you should assign the byte to some global variable, and the second call to receive one byte should go away. Maybe use the suggestion from Uskiara and sent 0 and 1 as a character instead, and use your second set of blocks instead.
Also, next time, click with your right mouse button on the block you want to show and choose download blocks as .png. That will be much better readable!

1 Like

Here is my code, note thst the line where it says "Serial.print(x)" normally says "BTSerial.print(x)" but I was checking whether it was shown on the serial monitor
#include <SoftwareSerial.h>
#define TxPin 11 // required by SoftwareSerial (PWM capabilities needed)
#define RxPin 10 // required by SoftwareSerial (PWM capabilities needed)

SoftwareSerial BTSerial(RxPin,TxPin); // instantiate the library

char state = ' '; // define input buffer as char (not empty but a blank)
const int stepPin = 4;
const int directionPin = 2;

//===============================================================================================
void setup() // done once at reset
{
pinMode(8, INPUT);
pinMode(stepPin,OUTPUT);
pinMode(directionPin,OUTPUT);
pinMode(RxPin,INPUT); // to be connected to Tx pin of HC05
pinMode(TxPin,OUTPUT); // to be connected to Rx pin of HC05
BTSerial.begin(9600); // supposed baudrate of HC05 (38400 ?)
Serial.begin(9600); // Used to echo on PC monitor the data received on BT

}

//===============================================================================================
void loop() // repeated forever
{

int x = digitalRead(8);

Serial.print(x);
delay(100);

if (BTSerial.available()) // any char from BT ?
{

state = BTSerial.read(); // yes, get it
Serial.print("Received : "); // echoes it on the PC screen
Serial.println(state);
if(state=='2') {// the received char to switch off the led
digitalWrite(directionPin,HIGH); //npr zatvori
for(int x = 0; x < 50; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
}

if(state=='3') {// the received char to switch on the led
digitalWrite(directionPin,LOW); //npr otvori
for(int x = 0; x < 50; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
}
}
}

OK, :+1:
then, are you transmitting characters ? i.e. '0' and '1' ? otherwise your ReceiveText block can be foolished if you trasmit numbers.
How your Arduino code looks like ? Can you post it ? At least the tramsission related function.

EDIT:
I was not able to read the clock1 blocks before. Now I did, and I agree totally with @Ghica. In clock1 you first receive a signed byte, and this empties the input buffer, then you try to read it again as a text, but at that moment the input buffer has been already emptied by the readbyte.
Therefore you shall only read as text once, without reading as a number before.
All that, by supposing that you send back a character to the AI2 app . You say that in the "real code" instead of Serial.println(state) you use the BTSerial,println(state).
Be sure that you don't do the same with the line Serial.print("Received: "): this row of code sends the string "Received: " to the serial monitor; and in this case you miss to send to the serial monitor also the 'state' received from the Ai2 app.
It seems to me that you you mixed up my sample code with yours, but you forgot (at least in the one you posted) some rows.

Well if you are referring to arduino code ablut the led turning on off. I included only data that was needed for my project here...

I am curious now what is the error here exactly. Should I change the arduino code to serial.printIn and include the text blocks in mit app inventor block editor rather than receiving numbers?

Dear @Bruno_Dragas,
you say that you have only added the rows needed to your purposes, nevertheless you have forgotten the feedback to AI2: in my example, the last row of the loop was sending the 'state' back to the app:


and I can't see it in your code.
Moreover, in the clock1 blocks, since you always display the received character (either '1' or '0'), you could simplify it as follows:
image

For the first part I honestly thought it wasn't needed. Thanks for your feedback. For the second part I need 2 variations of text,"Closed" if the received character is "1" and "open" if it is "0" so I can just add if-then-else instead of the second if-then?

sure you can :+1:

Sorry I am not near my laptop so I had to open it with my phone. Would this work? I am not sure if I understood correctly. The first text in pink is "opened" while the other "closed"

Nope :slight_smile:
The following should work in case your Arduino sends back a '0' for state = '0', which means "OFF" while it sends back a '1' for state = '1', which means "ON".
Of course you can adapt it with your wording and to your needs. :


The label R_received_BT jsut shows what is received whilst L_Status shows ON/OFF according to the character received.
In case that none answer is recognized a warning is displayed, instead.

1 Like

Hi, what did you set initialize global_Input_Buffer to so you could use it? And also couple of hours ago I tried to connect to the app and after I connected to bt I am unable to press any of the buttons and the app just does not react. Any reason maybe?

Hi, what did you set initialize global_Input_Buffer to so you could use it? And also couple of hours ago I tried to connect to the app and after I connected to bt I am unable to press any of the buttons and the app just does not react. Any reason maybe? Thanks

Hi @Bruno,
Hi, what did you set initialize global_Input_Buffer to so you could use it?
If the question is to what it is initialized, the answer is
image

And
after I connected to bt I am unable to press any of the buttons and the app just does not react.
If you are still using my .aia, please be aware that it tries 3 times to connect the BT and while it is doing this job, the rest of the app hangs (so nothing else can be done, neither the buttons do react).
Moreover, if the BT connection fails, and if nevertheless you push a button, it can happen an unexpected behaviour, since any button tries to send a text on the BT, whilst it is not available.

So I am having a little problem grasping what you just said :slight_smile: