PySerial

General project discussion area - What have you built with your Micro View

Moderators: phalanx, Help@GeekAmmo, marcus@geekammo

Post Reply
Aravs7
Posts: 2
Joined: Wed Oct 22, 2014 6:43 am

PySerial

Post by Aravs7 » Wed Oct 22, 2014 6:47 am

Hi,

I'm trying to send some data over to MicroView from a python script using PySerial and have it displayed. But it does not work. Anything that I'm missing here?

Here's my code:

Code: Select all

import serial
ser = serial.Serial("/dev/tty.usbserial-DA00SQTP",9600)
ser.write(b'5')
Thanks

Help@GeekAmmo
Posts: 41
Joined: Fri Jul 18, 2014 11:45 am

Re: PySerial

Post by Help@GeekAmmo » Thu Oct 23, 2014 3:37 pm

Hi Aravs7,

Since you did not include your sketch, I am unable to see what went wrong.

Below is a sketch to test your concept, it basically prints whatever send to MicroView's serial port on the OLED.

Code: Select all

#include <MicroView.h>

void setup() {
  uView.begin();
  uView.clear(PAGE);
  Serial.begin(9600);
}

void loop() {
  char c;
  if (Serial.available()) {
    c = Serial.read();
    uView.print(c);
    uView.display();
  }
}

Aravs7
Posts: 2
Joined: Wed Oct 22, 2014 6:43 am

Re: PySerial

Post by Aravs7 » Fri Oct 31, 2014 8:08 am

Hi, There's no problem with MicroView because my sketch works when I try to send data via the Arduino IDE's serial monitor.

I'm trying to write a python script to send data to MicroView over the serial port. I use PySerial to send data to an actual Arduino microcontroller and it works but it does not work with MicroView. This may be because MicroView uses FTDI to send data over serial port. I'm trying to see if there are any available python libraries for ftdi.

Thanks,
Aravind

Help@GeekAmmo
Posts: 41
Joined: Fri Jul 18, 2014 11:45 am

Re: PySerial

Post by Help@GeekAmmo » Fri Oct 31, 2014 10:27 pm

Hi Aravind,

Maybe I was not clear in my reply. I actually used your Python code in the first post and my sample Arduino sketch. I can see character being printed on MicroView.

The FTDI has nothing to do with Python, Python uses the system's serial port. It does not know if it is a FTDI or ATMEGA serial port.

Please try your Python code in the first post together with my sample sketch.

The other thing that you need to watch out is please make sure that you are using the latest MicroView library.

If still not working, please post the following

1. Your python code in full
2. Your Arduino sketch in full
3. OS type & OS version
4. FTDI driver version
5. Python version
6. PySerial version

Cheers
JP

Help@GeekAmmo
Posts: 41
Joined: Fri Jul 18, 2014 11:45 am

Re: PySerial

Post by Help@GeekAmmo » Mon Nov 03, 2014 5:24 pm

I forgot to mention that you might also want to have a delay after opening the serial port.

ser = serial.Serial("/dev/tty.usbserial-DA00SQTP",9600)
(add delay here, try with 1-2 seconds first)
ser.write(b'5')

The reason is because each time the code opens the serial port, depending on your OS, the driver will pulse the DTR line thus resetting the MicroView (Arduino should have the same behaviour). Window's system will pulse the DTR line a few times before it actually stopped. Linux OS from my system only one pulse.

So immediate sending of character will be lost because during the pulsing of DTR line the MicroView is being reset.

Cheers
JP

Post Reply