0

In Python I've made a script to read pointers of a game, it reads and output the data through the python console. Now i'm trying to send that data to an Arduino and move a servomotor similar to a speedometer.

The problem that i've got is the servomotor is not moving correctly when it's receive the data from python. Sometimes it's stucks, sometimes it's not responding. Kinda weird because i've tried to move manually a servomotor from python to arduino and it responds, but with 0.5 sec of delay, and even i tried with a LED, it responds instantly.

Here's the code of the Arduino

#include <Servo.h>

int angulo = 0;
Servo miServo;

void setup() {
  miServo.attach(3);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available() > 0)
  {
    angulo=Serial.parseInt();
    angulo=constrain(angulo,0,180);
  }
  miServo.write(angulo);
}

And this is the code that i've execute from python

# memreading it's from a module that i've created
import memreading, serial

# PLANTILLA
###################################################
proceso = 'or2006c2c.exe'
velocidad = 0x07806A4

# CODIGO COMUNICACION SERIAL
###################################################   
ser = serial.Serial('COM3', 9600)

# CODIGO LECTURA DE MEMORIA
###################################################
mem = memreading.MemReading()

processHandle = mem.openProcess(mem.attachToProcess(proceso))

def lecturaMemoria():
    data = mem.readMemory(processHandle, velocidad)
    data = int(float(data)/1.59)
    return str(data)

while True:
    try:
        ser.open()
        dato = lecturaMemoria()
        print dato
        ser.write(dato)
    except KeyboardInterrupt:
        ser.close()
        break

Here is the code to read in memory https://gist.github.com/PPastene/f955a80abc55964733accc9d9133b488

I'm not gonna explain that code, but the data returns as string from mem.readMemory() function. It's parsed to integer because it need a calculation for then parsed again to string (I can't put a integer value in a loop, python gives an error because integer objects are not iterable)

0 Answers0