Sample Python code using vex.Serial?

Hi,

I am trying to use the Vex EDR serial port (UART2) to talk to a Jevois camera.

So far I have not been able to read any data through the serial port.

Do you have any sample Python code using vex.Serial that you know works?

Thanks.

I have used PROS and ROBOTC with the UART ports but not Robot Mesh Studio. @RobotMesh @RobotMesh_Support are the people who might be able to help. Do you want to share your existing basic code so people can point you in the right direction?

Sure. Here is my code so far. It shows “Awaiting data…” and then does not change.

#VEX Cortex Python-Project
import vex
import sys

#region config
lcd = vex.LcdDisplay()
jevois = vex.Serial(vex.SerialParam.PORT_UART2, 115200)
#endregion config

# Make sure the jevois camera is attached to UART2 on the VEX Cortex
lcd.write_top("Awaiting data...")
while True:
  data = jevois.read_bytes(1) # this will block until it gets 1 byte of data
  lcd.write_bottom(data)
  print data
  lcd.write_top("jevois data:")
  sys.sleep(10) # wait 10 seconds so you can read the LCD script

You might try UART1 instead of UART2, I’m not sure which port the Cortex uses to send


print

s back to the host. It also might not play well with a LCD display on the other UART port. Also try selecting “Download: build the program and download only” from the dropdown under the Play button, this just downloads the program without opening a debug channel.

Here’s some serial code I wrote a couple years ago for the Pixy camera. It uses read_byte instead of read_bytes because I had to do a bunch of bit-shuffling on the 16-bit LSB uints the Pixy transmits. It runs the serial channel at 38400 bps, since the Cortex wasn’t fast enough to keep up at 115200.

https://www.robotmesh.com/studio/948