Alright everything’s alright … until i realised how json worked ; i wasn’t famliar with this library so actually i get a string chain of like ‘[29 , 128]’ (this is just an example of coordinates) and if i convert it as a tuple i get a long stringle tuple of each characters, i’ve been trying hard to get it as an integer tuple : (29, 128) in the receiver program, and the only idea i came up with is a for loop looking one by one each character of the long tuple but that is kind of hideous, is there anyway to directly send a tuple ? Here are the programs:
Micro python OpenMV cam:
import sensor, image, time, pyb, ujson
from pyb import USB_VCP
usb = USB_VCP()
red_led = pyb.LED(1)
green_led = pyb.LED(2)
blue_led = pyb.LED(3)
ir_leds = pyb.LED(4)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
seuils_Lab = (60, 85, 18, 50, 30, 70) # seuil de la couleur balle
while True:
a=0
n=0
data = {}
img=sensor.snapshot()
blobs = img.find_blobs([seuils_Lab])
red_led.on()
green_led.off()
if blobs:
for b in blobs:
if b.pixels()>>a:
a=b.pixels()
n=b
tmp=img.draw_rectangle(n[0:4])
c=(n[5],n[6])
data = ujson.dumps(c) #création du fichier micro json avec la variable que tu veux envoyer, en argument
usb.send(data) #envoie de la variable
tmp=img.draw_cross(n[5], n[6])
red_led.off()
green_led.on()
ANd receiver program :
import serial, sys,json, time
import serial.tools.list_ports as ports
port = '/dev/ttyACM1/'
for device_name in ports.comports():
if 'OpenMV' in str(device_name):
port = device_name.device
sp = serial.Serial(port, baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE,xonxoff=False, rtscts=False, stopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=False)
if sp.isOpen() == True:
sp.setDTR(True)
time.sleep(0.5)
data = sp.read(sp.inWaiting()).decode('utf-8')
print(data)
sys.stdout.flush()