Controlling Image Over Serial

asked 2014-03-18 10:46:26 -0500

pashakun gravatar image

I'm trying to manipulate an image in SimpleCV based on analog pressure sensor reading from Arduino via serial.

Can't get the values to come through, even though Arduino IDE serial monitor confirms the data is flowing.

I've scaled down my ambitions to this simple code -- adjusting a line's size depending on the reading:

from SimpleCV import *
import sys, time, serial

ser = serial.Serial('COM3', 9600)
disp = Display()
img = Image((1200, 800))

while disp.isNotDone():
  a = ser.readline()
  a = int(a)
  if not a:
    img.dl().line((100, 400), (110, 400), Color.WHITE, width = 80)
    img.drawText("No Reading", 170, 10, color=Color.BLUE, fontsize=40)
  else:
    img.dl().line((100, 400), (a, 400), Color.WHITE, width = 80)
    img.drawText(str(a), 170, 10, color=Color.BLUE, fontsize=40)

  print a
  img.save(disp)
  time.sleep(1)
  img.clearLayers()

Print continues to return 0, no change in image...

I know that the problem isn't

  • serial port -- running a simple readline>print show the numbers are coming across
  • baud rate -- Arduino and Python both set at 9600

Arduino code is

int flexiForcePin = A0; 

void setup(){
  Serial.begin(9600);
}
void loop(){
  int flexiForceReading = analogRead(flexiForcePin);
  Serial.println(flexiForceReading);
  delay (0.1);
  }

I realize that it's probably a simple code mistake befitting my noob level, but rummaging through StackOverflow forums didn't produce an answer.

Would greatly appreciate any help,

Thanks

edit retag flag offensive close merge delete