Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 13th, 2012, 01:14 AM
mrronoah mrronoah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 11 mrronoah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 39 m 35 sec
Reputation Power: 0
Pyserial help

Ok so I have code that will print out the value of the slider to idle every 100 ms but how can i send this value to the serial port.
My current code looks like this:

Quote:
import serial
import time
import Tkinter

ser = serial.Serial('/dev/tty.usbmodem1411', 9600)
time.sleep(2)

root = Tkinter.Tk()

w = Tkinter.Scale(root, from_=0, to=100)
w.pack()

def show_slider(root,w):
millisecond = 1
print(w.get())
root.after(100*millisecond,show_slider,root,w)

show_slider(root,w)

root.mainloop()

Reply With Quote
  #2  
Old December 13th, 2012, 11:17 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
For python code please use [code] tags instead of [quote] tags.

I expect you'd open a file and write to it. On DOS the file might be called COM1, SER1, or even LPT1:

In unix I expect the file would be accessible somewhere in /dev . Haven't done it. (In 1983 I wrote a BASICA program that communicated with a serial device. Come to think of it, I also worked on a FORTRAN program that communicated with an external device with that microcomputer operating system that preceded DOS.)
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old December 13th, 2012, 08:09 PM
mrronoah mrronoah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 11 mrronoah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 39 m 35 sec
Reputation Power: 0
[QUOTE=b49P23TIvg]For python code please use [code] tags instead of
Quote:
tags.

I expect you'd open a file and write to it. On DOS the file might be called COM1, SER1, or even LPT1:

In unix I expect the file would be accessible somewhere in /dev . Haven't done it. (In 1983 I wrote a BASICA program that communicated with a serial device. Come to think of it, I also worked on a FORTRAN program that communicated with an external device with that microcomputer operating system that preceded DOS.)


Haha sorry. I have the path to the microcontroller setup in the code and i can write to the serial port (ser.write("hello")) but i need the value of the scale to go to the serial port. Not the IDLE.

and i cant just put ser.write(w.get()) like i thought i would be able to, i get an error.
I'm so confused haha. Thanks

Reply With Quote
  #4  
Old December 13th, 2012, 08:59 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
Oh! Sorry, you do have
ser = serial.Serial('/dev/tty.usbmodem1411', 9600)

OK, so the problem may be data type. w.get() returns an integer.

ser.write(str(w.get()))

and of course that still might not work because Serial may need bytes.

Anyway, the problem may be data type. When debugging python the data type is often more useful to know than a human representation.

Reply With Quote
  #5  
Old December 15th, 2012, 01:15 AM
mrronoah mrronoah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 11 mrronoah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 39 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Oh! Sorry, you do have
ser = serial.Serial('/dev/tty.usbmodem1411', 9600)

OK, so the problem may be data type. w.get() returns an integer.

ser.write(str(w.get()))

and of course that still might not work because Serial may need bytes.

Anyway, the problem may be data type. When debugging python the data type is often more useful to know than a human representation.

Yes! it worked thankyou

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Pyserial help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap