Arduino Nano Or MKR 1010 Bluetooth Or WiFi Communication ... - B4X

B4X Programming Forum
  • Home
  • Products B4A B4i B4J B4R
  • Showcase
  • Store
  • Learn General Guides Video Tutorials Glossary
  • Teach
  • Blog
  • Forums #B4X Discord (unofficial) B4X Facebook Group Github Repository
  • New posts What's new New profile posts Latest activity
  • Members Current visitors New profile posts Search profile posts
Log in Register What's new
  • #B4X Discord (unofficial)
  • B4X Facebook Group
  • Github Repository
Menu Log in Register Install the app Install
  • Welcome to B4X forum! B4X is a set of simple and powerful cross platform RAD tools:
    • B4A (free) - Android development
    • B4J (free) - Desktop and Server development
    • B4i - iOS development
    • B4R (free) - Arduino, ESP8266 and ESP32 development
    All developers, with any skill level, are welcome to join the B4X community.
  • Home
  • Forums
  • B4R - Arduino, ESP8266 and ESP32
  • B4R Questions
You are using an out of date browser. It may not display this or other websites correctly.You should upgrade or use an alternative browser. B4R QuestionArduino Nano or MKR 1010 Bluetooth or WiFi Communication to B4A App or B4J App
  • Thread starter Guardian17
  • Start date Feb 18, 2022
  • Similar Threads Similar Threads
Guardian17

Guardian17

Active Member
Licensed User Longtime User I tried this on the B4A Forum, with no responses. Thought I'd move it here for any Arduino Users in case it was missed over there. Has anyone made any B4A/B4J application that can receive data and/or talk to one of the more recent Arduino boards, like the Arduino Nano 33 IoT, or MKR WiFi 1010, that use the u-blox NINA-W10? These Arduino boards use the WiFiNINA library for Bluetooth and WiFi. I'm interested in the Arduino taking garden watering measurements, storing them in an EEPROM-type device, and then transmitting/dumping the memory data upon a request from the B4A App on my smartphone, or to my Windows laptop. I'm already working on the Arduino application to control the garden watering and taking/storing sensor data, but the communications via WiFi or Bluetooth to my smartphone still eludes me. And I'm interested in talking directly via Bluetooth or WiFi, not via the IoT Cloud. Last edited: Feb 23, 2022 Sort by date Sort by votes K

KiloBravo

Active Member
Licensed User What about this ?

HC 05 Classic Bluetooth

In this example we will connect an Android device to an Arduino using class Bluetooth with the HC 05 module. Working with this module is simple. Connect the power and gnd pins and connect the HC05 RX pin to an Arduino TX pin and the HC05 TX pin to an Arduino RX pin. The HC05 RX pin expects 3.3... www.b4x.com www.b4x.com You should be able to port it to something else. Upvote 0 f0raster0

f0raster0

Well-Known Member
Licensed User Longtime User
Guardian17 said: I tried this on the B4A Forum, with no responses. Thought I'd move it here for any Arduino Users in case it was missed over there. Has anyone made any B4A application that can receive data and/or talk to one of the more recent Arduino boards, like the Arduino Nano 33 IoT, or MKR WiFi 1010, that use the u-blox NINA-W10? These Arduino boards use the WiFiNINA library for Bluetooth and WiFi. I'm interested in the Arduino taking garden watering measurements, storing them in an EEPROM-type device, and then transmitting/dumping the memory data upon a request from the B4A App on my smartphone. I'm already working on the Arduino application to control the garden watering and taking/storing sensor data, but the communications via WiFi or Bluetooth to my smartphone still eludes me. If the Arduino can talk to my Windows laptop through Bluetooth or WiFi, that would also be acceptable. And I'm interested in talking directly via Bluetooth or WiFi, not via the IoT Cloud. Click to expand...
I haven't used them.. those modules probably will work. This days they are developing hardware to talk to phones. you say "..still elude me." What is the problem that you have between your hardware and phone in your current system? In my jarden to see data and control pumps I have a website using the ESP8266 (nothing more) I'm having issues with the soil sensors - could i ask which one are you using? Last edited: Feb 18, 2022 -- Electronic IoT Bluetooth BLE Projects - We make it simple! Upvote 0 Guardian17

Guardian17

Active Member
Licensed User Longtime User
f0raster0 said: I haven't used them.. those modules probably will work. This days they are developing hardware to talk to phones. you say "..still elude me." What is the problem that you have between your hardware and phone in your current system? In my jarden to see data and control pumps I have a website using the ESP8266 (nothing more) I'm having issues with the soil sensors - could i ask which one are you using? Click to expand...
My garden project is still getting off the ground, but I believe capacitive sensors are better than resistive sensors. The moisture sensor I am planning to use is made by STEMMA. Here is a link: www.adafruit.com

Adafruit STEMMA Soil Sensor - I2C Capacitive Moisture Sensor

Most low cost soil sensors are resistive style, where there's two prongs and the sensor measures the conductivity between the two. These work OK at first, but eventually start to oxidize ... www.adafruit.com www.adafruit.com Although I have verified that I can obtain readings over i2c, I have not yet placed anything in my garden to see how well they work ... this will be my first year to implement anything like this. If you have tried these STEMMA sensors and have any feedback, please let me know. In regards to the "...still eludes me", I have only seen examples where one device allows turning an LED ON that's on another device. I am more interested in seeing examples of actual byte/data transfer over Bluetooth or WiFi. My anticipated project has a 32Kx8 FerroRAM i2c device, (which will save data on moisture readings, temperature, control solenoid on/off times (gravity-feed watering), and tank level sensor (time-of-flight sensor)), and I want to be able to dump the memory from time to time to analyze whether any improvements are needed in my watering cycles. Yes, I could arrange to hook up to the USB port to do the memory dump via the Serial Monitor, but it would be less arduous if I can access the data wirelessly. Last edited: Feb 23, 2022 Upvote 0 Guardian17

Guardian17

Active Member
Licensed User Longtime User
KiloBravo said: What about this ?

HC 05 Classic Bluetooth

In this example we will connect an Android device to an Arduino using class Bluetooth with the HC 05 module. Working with this module is simple. Connect the power and gnd pins and connect the HC05 RX pin to an Arduino TX pin and the HC05 TX pin to an Arduino RX pin. The HC05 RX pin expects 3.3... www.b4x.com www.b4x.com You should be able to port it to something else. Click to expand...
Thanks for the feedback. I had seen several of these posts (as well as YouTube videos), but I have yet to look into them extensively, and I think these may be outdated (May of 2016) compared to the Nano 33 IoT and/or MKR WiFi 1010, which use the u-blox NINA-W10 module and the WiFiNINA library for Bluetooth and WiFi. I am also interested in actual byte/data transfer between the Arduino board and my smartphone or laptop, not just turning an LED on/off. Last edited: Feb 23, 2022 Upvote 0 K

KiloBravo

Active Member
Licensed User I have code taken from the forum examples that can send data back and forth from an ESP32 or ESP8266 to a PC or Phone. I usually use B4R code and an ESP board to send and receive data to my PC running a B4J program. Two examples I have gotten to work are 1.) use the WIFI network in your home or 2.) use the ESP as a WIFI Server connect your PC to that "server" and then receive the data to the B4j program. Erel's MQTT example also works very well. Here is link to one of Erel's Projects that works ...

ESP8266 + UDP + BMP180 = Simple weather station

This is an example of how UDP can be used to broadcast the current temperature and pressure to one or more clients. The nice thing about it is that there is no server involved. The ESP8266 just sends the packets to the broadcast address. RandomAccessFile is used to create the packets. B4R... www.b4x.com www.b4x.com I do not know anything about those boards, but an esp8266 or esp32 can easily be used for I2c comms and TCP/UDP. I can post a short example of a B4R program and a B4j program that can send and recevieve data in both directions. The B4R program reads a WII Nunchuck over I2c and sends the button and joystick position to the B4J program. The B4J program then changes the data and sends it back. If that would help let me know and I will post the code. Upvote 0 K

KiloBravo

Active Member
Licensed User Yesterday I wrote some code for a B4J app to talk back and forth over UDP to an ESP32. The ESP32 module reads the two positions and the button from a KY-023 Joystick. Peter Simpson wrote this post on it and I borrowed his code.

Reading KY-023 dual-axis XY joystick

SubName: Reading an KY-023 joystick Description: You can use this simple code to read the position of a KY-023 dual-axis joystick. At its centre point the joystick readings are around 512, moving the joystick up/down/left/right will change the resistance values either higher until it reaches... www.b4x.com www.b4x.com B4J is running on Win10 PC it is the Client. ESP32 is the Server. (wifi.StartAccessPoint("esp32_Base") Fire up B4R and connect to the ESP32 module over USB. <<< this is just to see the messages in the log. It can run standalone from a USB power block. On your PC disconnect from your router and connect to esp32_Base. Fire up the B4J Program and then send data back and forth. Upvote 0 K

KiloBravo

Active Member
Licensed User B4J_B4R_UDP.gif Upvote 1 K

KiloBravo

Active Member
Licensed User B4J code. Just a quick hack cobbled together from examples on the forum. It should be relatively easy to follow the excellent tutorials on (B4X Pages) making it a B4X cross platform app for B4J, B4A, and B4I. B4J UDP App: #Region Project Attributes #MainFormWidth: 600 #MainFormHeight: 600 #End Region Sub Process_Globals Private fx As JFX Private MainForm As Form Private xui As XUI Private Button1 As B4XView ''' Private usocket As UDPSocket Private bc As ByteConverter Private serz As B4RSerializator Private TextArea1 As B4XView Private IPcon As String = "222.111.7.10" Private portCon As Int = 55777 Private Button2 As B4XView Private TextArea3 As B4XView Private Label1 As B4XView Private Label2 As B4XView Private Button3 As B4XView End Sub Sub AppStart (Form1 As Form, Args() As String) MainForm = Form1 MainForm.RootPane.LoadLayout("Layout1") MainForm.Show usocket.Initialize2("UDP", portCon, 1024, True, False) 'reuse is set to true serz.Initialize End Sub Sub Button1_Click ' Send Data To ESP32 Button TextArea3.SelectAll If TextArea3.SelectionLength = 0 Then TextArea3.Text = "Nothing To Send" Else build_Packet ' Build and Send the Packet over UDP End If End Sub Sub Button2_Click ' Clear Recieve Data Button TextArea1.Text = "" End Sub Private Sub Button3_Click ' Clear Sent Data Button TextArea3.Text = "" End Sub Sub build_Packet ' Dim mySTR() As String = Regex.Split(" ",TextArea3.Text) Dim send_data () As Object = mySTR UDP_SendPacket(serz.ConvertArrayToBytes(send_data)) TextArea3.Text = "" TextArea3.Text = "Data Was Sent" ' ' Old Code just sends a predefined array of data ' ' Dim pktStart As Object = "<" ' Dim x As Object = Rnd(0,255) ' Dim y As Object = Rnd(0,255) ' Dim some_string As Object = "string" ' Dim pktEnd As Object = ">" ' Dim send_data(5) As Object ' send_data(0) = pktStart ' send_data(1) = x ' send_data(2) = y ' send_data(3) = some_string ' send_data(4) = pktEnd ' UDP_SendPacket(serz.ConvertArrayToBytes(send_data)) ' TextArea3.Text = "" ' TextArea3.Text = "Data Was Sent" End Sub Sub UDP_SendPacket (xmit_data() As Byte) Dim Packet As UDPPacket Packet.Initialize(xmit_data, IPcon, portCon) usocket.Send(Packet) Log("Packet Sent") Log($"IPcon: ${IPcon}"$) Log($"portCon: ${portCon}"$) End Sub Sub UDP_PacketArrived (Packet As UDPPacket) Log($"Packet.Length: ${Packet.Length}"$) Log($"Packet.Data.Length: ${Packet.Data.Length}"$) Log("Packet Arrived") Log($"Packet IP: ${Packet.HostAddress}"$) Log($"Packet Port: ${Packet.Port}"$) Dim data() As Byte = Packet.Data Log($"Packet.Data ${Packet.Data}"$) If Packet.Data.Length > Packet.Length Then Dim data(Packet.Length) As Byte bc.ArrayCopy(Packet.Data, 0, data, 0, Packet.Length) End If Dim rcvd_data() As Object = serz.ConvertBytesToArray(data) ''' Private serz As B4RSerializator TextArea1.Text = "" For Each o As Object In rcvd_data Log($"${o}"$) TextArea1.Text = TextArea1.Text & o & CRLF Next End Sub Upvote 0 K

KiloBravo

Active Member
Licensed User B4R ESP32 Server Code for UDP xmit & receive. B4R UDP Server App: #Region Project Attributes #AutoFlushLogs: True #CheckArrayBounds: True #StackBufferSize: 600 #End Region 'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src Sub Process_Globals Public Serial1 As Serial Private esp As ESP32extras Private wifi As ESP8266WiFi Private udp As WiFiUDP Public bc As ByteConverter Public ser As B4RSerializator Private js_timer As Timer Private btn_timer As Timer Public cntr As Int = 0 ''''''''''''''''''''''''''''''''''''''''' Public myIP As String = "222.111.7.10" Public myGateway As String = "222.111.7.10" Public mySubnet As String = "255.255.255.0" Private Switch, VRx, VRy As Pin End Sub Private Sub AppStart Serial1.Initialize(115200) Log("AppStart") '***************************************** esp.ConfigAP(myIP, myGateway, mySubnet) wifi.StartAccessPoint("esp32_Base") Log(wifi.AccessPointIp) Log(wifi.LocalIp) '********* Switch.Initialize(33, Switch.MODE_INPUT_PULLUP) ' ESP32 Pin 33 (Joystick Button) VRx.Initialize(35, VRx.MODE_INPUT) ' ESP32 Pin 35 VRy.Initialize(34, VRy.MODE_INPUT) ' ESP32 Pin 34 ' js_timer.Initialize("ReadJoystick", 500) js_timer.Enabled = True 'don't forget to enable it ' btn_timer.Initialize("ReadButton", 500) btn_timer.Enabled = True 'don't forget to enable it '********* Log("Socket Init and Listening") udp.Initialize(55777, "udp_PacketArrived") End Sub Sub ReadButton Dim B_State As Boolean B_State = Switch.DigitalRead If Not(B_State) Then ' Button Pushed Down is Zero Dim xmit_Data() As Object = Array As Object (0,0,0) xmit_Data (0) = "ESP32" xmit_Data(1) = "Test" xmit_Data(2) = "Packet" Send_Packet(xmit_Data) End If End Sub Sub ReadJoystick Dim X As Int = 0 Dim Y As Int = 0 Dim B_State As Boolean X = VRx.AnalogRead Y = VRy.AnalogRead B_State = Switch.DigitalRead ' Log("X: ", X) ' Log("Y: ", Y) ' Log("B_State: ", B_State) Dim xmit_Data() As Object = Array As Object (0,0,0) xmit_Data(0) = B_State xmit_Data(1) = X xmit_Data(2) = Y '********************** ' Check X/Y Values High or Low to make sure Joystick has been moved If ((X < 1300) Or (X > 2400)) Then Send_Packet(xmit_Data) Else If ((Y < 1300) Or (Y > 2400)) Then Send_Packet(xmit_Data) End If End Sub Sub Udp_PacketArrived (Buffer() As Byte, Ip() As Byte, Port As UInt) Log("PacketArrived: ", Buffer.Length) Log("IP: ",Ip(0),".",Ip(1),".",Ip(2),".",Ip(3)) Log("Port: ",Port) If Buffer.Length = 0 Then Log("Packet Length 0 ") Return 'invalid message End If If Buffer.Length > 50 Then Log("Packet Length > 50") Return 'invalid message End If '******************************************************************************** Dim be(50) As Object 'used as a storage buffer. Can be a global variable Dim Data() As Object = ser.ConvertBytesToArray(Buffer, be) '******************************************************************************** For Each o As Object In Data Log("Data: ", o) Next cntr = cntr + 1 Log("Counter: ", cntr) Data(0) = cntr End Sub Sub Send_Packet(xmit_Data()As Object) '********************************************************************** '''' IP/Port of Client "222.111.7.100" --- "55777"''''''''''''''''''''' '********************************************************************** Private ip() As Byte = Array As Byte(222,111,7,11) Private port As UInt = 55777 udp.BeginPacket(ip, port) udp.Write(ser.ConvertArrayToBytes(xmit_Data)) udp.SendPacket Log("SentPckt: ",xmit_Data(0)," ",xmit_Data(1)," ",xmit_Data(2)) End Sub Upvote 0 K

KiloBravo

Active Member
Licensed User I attached a zip of the B4J Project. The B4R Bin was 33 meg, so I did not zip the B4R Project, but you have the source code and libraries I used. B4R_Libs.PNG

Attachments

  • !B4J_UDP.zip 115.8 KB · Views: 401
Upvote 0 K

KiloBravo

Active Member
Licensed User As I said, this is just a quick hack but the code works and should get you started for whatever you want to do. I have plenty of LOG statements in both programs, so hopefully the logic/code is easy to follow. Erel and other's on the forum have posted plenty of great examples of various communication methods. Upvote 0 K

KiloBravo

Active Member
Licensed User If you have issues connecting from the PC it might be a firewall issue. You may have to open the ports for UDP comms. WireShark is great for diagnosing this as well as IP/TCP/UDP and Bluetooth issues. for I2C I found the port scanner handy.

I2C Address Scanner

Snippet to scan for I2C (Inter-Integrated Circuit) devices. Helpful to obtain the connected I2C device(s) address. The address range is 0 and 127. Reference. Libraries: rWire, rRandomAccessFile Example output Scanning started... I2C device found at address: 0x76 (118) Scanning completed... www.b4x.com www.b4x.com I hacked the I2C on a WII Nunchuk with code written by Robert Eisele. The URL is listed in my source code in the post below.

Read a Nunchuk using I2C with B4R an ESP8266

Nothing spectacular the code just reads and logs the joystick x & y axis, the 2 buttons (Z&C), the 3 axis accelerometer data, as well as the calibration data. It works on the OEMs and Knock Offs if you lower the clock speed as indicated. I just ported some Arduino Code to B4R from the website... www.b4x.com www.b4x.com Upvote 0 K

KiloBravo

Active Member
Licensed User I sometimes use an old router (not on the internet) and connect both devices to that for communications. You can set it up to only allow connections from predefined device MAC Addresses. Upvote 0 Guardian17

Guardian17

Active Member
Licensed User Longtime User
KiloBravo said: I sometimes use an old router (not on the internet) and connect both devices to that for communications. You can set it up to only allow connections from predefined device MAC Addresses. Click to expand...
WOW! I just looked again at this thread and saw all of your posts!! Thank you for all of your responses!! I will probably get to looking at these over this weekend. THANKS AGAIN! Upvote 0 K

KiloBravo

Active Member
Licensed User I am just trying to pay it forward a little. Lots of folks on the forum have been very generous with their time helping me out. The video tutorials are great as well as the booklets. I strongly suggest using B4X Pages. The learning curve is a little steeper in the beginning but making a project cross compatible between B4A, B4J, and B4I with 90% code reuse is definitely worth it. IMHO! If you run into issues start a new post with specific details, any error messages, and a small code sample to reproduce the error. (Don't forget to use code code tags.) I will try and help out when and where I can. Upvote 0 You must log in or register to reply here.

Similar Threads

hatzisn
  • Article
B4R Code Snippet Benchmark of Microcontrollers
  • hatzisn
  • Dec 5, 2022
  • B4R Code Snippets
Replies 0 Views 2K Dec 5, 2022 hatzisn hatzisn aeric
  • Article
B4R Tutorial Glossary for Arduino Development
  • aeric
  • Apr 4, 2022
  • B4R Tutorials
Replies 2 Views 4K Apr 6, 2022 aeric aeric Tronak
  • Question
B4R Question Arduino MKR WiFi 1010... Hating it. Help please.
  • Tronak
  • Dec 1, 2019
  • B4R Questions
Replies 3 Views 4K Dec 2, 2019 Erel Erel Roger C
  • Question
B4R Question Uno with internet modules (ESP-01Wifi or Ethernet LAN)
  • Roger C
  • Apr 4, 2019
  • B4R Questions
Replies 6 Views 5K Apr 7, 2019 Erel Erel johnf2013
  • Question
B4R Question Simple interrupt in B4R
  • johnf2013
  • Jan 12, 2018
  • B4R Questions
Replies 6 Views 5K Aug 4, 2020 KiloBravo K Share: Facebook Twitter Reddit Pinterest Tumblr WhatsApp Email Share Link
  • Home
  • Forums
  • B4R - Arduino, ESP8266 and ESP32
  • B4R Questions
  • This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register. By continuing to use this site, you are consenting to our use of cookies. Accept Learn more…
Top

Tag » Arduino Mkr1010 Ble