perfect, it works great! Thank you for your effort and your patience to do this. I know nothing about kotlin or android studio and I think this is the best way to learn. Old cell phones can be recycled and usefull again with apps. I (as other people here) will try to send serial data from a HC06 to the cell phone and process/save it. I also liked your calm style, and your explaining everything. Great Job
It doesn´t work, could you help me? Everything´s working fine, when I clic a button in the app the arduino 'TX' led turns on, but LED connected to Pin 13 does not. Maybe is 'cause in the app you have sendCommand("a") & sendCommand("b") A&B toByteArray , and arduino expects a '1' or '0'. How can I fix this? Thanks
Same Problem here. Have you been able to fix it? Nevermind. You were right. I just changed "a" and "b" to "1" and "0" in ControlActivity.kt and it worked. Ty
I think he renamed the MainActivity to SelectDeviceActivity or somethig so u just need to switch SelectDeviceActivity to MainActivity (tahts what i did)
@@ballaownz It's what sepldepl said; we change the line where we define class for MainActivity.kt (or SelectDeviceActivity.kt, if you renamed the file but not the classname) from: class MainActivity : AppCompatActivity() { to: class SelectDeviceActivity : AppCompatActivity() { This solved my issue here
I copied your code exactly and when I run the app with the bluetooth module running on the arduino, it says no paired devices found. I checked on my phones usual bluetooth in settings and it can pick up several paired devices, but they're not visible from this app that we made...
You already pass Context as c in the default constructor. Just declare it as a val [val c:Context] instead of as a parameter [c:Context] and you can avoid the leaky copy of Context that you create and use [c] where needed instead of [context]
This is an excellent tutorial!! I am looking for read data from the Bluetooth and make some routines to search the devices, so , I don't need to pair before. Would you have plans to release some tutorial to perform these as well? Thanks again for sharing your knowledge! I really appreciate it.
This is a great tutorial, I really like it. I tried the app and everything works, but I couldn't connect to the bluetooth device. The logcat says: couldn't connect Do you know this problem and may know how I can fix it?
Hi ! Can you tell us how you did it please ? i've written this code but in a loop but it the progress dialogue of the doInBackground function won't disapear : fun checkReceive(){ if (m_bluetoothSocket != null) { var input = m_bluetoothSocket!!.inputStream var buffer: ByteArray = ByteArray(1024) var bytes: Int try { bytes = input.read(buffer) var incomingMessage = String(buffer, 0, bytes); Toast.makeText(this, incomingMessage, Toast.LENGTH_SHORT).show() } catch (e: IOException){ e.printStackTrace() } } }
@@theoberessi6794 I've setup a background thread the looks for data received in the BT buffer and acts on that.. whats your email I'll send you some code snippets
OK guys I've figured it by myself :) Instead of ArrayList we can simpy use ArrayList and then we can add elements to our list by using "device.name". Code: val names : ArrayList = ArrayList() if (m_pairedDevices.isNotEmpty()) { for (device : BluetoothDevice in m_pairedDevices) { names.add(device.name) //Log.i("device", ""+device) } } else { toast("No paired BT devices found...") } val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, names) If I'm wrong in this point please tell me - I'm not so experienced with android studio and Kotlin :)
@@ksaweryc I tried to replaced it like you did but the app crashed when i tried to connect to a device. It's because we use the object BluetoothDevice in the other activity, so instead i jest added your code with the alreading existing code : val list : ArrayList = ArrayList() val names : ArrayList = ArrayList() if(m_pairedDevices.isNotEmpty()){ for(device: BluetoothDevice in m_pairedDevices){ list.add(device) names.add(device.name) Log.i("device", ""+device) } } else { Toast.makeText(this, "No paired bluetooth devices found", Toast.LENGTH_SHORT).show() } val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, names)
Hi Diego, thanks for the comment. The reason for making the functions private is because I didn't want other Classes/Activities from calling them. If there is a specific function that you want to know about please let us know.
Apps In The Sky thanks for the code! Though I have tried this code but it does not work if I change 1 and 0 with 'a' and 'b' in Arduino. So I made the app send 1 or 0 instead and it worked. Great tutorial man!👍
I'm sorry, but how did you get that UUID?
Bro, I just wanted to say THANKS.
You’re a genius and you saved my project.
THANKS again :’)
how can i read data from the device?
perfect, it works great! Thank you for your effort and your patience to do this. I know nothing about kotlin or android studio and I think this is the best way to learn. Old cell phones can be recycled and usefull again with apps. I (as other people here) will try to send serial data from a HC06 to the cell phone and process/save it.
I also liked your calm style, and your explaining everything. Great Job
Bestest example about this interaction, Thanks for your help...
Great tutorial!
But please use a series resistor for the led.
Clear and concise tutorial. Very useful.
Where do I get the UUID?
It doesn´t work, could you help me? Everything´s working fine, when I clic a button in the app the arduino 'TX' led turns on, but LED connected to Pin 13 does not. Maybe is 'cause in the app you have sendCommand("a") & sendCommand("b") A&B toByteArray , and arduino expects a '1' or '0'. How can I fix this? Thanks
Same Problem here.
Have you been able to fix it?
Nevermind.
You were right.
I just changed "a" and "b" to "1" and "0" in ControlActivity.kt and it worked.
Ty
@@poobels you could also change Arduino file to expect A and B
Hi, thank you again !
I have "Unresolved SelectDeviceActivity" !
Do you have an idea ?
I have the same issue, did you fix it?
@@KiroLive No, I didn't !
I try to mail the video creator but they seems to be dead (or, at least, out of the game) !
I think he renamed the MainActivity to SelectDeviceActivity or somethig so u just need to switch SelectDeviceActivity to MainActivity (tahts what i did)
Same here, any ideas?
@@ballaownz It's what sepldepl said; we change the line where we define class for MainActivity.kt (or SelectDeviceActivity.kt, if you renamed the file but not the classname) from:
class MainActivity : AppCompatActivity() {
to:
class SelectDeviceActivity : AppCompatActivity() {
This solved my issue here
Where did you get the UUID from? does it work with any device? you didn't explain that part
I copied your code exactly and when I run the app with the bluetooth module running on the arduino, it says no paired devices found. I checked on my phones usual bluetooth in settings and it can pick up several paired devices, but they're not visible from this app that we made...
You already pass Context as c in the default constructor. Just declare it as a val [val c:Context] instead of as a parameter [c:Context] and you can avoid the leaky copy of Context that you create and use [c] where needed instead of [context]
Async and a couple other things are out of date. does anyone know of an updated one?
How can i use toast inside postexecute in your program? 🙏
Hi!, how can we read the RSSI value of that bluetooth signal? can anyone please answer it?
This is an excellent tutorial!! I am looking for read data from the Bluetooth and make some routines to search the devices, so , I don't need to pair before. Would you have plans to release some tutorial to perform these as well? Thanks again for sharing your knowledge! I really appreciate it.
I have done exactly as you have shown here, app is working but it doesn't showing paired devices in listview
Great tutorial. Works like a charm. Thanks!
WoW Such an amazing tutorial Thank you so much!
Excellent Tutorial, but can you please help with update? AsyncTask is deprecated now and i dont know what to do :(
File -> Project Structure -> Modules -> Compile Sdk Version -> 28, Then is works
thank you so much man...... you literally saved my life
please make a similar tutorial but for BLE communication with an arduino, and how to store our datas
Dude you're awesome. Thanks!
its so awesome you are the only person how do this witout appinventor ty so much
it uses bluetooth or BLE?
Hello, Where can I find Arduino code? Thank You
Great job! I am getting this error "isSocketAllowdBySecurityPolicy start :device null" Some idea? thanks
I have an error: Inactivity, disconnecting from the service.
I don't know how to fix it. Can you help me? Thanks
What does he exactly send to the Bluetooth module?
this is really good tutorial! everything works fine, but can it receive something from arduino??
Good question
@@canererhadim3772 Ben de aynı şeyi araştırıyorum ? Bu sorunu çözebildin mi
Thank you so much from Spain¡
How can I read data from m_bluetoothSocket instead of write? I just want to show my arduino's data inside the app.
Anyway. I've discovered. Just use Reader.
val reader = Reader(m_bluetoothSocket!!.inputStream)
reader.nextLine() (depends on your data stream)
@@kleanlins hi, can u share your code ? i am new in kotlin - aimonboard@gmail.com - thanks
could any of you share your code? cant seem to figure out how to read data from the device connected.
Hi, can you share your code please ? I can't figure it out :/
Great tutorial!! It works !!
Nice tutorial! Thanks
Interesting video but how can we receive datas from an arduino to the application ? (And how can we display it ?)
Hi Devpax, thanks for the comment. We have a tutorial about reading data from an Arduino via Bluetooth coming very soon.
I can't wait for this. These tutorials are helpful, but I haven't figured out how to read my Arduino code on my own.
@@apptaura8131 do you have upload the tutorial?
@@apptaura8131 Where is it ? :)
AMAZING tutorial thanks
ASyncTask has since been deprecated. Does anybody know an alternative?
Hey, I have the same problem. Have you found an answer yet :)
one alternative is Coroutines
Consider using the screen magnifier.
This is a great tutorial, I really like it. I tried the app and everything works, but I couldn't connect to the bluetooth device. The logcat says: couldn't connect
Do you know this problem and may know how I can fix it?
I am trying this tutorial several days ago but using a raspberry PI but does not work, anyway, many thanks for the usefull information!
Is this a new App or an addition to Part 1
Hi Richard, thanks for the comment. This video is a continuation from part one, both videos make one app
Good Tutorial
Great tutorial!!! . Can or have you done one on getting data from an Arduino back to Android device. ie sensor data etc??
Managed to get some code written up in Kotlin.... Thanks for your effort in making these videos. As a noob i reference them often
@@snowiethetoolguy i am trying to read data from arduino can you refer me to that code, thanks in advance
@@alaanasef5162 contact me at scroatsac@gmail.com .I'll forward you what i have..
Hi ! Can you tell us how you did it please ? i've written this code but in a loop but it the progress dialogue of the doInBackground function won't disapear :
fun checkReceive(){
if (m_bluetoothSocket != null) {
var input = m_bluetoothSocket!!.inputStream
var buffer: ByteArray = ByteArray(1024)
var bytes: Int
try {
bytes = input.read(buffer)
var incomingMessage = String(buffer, 0, bytes);
Toast.makeText(this, incomingMessage, Toast.LENGTH_SHORT).show()
} catch (e: IOException){
e.printStackTrace()
}
}
}
@@theoberessi6794 I've setup a background thread the looks for data received in the BT buffer and acts on that.. whats your email I'll send you some code snippets
Is there any possibility to display names of bluetooth devices instead of their MAC Addresses? Thanks in advance! :) (Btw great video!!!)
OK guys I've figured it by myself :)
Instead of ArrayList we can simpy use ArrayList and then we can add elements to our list by using "device.name".
Code:
val names : ArrayList = ArrayList()
if (m_pairedDevices.isNotEmpty()) {
for (device : BluetoothDevice in m_pairedDevices) {
names.add(device.name)
//Log.i("device", ""+device)
}
} else {
toast("No paired BT devices found...")
}
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, names)
If I'm wrong in this point please tell me - I'm not so experienced with android studio and Kotlin :)
@@ksaweryc I tried to replaced it like you did but the app crashed when i tried to connect to a device. It's because we use the object BluetoothDevice in the other activity, so instead i jest added your code with the alreading existing code :
val list : ArrayList = ArrayList()
val names : ArrayList = ArrayList()
if(m_pairedDevices.isNotEmpty()){
for(device: BluetoothDevice in m_pairedDevices){
list.add(device)
names.add(device.name)
Log.i("device", ""+device)
}
} else {
Toast.makeText(this, "No paired bluetooth devices found", Toast.LENGTH_SHORT).show()
}
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, names)
Thanks, it works!!!
HII .. I'm not sure, but I see too much code
why you make private the fun?
Hi Diego, thanks for the comment. The reason for making the functions private is because I didn't want other Classes/Activities from calling them. If there is a specific function that you want to know about please let us know.
ok ty
Thank you so much!
Where is the Arduino code?
Hi Shivam. We have added a link to where we got the Arduino code in the description.
Apps In The Sky thanks for the code! Though I have tried this code but it does not work if I change 1 and 0 with 'a' and 'b' in Arduino. So I made the app send 1 or 0 instead and it worked. Great tutorial man!👍
@@MrShivamgautam1 In my case even 1 and 0 doesn't work :(
OMG, we need 2 hours to create one simple BT app to start the LED! How meny we need to create calculator app? 22 days?
Too bad it didn't have a sequel. Getting data into Android.
If it only would work.
SOS for the morse code