Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] arduino via serial port

edited March 2014 in OpenSesame

Hi
I am using open sesame with arduino microcontroller platform.
I am communicating with my arduino with pySerial library.

I am using the arduino to activate motors, but each loop when I write the command
ser = serial.Serial("com8", 9600)
It resets the arduino and its take few seconds that destroy my experiment(due to the arduino bootloader).

Is there any way to create the ser class of pyserial just once when I start the experiment
and call the serial.write command without creating a new class every time?

Comments

  • edited 11:26PM

    Hi!

    Yes there is! Put the following inline_script somewhere at the beginning of your experiment:

    import serial
    
    # create a new serial device, under the exp dict
    exp.ser = serial.Serial("com8", 9600)
    

    Now use the following inline_script whenever you want to call the write method:

    # do some stuff here
    myvar = "000000000"
    
    # call write!
    exp.ser.write("myvar")
    

    Good luck!

  • edited 11:26PM

    thank you!!!

Sign In or Register to comment.