Bi-Directional communication between a pc / Pi Questions

Hi all, so I am fairly new to the Cortex but have a good experience with IQ, EV3, and am a mobile developer. I want to take my building to the next level and so I thought the Cortex would be the best way to do it. I want to start using the Microsoft Kinect / Lidar with it and looking at what the best solutions are. Both would involve a host (Raspberry Pi or PC) but what’s the best way to exchange data between them? What programming language would you suggest.

I have connected a Android tablet to a Cortex, I know RobotC well (ish) via BT (wiring in one on the Cortex)
I know both the Lidar and Kinect have Python drivers.

Has someone got Python (Host) talking to a Cortex (I guess running RobotC)? I have EDR hardware programming kit

I had a python program talking over BT to a cortex running RobotC (with hc-05). Was part of this project

I had my laptop visualize the lidar data in python and then show the robots location and draw large circles everywhere a ball was computed to be. I did all of calculations on board the cortex but with the sheer amount of data coming out of the kinect you will definitely need to do processing on your host machine.

Oh boy thats epic, I am using the same Lidar The Lidar is working :) - YouTube

Did you github any of it, I have a RobotC example to show how it read BT I think, maybe send to but wont have the Python side.

For the python part my partner and I started with this XV-11 python program and then heavily modified it.

Making it work over BT is actually incredibly easy. Your current program should work assuming you change the com port to the port of your computer’s BT chip. The lidar can be read quite easily through UART like you do with your Arduino mega. A ROBOTC program like this to read data in from 1 UART out another is pretty simple. This program was used whenever we wanted to visualize the raw data. A little note is to pay attention to the data != 0xFF because ROBOTC doesn’t have a way of checking the contents of the UART buffer other than grabbing the byte, 0xFF is returned whenever the buffer is empty.

#pragma config(UART_Usage, UART1, uartUserControl, baudRate115200, IOPins, None, None)
#pragma config(UART_Usage, UART2, uartUserControl, baudRate250000, IOPins, None, None)
#pragma config(Motor,  port1,           lidarMotor,    tmotorNone, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
	setBaudRate(UART1, baudRate115200);
	setBaudRate(UART2, baudRate250000);
	char data = getChar(UART2);
		if(data != 0xFF)

Actually all of code is on github and I would totally be willing to release it if it were not for the just sheer amount of inappropriate jokes and comments through out the code. Just skimming I came across “Added findBalls to find balls deep in the sweaty pants of vex u nerds…” as a commit message.(facepalm) I would be willing to throw all the lidar code into a new repository and add you if you would like.(there is a lot of non lidar code in the current repo and it would just be a mess for you to try to sort through it)

edit: if a mod would like to remove the inappropriate sentence feel free. I know it is at best towing the line.

Thanks for another awesome reply. I already have the Lidar up and running and can modify the python code to do whatever I need for it to.

It seems I assumed wrongly that the Hardware dev usb thing was the way to go. Programming Hardware Kit - VEX Robotics

The code I really could do with is the PC side of the uart communication but I am guessing that is fairly ok to work out (I have it in Android).

Does seem weird they never did a easy way to do it, I know its not needed for the comp etc, but EDR would be a epic research platform

So the python side doesn’t need to change other than the com port. It’s all just serial. You need to figure out which com port is BT chip and then connect as you would connect any BT device and then start the python program. Not sure how much electrical computer engineering education you have and James(@jpearman) would explain it better but here it goes
USB - universal serial bus
UART - asynchronous serial communication
Serial just means sending all the data over a single transmit data line and a single receive line. The arduino mega has several UART busses and 1 of them is wired to a USB port but has no hardware differences to the other ones. So when you are connected currently it is the same as if you had used a BT chip attached to a different UART and printed using Serial2 or Serial 3. The cortex is the same way except getting the main usb connection is difficult to access so you have to use one of the other UARTs.

The issue is that the official wireless debugging tool has no current way to get the data to an external program. If ROBOTC had a way to send all debug print statements out a virtual com port it would be best. The live debugger sending over all the global variables and motor values makes it hard to try to intercept the data using your own program instead. (no one has ever tried but it could be interesting)

Thanks, I think I know what to do now, I probably did not explain myself correctly but your help is awesome.

I am sure there is plenty out there to show me how to receive BT data in Python. I have done tons of BT on Android etc. I will probably give it a go tonight. Test the Android to -Cortext connection, then rewrite the Android code in Python for the PC. If you ever get time, I would still love to see your project code (jokes and all)

The only line you need to change on your Github python program is

com_port = ‘/dev/tty.usbmodem14131’

It fundamently communicates the same as your wired usb connection. Maybe I am missunderstanding what code you want to currently get working wirelessly.

This may explain more mate python 3.x - Serial communications between PySerial and VEX EDR Cortex - Stack Overflow

Solved this, thank you :slight_smile: