Manipulating Image in SimpleCV Over PySerial

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 -- Arduino serial monitor shows data; running just readline>print in Python also shows 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 I haven't had any luck attracting attention on SimpleCV forum. StackOverflow posts on serial got me this far.

Would greatly appreciate any help,

Thanks

delay(0.1) does not work as it needs a unsigned long, not a float. it will be delay(0) effectively.

Can you make a simple receiving program that just shows it receives something?
I see you do a readline in python without testing if something is available?

Many thanks for the response.

And thank you for pointing that out. But I've played with different delay settings before - all to no avail.
So I flashed Arduino again, changing to delay (1) .

Then ran this code in Python

from SimpleCV import *
import sys, time, serial

ser = serial.Serial(port = 'COM3', baudrate = 9600)

while True:
	try:
	 t1 = ser.readline()
	 
	 print int(t1)
	 
	except KeyboardInterrupt:
	 print 'exiting'
	 break

ser.flush()
ser.close()

The command prompt was showing 0s when the sensor was left alone and climbed to as much as 800+ when I pressed on it.
This was in-line with what I would see on Arduino's serial monitor and just as responsive.

Again, thank you for helping out.

Tried a few new things

a) made sure the serial is delivering numbers in a while-loop -- worked without a problem

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)
  print a

b) made sure the problem isn't in the draw function, taking input from a for-loop -- also no problem

c) tried a for-loop nested inside a while-loop feeding numbers into a draw function -- again, OK

Not sure what else to try.

Tks~