Connecting arduino to computer with wifi instead of usb - Page 1
Forum section: electronics / beginners

author: Capernicus
author_rank: Frequent Contributor
timestamp: October 18, 2021, 03:03:43 am
content: So you connect with the arduino using a COM port, to upload the sketch, and to communicate values to and from the computer.Uploading the sketch isnt a problem, because u can detatch the robot anyhow, but I would like to communicate to the pc whilst the unit is disconnected, with a wifi.I need to send camera data and motor positions to the computer, and send motor position changes to the unit.Is this easy to setup?

author: Capernicus
author_rank: Frequent Contributor
timestamp: October 18, 2021, 03:37:48 am
content: AH I see now!I just need to communicate through the COM port using this->https://www.codeproject.com/Questions/1116584/Reading-from-serial-port-using-C-in-visual-studioSo a wifi connection is just a COM port the same? Thanks I should be right...

author: ledtester
author_rank: Super Contributor
timestamp: October 18, 2021, 03:51:32 am
content: You will need either:1) a microcontroller that has a WiFi radio built into it -- like an ESP322) add a WiFi radio to your existing microcontroller boardCommunication over WiFi is very different and more complex than communicating over a serial port.Maybe look at this project:https://hackaday.io/project/163542-esp32-wifi-robot

author: Capernicus
author_rank: Frequent Contributor
timestamp: October 18, 2021, 04:21:41 am
content: I have an esp32.Oh thats a shame, I wished it was just the same as the COM port, would have been easier...I want to use my gpu for the Ai and get the performance boost, then just use the esp32 as a dummy terminal basicly.

author: BrokenYugo
author_rank: Super Contributor
timestamp: October 18, 2021, 04:36:42 am
content: Easier solution may be to do it over bluetooth, you can get little serial to bluetooth boards that just show up as a com port.

author: ledtester
author_rank: Super Contributor
timestamp: October 18, 2021, 04:49:30 am
content: Quote from: BrokenYugo on October 18, 2021, 04:36:42 amThat reminds me...Bluetooth RC Controller Interface / Blue-pill ARM -- 0033merhttps://youtu.be/Sjb6sinTHTs

author: Ian.M
author_rank: Super Contributor
timestamp: October 18, 2021, 05:41:14 am
content: That's reasonably simple to do with esp-link and an ESP8266 WiFi<>serial module (e.g. ESP-01):https://github.com/jeelabs/esp-linkUnder Linux, AVRDUDE can connect to a TCP/IP port over your LAN, so with a bit of config file hacking, its possible to add the remote esp-link to the Arduino IDE as a 'programmer' using the 'Arduino' protocol. Unfortunately under Windows, that functionality is borked, so you need some way of mapping a local COM port to a remote one over TCP/Ip as the 'secret sauce'.The easiest way I have found to do that without payware is using the com0com virtual null modem and its associated com2tcp utility.https://sourceforge.net/projects/com0com/Install com0com and also copy com2tcp.exe to its program folder.To connect a COM port to port 2323 of an esp-link TCP/IP<=>serial bridge available on the LAN as 'robot.lan', for use by AVRDUDE under the Arduino IDE1. Create a virtual port pair using com0com. The visible side of the pair should be called COMnn(set nn to your preference, I suggest a fairly high number so it doesn't conflict with real hardware ports), and have 'emulate baud rate' and 'enable plug-in mode' checked. The hidden side of the pair can be called ROBOT, and have 'emulate baud rate' and 'enable hidden mode ' checked, so that when it is opened the visible side appears.2. Create a shortcurt to com2tcp.exe called 'Connect to robot', to run minimized:Code:"C:\Program Files (x86)\com0com\com2tcp.exe" --baud 115200 \\.\ROBOT robot.lan 2323Change 'robot.lan' and the baud rate to match esp-link settings and whatever LAN suffix your router uses. Do not change the port 2323 as that signals esp-link to reset the target when it is opened (required for AVRDUDE <> bootloader sync).3. When you start the 'Connect to robot' com2tcp utility, COMnn appears and can be used by the Arduino IDE for programming, and by its terminal utility as-if the Arduino was hard-wired. When you close com2tcp, COMnn goes away. If it doesn't stay open there's probably an issue with your robot's wifi connectivity - run it from a console with the above command line and look at the error messages.

author: rstofer
author_rank: Super Contributor
timestamp: October 18, 2021, 04:44:06 pm
content: All you need on the PC end is a bit of code to implement a Berkeley Socket as a server. Open the socket on some agreed port number and listen for a connection. The PC is the server and responds to packets from the client.On the robot end, you need to write a bit of code to connect to the PC server using Berkeley Sockets (TCP) as a client. Then you can talk back and forth as long as you want.I have done the client/server thing in a similar way when I wanted to use my Linux workstation as an HP printer so I could see what HPGL strings I was sending from a project MCU. It was trivial! The client didn't even know whether it was talking to the workstation or the printer. The only change in code was the IP address.Whether it is 'easy' depends on your platform. Under Linux, sockets are easy to use but they don't exactly end up as a /dev/tty... The server code needs to interact with whatever the client sends so there needs to be some agreed protocol. You can find elementary client and server C code on the web.In Windows, it should be possible to use VB.NET to work as a server. Here is a tutorial:http://vb.net-informations.com/communications/vb.net_socket_programming.htmDepending on your needs, you can have several servers running on a host. One might be waiting for camera images, another might want to know about position and speed. Even another might want to know about other sensors. This all depends on the client (the robot) end being able to handle more than one connection. I don't know the answer to that.http://www.iotsharing.com/2017/05/tcp-udp-ip-with-esp32.html

author: rstofer
author_rank: Super Contributor
timestamp: October 18, 2021, 04:48:28 pm
content: You can turn the socket strategy around and make the robot the server and the PC the client. This allows a connection with something like puTTY using a 'Raw' connection. Again, it might be desirable to open a multitude of server sockets.https://documentation.help/PuTTY/using-rawprot.html

author: rstofer
author_rank: Super Contributor
timestamp: October 18, 2021, 09:04:10 pm
content: Here's a nice tutorial that is easiest to work on in *nix.https://www.binarytides.com/socket-programming-c-linux-tutorial/There is even a section on multiple clients connecting to a single server running in separate threads.The Berkeley Sockets API is truly easy to use. How well it is implemented on an ESP32 is not known to me. If it is based on lwIP, it should be quite good.I was using an LPC1768 MBED board as a client to connect with the print server inside my LaserJet...https://os.mbed.com/platforms/mbed-LPC1768/You can use Windows but I haven't tried ithttps://docs.microsoft.com/en-us/cpp/mfc/windows-sockets-background?view=msvc-160

author: Capernicus
author_rank: Frequent Contributor
timestamp: October 19, 2021, 01:08:06 am
content: Thanks rstofer for the advice. Its a bit of networking code, The most data I have to send is the camera pixel data, the rest of the data send is 1% compared to that, If I end with some UART emulator thing, maybe it wont support very high resolution, but low res will do fine, Not sure what I'll use yet, but its just a bit of networking code, I should be able to handle it, thanks alot!