R rfsingh81 Member Licensed User Longtime User Jun 3, 2013 #1 I am trying to play with the BT example and on the other end I have a microcontroller which is receiving the data from this module. I am facing a problem: My Micro is waiting for decimal number. If the decimal number is 4 it switches on 1 led if 5 then the other. Now My tablet is connected to the module, and when I type 4 on the chat window, I HAVE TO PRESS IT TWICE for the other side to accept it as 4. Same happens with 5. I would like to ask what happens on the app side. I am more into programming micros and trying to build an app for the first time. I am interested in the following code and thinking if this has something to do with the problem: Code: Copy Sub btnSend_Click AStream.Write(txtInput.Text.GetBytes("UTF8")) txtInput.SelectAll txtInput.RequestFocus LogMessage("Me", txtInput.Text) End Sub I am sorry but I am not into this programming a lot, so don't know if the above makes perfect sense but I tried to delivery my problem here in a hope that it can be understood. But I welcome any clarification if needed. Thanks
I am trying to play with the BT example and on the other end I have a microcontroller which is receiving the data from this module. I am facing a problem: My Micro is waiting for decimal number. If the decimal number is 4 it switches on 1 led if 5 then the other. Now My tablet is connected to the module, and when I type 4 on the chat window, I HAVE TO PRESS IT TWICE for the other side to accept it as 4. Same happens with 5. I would like to ask what happens on the app side. I am more into programming micros and trying to build an app for the first time. I am interested in the following code and thinking if this has something to do with the problem: Code: Copy Sub btnSend_Click AStream.Write(txtInput.Text.GetBytes("UTF8")) txtInput.SelectAll txtInput.RequestFocus LogMessage("Me", txtInput.Text) End Sub I am sorry but I am not into this programming a lot, so don't know if the above makes perfect sense but I tried to delivery my problem here in a hope that it can be understood. But I welcome any clarification if needed. Thanks
Beja Expert Licensed User Longtime User Jun 3, 2013 #2 Hi rfsingh81, try to increase the delay in the MCU firmware. Upvote 0
R rfsingh81 Member Licensed User Longtime User Jun 3, 2013 #3 Beja said: Hi rfsingh81, try to increase the delay in the MCU firmware. Click to expand... Hi, it is not possible as there is no feature for doing that. The code below will explain more: Code: Copy Main: Debugin [DEC B0] if b0=4 then GoSub TOG ; led 1 toggles if b0=5 then GoSub DOG ; led 2 toggles Pause 200 Goto Main B0 is a byte, and the first command loads the byte into B0. I think it is something to do with the way data is sent from the App. Is it possible to send the data as a decimal or a STRING in one go? What changes will I need to do to accomplish that (if possible)? Upvote 0
Beja said: Hi rfsingh81, try to increase the delay in the MCU firmware. Click to expand... Hi, it is not possible as there is no feature for doing that. The code below will explain more: Code: Copy Main: Debugin [DEC B0] if b0=4 then GoSub TOG ; led 1 toggles if b0=5 then GoSub DOG ; led 2 toggles Pause 200 Goto Main B0 is a byte, and the first command loads the byte into B0. I think it is something to do with the way data is sent from the App. Is it possible to send the data as a decimal or a STRING in one go? What changes will I need to do to accomplish that (if possible)?
Beja Expert Licensed User Longtime User Jun 3, 2013 #4 Can you post the MCU code that controls the I/O? The code above tells it may be a high-level interpreted code which is used in Basic Stamp and similar modules.. you need to edit the MCU firmware. I still believe this is a sync problem and not from the bt example. Also try to put the I/O module far from the mobile device. Upvote 0
Can you post the MCU code that controls the I/O? The code above tells it may be a high-level interpreted code which is used in Basic Stamp and similar modules.. you need to edit the MCU firmware. I still believe this is a sync problem and not from the bt example. Also try to put the I/O module far from the mobile device.
R rfsingh81 Member Licensed User Longtime User Jun 3, 2013 #5 Hi Beja, the code which relates to receiving data and I/O operation is above. There is nothing more to it MCU code wise, yes the language is PICBasic. I have checked the manual and I can confirm not even a single word is mentioned on handling a UTF8 character or conversion of it to decimal or string. So what I wanted to ask is how can he following be changed : AStream.Write(txtInput.Text.GetBytes("UTF8")) Click to expand... To send a fixed character as a string or decimal. Lets say for example send an String "a" or decimal equivalent of "a". Upvote 0
Hi Beja, the code which relates to receiving data and I/O operation is above. There is nothing more to it MCU code wise, yes the language is PICBasic. I have checked the manual and I can confirm not even a single word is mentioned on handling a UTF8 character or conversion of it to decimal or string. So what I wanted to ask is how can he following be changed : AStream.Write(txtInput.Text.GetBytes("UTF8")) Click to expand... To send a fixed character as a string or decimal. Lets say for example send an String "a" or decimal equivalent of "a".
R rfsingh81 Member Licensed User Longtime User Jun 3, 2013 #6 Ok. I just downloaded serialMon software and found out that UTF8 means plain text. So my question now is - What is the HEX or Decimal Equivalent of UTF8 character 4? And is there any table of equivalent values? Upvote 0
Ok. I just downloaded serialMon software and found out that UTF8 means plain text. So my question now is - What is the HEX or Decimal Equivalent of UTF8 character 4? And is there any table of equivalent values?
GMan Well-Known Member Licensed User Longtime User Jun 3, 2013 #7 Sites like this Unicode, Hexadecimal, Decimal NCR, UTF-8 Converter -- EndMemo will help you. You can find them in a place called internet Upvote 0
Sites like this Unicode, Hexadecimal, Decimal NCR, UTF-8 Converter -- EndMemo will help you. You can find them in a place called internet
Beja Expert Licensed User Longtime User Jun 3, 2013 #8 will test the example code in my Atmel and PIC16 boards and get back to you, hopefully soon as I am a little busy now with other things. Upvote 0
will test the example code in my Atmel and PIC16 boards and get back to you, hopefully soon as I am a little busy now with other things.
R rfsingh81 Member Licensed User Longtime User Jun 4, 2013 #9 Thanks Thanks Beja and GMan. I did it finally :sign0060: . The problem was that every 4 bit nibble of hex showing on my screen was actually a whole byte of 8 bits. So adjusting the variables did the job. JOB DONE! Cheers for the help. Upvote 0
Thanks Thanks Beja and GMan. I did it finally :sign0060: . The problem was that every 4 bit nibble of hex showing on my screen was actually a whole byte of 8 bits. So adjusting the variables did the job. JOB DONE! Cheers for the help.
Beja Expert Licensed User Longtime User Jun 4, 2013 #10 Thanks, Would you please share with us your solution? how did the problem solved? I mean the steps you made. thanks in advance.. Upvote 0
Thanks, Would you please share with us your solution? how did the problem solved? I mean the steps you made. thanks in advance..
KitCarlson Active Member Licensed User Longtime User Jun 4, 2013 #11 Rfsingh81, You have made an important discovery! The representation of data is fundamental to handling it. You will find different computer languages often handle data types differently. By learning the details, you are well on the way, if not already, to be a great programmer. Cheers! Upvote 0
Rfsingh81, You have made an important discovery! The representation of data is fundamental to handling it. You will find different computer languages often handle data types differently. By learning the details, you are well on the way, if not already, to be a great programmer. Cheers!
R rfsingh81 Member Licensed User Longtime User Jun 4, 2013 #12 KitCarlson said: Rfsingh81, You have made an important discovery! The representation of data is fundamental to handling it. You will find different computer languages often handle data types differently. By learning the details, you are well on the way, if not already, to be a great programmer. Cheers! Click to expand... Thanks M8 for the appreciation. Beja, I did the following change: Code: Copy Main: Debugin [Wait(1), B0] if b0=4 then GoSub TOG ; led 1 toggles if b0=5 then GoSub DOG ; led 2 toggles Pause 200 Goto Main Now it waits for the 1 to arrive first and then loads the value in B0 - Which has the actual value (HEX type). Now I am trying to handle the data the opposite way i.e. MCU to tablet. If I get stuck, I will open another thread and hope to get support from you guys. Cheers! Upvote 0
KitCarlson said: Rfsingh81, You have made an important discovery! The representation of data is fundamental to handling it. You will find different computer languages often handle data types differently. By learning the details, you are well on the way, if not already, to be a great programmer. Cheers! Click to expand... Thanks M8 for the appreciation. Beja, I did the following change: Code: Copy Main: Debugin [Wait(1), B0] if b0=4 then GoSub TOG ; led 1 toggles if b0=5 then GoSub DOG ; led 2 toggles Pause 200 Goto Main Now it waits for the 1 to arrive first and then loads the value in B0 - Which has the actual value (HEX type). Now I am trying to handle the data the opposite way i.e. MCU to tablet. If I get stuck, I will open another thread and hope to get support from you guys. Cheers!
R rfsingh81 Member Licensed User Longtime User Jun 5, 2013 #13 Another Question Hi, I thought it would be more appropriate to ask this question here as some of you already aware of my aims. Now, I am trying to send data from the MCU to the APP running on my tablet. The MCU Side is like this: Code: Copy debug "a" // Send 'a' as a string The app side is something like this: Code: Copy Sub AStream_NewData (Buffer() As Byte) ToastMessageShow(BytesToString(Buffer, 0, Buffer.Length, "UTF8"),True) ' LoadMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8")) End Sub THE PROBLEMS: 2 problems I am facing with running this code. a) After MCU sends the data, twice in a row the bluetooth example stops working on the second time b) No data is toast displayed on my tablet screen. Upvote 0
Another Question Hi, I thought it would be more appropriate to ask this question here as some of you already aware of my aims. Now, I am trying to send data from the MCU to the APP running on my tablet. The MCU Side is like this: Code: Copy debug "a" // Send 'a' as a string The app side is something like this: Code: Copy Sub AStream_NewData (Buffer() As Byte) ToastMessageShow(BytesToString(Buffer, 0, Buffer.Length, "UTF8"),True) ' LoadMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8")) End Sub THE PROBLEMS: 2 problems I am facing with running this code. a) After MCU sends the data, twice in a row the bluetooth example stops working on the second time b) No data is toast displayed on my tablet screen.
KitCarlson Active Member Licensed User Longtime User Jun 5, 2013 #14 Many experience problems using prefix mode without setting length in first 32 bits. The solution is non prefix mode. There are many posts on this. The system hangs because the "a" is interpreted as a length, and receive waits for more. Upvote 0
Many experience problems using prefix mode without setting length in first 32 bits. The solution is non prefix mode. There are many posts on this. The system hangs because the "a" is interpreted as a length, and receive waits for more.
Erel B4X founder Staff member Licensed User Longtime User Jun 5, 2013 #15 Many experience problems using prefix mode without setting length in first 32 bits. Click to expand... Prefix mode can only work if both sides of the connection adhere to the protocol. Another possible "message handler" is implemented in AsyncStreamsText class. Upvote 0
Many experience problems using prefix mode without setting length in first 32 bits. Click to expand... Prefix mode can only work if both sides of the connection adhere to the protocol. Another possible "message handler" is implemented in AsyncStreamsText class.
R rfsingh81 Member Licensed User Longtime User Jun 5, 2013 #16 Attempt 1 KitCarlson said: Many experience problems using prefix mode without setting length in first 32 bits. The solution is non prefix mode. There are many posts on this. The system hangs because the "a" is interpreted as a length, and receive waits for more. Click to expand... I tried and found the info about prefix and changed the following line in the example to: Code: Copy AStream.InitializePrefix(Main.serial1.InputStream, False, Main.serial1.OutputStream, "AStream") I changed the code of my MCU a little to accept the changes the way info will come this time. It Worked FinE. When the MCU sent the data in return, the message which came on the screen is: 'Connection is Broken' which is a part of error sub. Upvote 0
Attempt 1 KitCarlson said: Many experience problems using prefix mode without setting length in first 32 bits. The solution is non prefix mode. There are many posts on this. The system hangs because the "a" is interpreted as a length, and receive waits for more. Click to expand... I tried and found the info about prefix and changed the following line in the example to: Code: Copy AStream.InitializePrefix(Main.serial1.InputStream, False, Main.serial1.OutputStream, "AStream") I changed the code of my MCU a little to accept the changes the way info will come this time. It Worked FinE. When the MCU sent the data in return, the message which came on the screen is: 'Connection is Broken' which is a part of error sub.
KitCarlson Active Member Licensed User Longtime User Jun 5, 2013 #17 That is still using prefix mode. I do not have, my pc, I seem to remember it is just initialize. The lost connection may also be hardware issue. Too much distance, power loss or noise. Upvote 0
That is still using prefix mode. I do not have, my pc, I seem to remember it is just initialize. The lost connection may also be hardware issue. Too much distance, power loss or noise.
Beja Expert Licensed User Longtime User Jun 5, 2013 #18 set a Boolean variable (flag), to see for new data before trying to act on them. Upvote 0
IanMc Well-Known Member Licensed User Longtime User Jun 5, 2013 #19 The thing is that the serial connection, virtual over bluetooth or otherwise is 'character based' and yes, one character is 8 bits with or without 1 stop bit and with or without 1 parity bit so each character received will be ... a character You just have to remember the old RS232 stuff. Upvote 0
The thing is that the serial connection, virtual over bluetooth or otherwise is 'character based' and yes, one character is 8 bits with or without 1 stop bit and with or without 1 parity bit so each character received will be ... a character You just have to remember the old RS232 stuff.
R rfsingh81 Member Licensed User Longtime User Jun 7, 2013 #20 Beja said: set a Boolean variable (flag), to see for new data before trying to act on them. Click to expand... Thanks. Is there any code example somewhere pertaining to what you mean? It will be easier for me to tweak any existing code than break my head against a wall for doing silly mistakes in writing it myself. Currently my sub looks like this: Code: Copy Sub AStream_NewData (Buffer() As Byte) ToastMessageShow(BytesToString( Buffer, 0, Buffer.Length, "UTF8"),True) ' LoadMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8")) End Sub Upvote 0
Beja said: set a Boolean variable (flag), to see for new data before trying to act on them. Click to expand... Thanks. Is there any code example somewhere pertaining to what you mean? It will be easier for me to tweak any existing code than break my head against a wall for doing silly mistakes in writing it myself. Currently my sub looks like this: Code: Copy Sub AStream_NewData (Buffer() As Byte) ToastMessageShow(BytesToString( Buffer, 0, Buffer.Length, "UTF8"),True) ' LoadMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8")) End Sub