Think thatĭata = "XZ".format( int(xx), int(yy) ) You make things easier when formatting data in raspberry side in the format needed on microcontroller side. Data on arduino side are obviously expected as integer. Here you can convert by adding the encode-method of the string class.ĭata formatting.
Writing to serial needs a bytes like object. The TypeError is thrown as you pass a string object to the arduino.write method. There are multiple places where things could be improved. If(posy <= 175)posy -= distancey //Update the tilt position variable to raise the tilt servo. Find out if the Y component of the face is above the middle of the screen.
If(posx = 5)posy += distancey //If it is below the middle of the screen, update the tilt position variable to lower the tilt servo. Find out if the X component of the face is to the right of the middle of the screen. If(valx = incx ) posx += distancex //Update the pan position variable to move the servo to the left. Find out if the X component of the face is to the left of the middle of the screen. While(Serial.available() = 4) // wait for 4 bytes. PinMode(servopiny,OUTPUT) // declare the LED's pin as output PinMode(servopinx,OUTPUT) // declare the LED's pin as output Serial.println("Starting Cam-servo Face tracker") Serial.begin(baudrate) // connect to the serial port Int XY = 0 //to build 2 byte integer from serial in byte Short Y = 0 // to build 2 byte integer from serial in byte Short X = 0 // to build 2 byte integer from serial in byte Int incy = 10 // significant increments of vertical (y) camera movement Int incx = 10 // significant increments of horizontal (x) camera movement Int valy = 0 // store y data from serial port Int valx = 0 // store x data from serial port #define distancey 1 // y servo rotation steps #define distancex 1 // x servo rotation steps #define servopiny 10 // digital servo for pin y
#define servopinx 9 // digital pin for servo x
#define servocentery 60 // center po#define of y servo #define servocenterx 85 // center po#define of x servo
#define screenmaxy 240 // max screen vertical (y) resolution #define screenmaxx 320 // max screen horizontal (x)resolution #define servomaxy 180 // max degree servo vertical (y) can turn #define servomaxx 180 // max degree servo horizontal (x) can turn Print("Center of Rectangle is :", center)