Go Down

Topic: arduino and pyserial (Read 7270 times) previous topic - next topic

powergolden

I am trying to connect my arduino uno board to windows 8 through pyserial and send a series of numbers from arduino to pyserial. how would i go about doing this?

AJITnayak

If using python. Then  you need usb to TTL converted to interface with Arduino
Then only you can get data or send data over arduino.
AMPS

Grumpy_Mike


If using python. Then  you need usb to TTL converted to interface with Arduino
Then only you can get data or send data over arduino.


This is wrong.

You need to simply open the serial port in python and start sending data. Or recieving data.
Study the pose rial documentation.
The baud rate must be set the same as the arduino.
On the arduino end you use serial read and write just as you would with any serial input / output.

AJITnayak

Quote

You need to simply open the serial port in python and start sending data. Or recieving data.
Study the pose rial documentation.
The baud rate must be set the same as the arduino.
On the arduino end you use serial read and write just as you would with any serial input / output.


You can try this out. I am sure it will
not going to work unless it has USB to ttl converter in case of arduino,
Yes it is true, you followed right process but i doubt it will work.
AMPS

Grumpy_Mike


Quote

You need to simply open the serial port in python and start sending data. Or recieving data.
Study the pose rial documentation.
The baud rate must be set the same as the arduino.
On the arduino end you use serial read and write just as you would with any serial input / output.


You can try this out. I am sure it will
not going to work unless it has USB to ttl converter in case of arduino,
Yes it is true, you followed right process but i doubt it will work.


Why do you comment about things you know nothing about?
This is rubbish. I have done this many times.

AJITnayak

What you think yourself. We also not done these kind of stuff. I have also programmed. i also tried these kind of stuff in python.I have written the statement on basis of trial runs done on arduino and python communication
AMPS

Grumpy_Mike


What you think yourself. We also not done these kind of stuff. I have also programmed. i also tried these kind of stuff in python.I have written the statement on basis of trial runs done on arduino and python communication

Then you have no idea about what you have done. And very poor language skills in trying to express what you have done.

Coding Badly

I have done this many times.


As have I.  Several times in the last few days.

The only caveat is opening the serial port resets the Arduino.  Which can be disabled with a capacitor or Exacto knife.

Coding Badly


Waits for the Arduino to send an 'M'...

Code: [Select]
import serial

port = 'COM26'
#port = 'COM6'
baud = 1000000
timeout = 3

_serial = serial.Serial( port, baud, timeout=timeout )

_serial.flushInput()

gotsomething = False

for j in range(3):
 response = _serial.readline().decode( 'ascii' ).strip()
 if response != '':
   cracked = response.rstrip().split('\t')
   if cracked[0] == 'M':
     gotsomething = True
     break


Robin2

This demo illustrates Python to Arduino comms. It should work on any PC as long as the correct reference to the serial port is used.

The Arduino code also works just with the Arduino Serial Monitor.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

powergolden

Ive gotten as far now as sending data. it doesn't seem to be reeding it right.

Grumpy_Mike


Ive gotten as far now as sending data. it doesn't seem to be reeding it right.

You are going to have to do better in your explanation.
What side is sending and what is receiving on the system you have got working?

Plus post the code you have now.

powergolden

#12
Aug 26, 2014, 11:30 pm Last Edit: Aug 26, 2014, 11:47 pm by powergolden Reason: 1
on the arduino side
Code: [Select]
/*
* ArduinoNunchukDemo.ino
*
* Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
*
* Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
*plastic down
*top left A5 top right ground bottom left 3.3v bottom right A4
*/

#include <Wire.h>
#include <ArduinoNunchuk.h>

#define BAUDRATE 19200
const int led = 13;
const int left = 12;
const int right = 7;
const int up = 4;
const int down = 8;
const int ledz = 2;
int c = 1;
int cbutton = 0;
ArduinoNunchuk nunchuk = ArduinoNunchuk();

void setup()
{
 Serial.begin(9600);
 nunchuk.init();
 pinMode(led,OUTPUT);  
 pinMode(up,OUTPUT);  
 pinMode(down,OUTPUT); // this is your basic code that says what pins do.
 pinMode(left,OUTPUT);
 pinMode(right,OUTPUT);
 pinMode(ledz,OUTPUT);
}

void loop()
{
 nunchuk.update();

 Serial.write(nunchuk.analogX); //first number to send
 Serial.print(',');
 Serial.write(nunchuk.analogY);
 Serial.print(',');
 Serial.write(nunchuk.accelX);
 Serial.print(',');
 Serial.write(nunchuk.accelY);
 Serial.print(',');
 Serial.write(nunchuk.accelZ);
 Serial.print(',');
 Serial.write(nunchuk.zButton);
 Serial.print(',');
 Serial.write(nunchuk.cButton); //last number to send


                                                          // EVERYTHING PAST THIS POINT IS IRRELAVENT



if (nunchuk.cButton == 1) {
   if (cbutton == 0) {
      if (c == 1) {
       digitalWrite(led,LOW);
     cbutton = 1;
     c = 0;
     }
     else
     {
     digitalWrite(led,HIGH);
   cbutton = 1;
   c = 1;
   }
 }
 }
 else
 {
   cbutton = 0;
 }
 if (nunchuk.zButton == 1) {
   digitalWrite(ledz,HIGH);
 }
 if (nunchuk.zButton == 0) {
   digitalWrite(ledz,LOW);
 }
 if (nunchuk.analogY > 150) {
   digitalWrite(up,HIGH);
 }
 else
 {
   digitalWrite(up,LOW);
 }
 if (nunchuk.analogY < 110) {
   digitalWrite(down,HIGH);
 }
 else
 {
   digitalWrite(down,LOW);
 }
 if (nunchuk.analogX > 150) {
   digitalWrite(right,HIGH);
 }
 else
 {
   digitalWrite(right,LOW);
 }
 if (nunchuk.analogX < 110) {
   digitalWrite(left,HIGH);
 }
 else
 {
   digitalWrite(left,LOW);
 }
}



basicly what im trying to do is send these numbers over serial and recieve them in python to set each one as a variable.
all

on python
Code: [Select]
import serial
arduino= serial.Serial('COM3', 9600)
data = arduino.read(20)
hi = data[0] //Set hi to the first number.

Grumpy_Mike

#13
Aug 26, 2014, 11:35 pm Last Edit: Aug 26, 2014, 11:37 pm by Grumpy_Mike Reason: 1
OK I am not going to even read that until you put code tags round it.
If you don't know what that means read the how to use the forum sticky post.

Plus you need to say what it does, that is what you are seeing, and you need to post all the python code.

powergolden


Go Up