Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101753 > unrolled thread
| Started by | sam Rogers <samlro2@yahoo.com> |
|---|---|
| First post | 2016-01-15 13:45 +0000 |
| Last post | 2016-01-15 15:02 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
help sam Rogers <samlro2@yahoo.com> - 2016-01-15 13:45 +0000
Re: help Dave Farrance <df@see.replyto.invalid> - 2016-01-15 15:02 +0000
| From | sam Rogers <samlro2@yahoo.com> |
|---|---|
| Date | 2016-01-15 13:45 +0000 |
| Subject | help |
| Message-ID | <mailman.13.1452865749.15297.python-list@python.org> |
I have downloaded python 2.7 with no problem. It works. I am trying to get pyserial to work. I have tried many different solutions. I am not sure if it works or not. How can I be sure? I am using windows 7. I did not see any help at python.org. Can you help? PS my goal is make this adafruit project work. https://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector/overview Thanks,Sam
[toc] | [next] | [standalone]
| From | Dave Farrance <df@see.replyto.invalid> |
|---|---|
| Date | 2016-01-15 15:02 +0000 |
| Message-ID | <0q1i9bpvu537l2p9mf555a5s0ht5t57mbs@4ax.com> |
| In reply to | #101753 |
sam Rogers <samlro2@yahoo.com> wrote:
> I have downloaded python 2.7 with no problem. It works. I am trying to get pyserial to work. I have tried many different solutions. I am not sure if it works or not. How can I be sure? I am using windows 7. I did not see any help at python.org. Can you help?
>PS my goal is make this adafruit project work.
>https://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector/overview
Before using Python, have you verified that the IDE talks on the serial
port OK -- and that you can upload the simple blink sketch from its
provided examples and that you can change the blink rate of the LED?
Having done that, can you establish 2 way communication with Python?
What happens if you try the simple test script below? You will need to
change the "dev" line to whichever port you're using.
// Arduino sketch to echo serial port strings
char buf[81]; // max 80 chars + null
int siz = 0; // size of input string
void setup(){
Serial.begin(9600);
Serial.setTimeout(100);
}
void loop(){
siz = Serial.readBytesUntil('\n',buf,80); // get input string
if (siz == 0) return; // if timeout, loop again
Serial.print("I heard: "); // reply with some text and
buf[siz] = 0; // must add null terminator
Serial.println(buf); // return original string
}
#!/usr/bin/env python2
import serial,time
# LINUX PORT -- change to "COM1" or whatever for Windows
dev = "/dev/ttyACM0"
ser = serial.Serial(dev, 9600, timeout=1)
time.sleep(2) # Arduino starts in ~1.6s
while True:
mystr = raw_input("Enter text max 80 chars: ")
if mystr == '': break # terminate prog with <enter>
ser.flushInput() # flush input just in case
ser.write(mystr + '\n') # send newline-terminated string
txt = ser.readline(80) # read newline-terminated string
print len(txt),"chars: ",txt, # \r\n included so add final comma
ser.close() # close port
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web