473,385 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pyserial output does not change

We are trying to read data from a microcontroller and interface it through serial port. The output is then displayed in Python using Pyserial or the hyperterminal, the former is more important

When you touch the input pins of the microcontroller the value changes real time in hyper terminal. But In the case of the pyserial module, even though you touch the input pins, the value does not change. We have actually noticed that python records and prints the input to the pins of the microcontroller before the code is executed in python. Hence, it does not record and print new inputs once the code was been executed.

What could possibly be wrong with this?

CODE:
import serial,csv,sys


print('Tactile Sensing Feedback for Medical Palpation in MIS\n Pyserial Testing Module\n')
ch= raw_input("Enter a to initialize pyserial module, b to quit:")

if ch == 'a':
print 'Initializing Pyserial module'
ser = serial.Serial(0,baudrate=57600,timeout=0,xonxoff=0 )
print ser.portstr
ser.flushInput()

for x in range (0,100):
s = ser.readline()
print repr(s)
ser.close()

elif ch == 'b':
print 'closing port......\n'
quit()

else:
print 'Invalid option please input a or b only'
Sep 23 '08 #1
2 4140
Example.

When I touch the pins of the microcontroller it outputs a certain value. And then when I execute the program in python it outputs that data from the microcontroller. But when I release my hand or input a certain voltage to the pins of the microcontroller(while the code is running), the output (which is a continuous stream) does not change and still prints the data when the pins were touched.

So no matter how you change the output of the MCU (which is the input to the serial line), output in python does not change and will just retain the value of the output of the MCU at the instant the script in python was executed. So its like the serial line isn't accepting new inputs.

New Findings:

I have actually used the flushInput() command and is incorporated in the code

for x in range (0,100):
s = ser.readline(16)
flushInput()
print (s)
ser.close()

I have noticed that the value now changes when I touch the pins of the MCU. This leads me to the conclusion that the Input buffer does not dumped the initial data it recorded. Now by using flushInput(), the input buffer dumped the old data and accepts new ones but the data printed is disorganized. Why did the input buffer not update when there was new data????

So I have a new problem, which is to organize the data. haha
Sep 25 '08 #2
The flushInput() successfully solved the output changing part. Data seem not to change probably because...

Here are my theories:
1. The Input buffer was not accepting new ones. Since there was not interrupt to signal the CPU to read the contents of the Input buffer
2. Pyserial was reading the data in the input buffer way too slowly. But its so weird how the data can be read this slow.


Any thoughts on this?

Thanks for the Help
Sep 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Petr Jakes | last post by:
Hi, I am trying to set-up communication to the coin change-giver from my Linux box using the Python code. The change giver uses MDB (Multi Drop Bus) serial protocol to communicate with the...
6
by: googlinggoogler | last post by:
Hiya, I've got a PIC microcontroller reading me humidity data via rs232, this is in ASCII format. I can view this data easily using hyperterminal or pyserial and convert it to its value...
5
by: Mimi | last post by:
Hi, I use the pyserial to read data from a serial port. My code is in window Xp and python 2.4. when I use Hyperteminal I can read data without try and try again that it is not the case with...
2
by: Jon | last post by:
Hi, I wrote some code to read in info from a port using pyserial. the code reads info sent by a box that is connected to my computer by an rs232-to usb adapter. When I was writing the code and...
15
by: Lone Wolf | last post by:
I'm trying to get data through my serial port from a CMUcam. This gizmo tracks a color and returns a packet of data. The packet has nine data points (well, really eight since the first point is...
0
by: pauland80 | last post by:
<snip> <snip> Late thanks for your both answers! (Please excuse me for that) The problem was a bug in the device firmware. But before finding this, I dugg lightly in the pyserial source...
0
by: Kineta | last post by:
Hello all, I am attempting to send commands to the firmware on my PIC18F4550 (usb port) microcontroller using Pyserial. If I open Hyperterminal, I can send the following commands and it works...
6
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send...
3
by: Rainy | last post by:
Hello! I'm having some trouble with pyserial package, I'm sending commands and reading responses from a custom pcb, and sometimes I get a proper response, at other times I get nothing, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.