Adafruit Bluefruit EZ-Link 1.0 Issues with pySerial

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Gingey
 
Posts: 6
Joined: Fri Nov 08, 2013 3:45 pm

Adafruit Bluefruit EZ-Link 1.0 Issues with pySerial

Post by Gingey »

Hello, I am a High School Student who is trying to learn Electrical Engineering in my free time. I am trying to create a robot that will be able to be driven by a GUI run by python and Tkinter. I am trying to make it so the computer gets command from the user through the python script, sends it through serial (using the pyserial library) to the arduino over bluetooth, which will control the robot. Here is my python code:

Code: Select all

#Tkinter Test Script

print "Importing Libaries"
from Tkinter import *
from PIL import Image, ImageTk
import serial

#Set up connection with arduino"
port = serial.Serial(
    port=r"COM7",
    baudrate=9600)
print "Connected with Arduino"

root = Tk()

root.title("Rover Controller")
leftImage = ImageTk.PhotoImage(Image.open(r"C:\Users\Gingey\Desktop\left.png"))
rightImage = ImageTk.PhotoImage(Image.open(r"C:\Users\Gingey\Desktop\right.png"))
upImage = ImageTk.PhotoImage(Image.open(r"C:\Users\Gingey\Desktop\up.png"))
downImage = ImageTk.PhotoImage(Image.open(r"C:\Users\Gingey\Desktop\down.png"))

def moveLeft(event):
    print "Left"
    port.write("l")

def moveRight(event):
    print "Right"
    port.write("r")

def moveUp(event):
    print "Forward"
    port.write("u")

def moveDown(event):
    print "Backwards"
    port.write("b")


frame = Frame(root)
frame.grid()
frame.focus_set()
frame.bind("<Left>", moveLeft)
frame.bind("<Up>", moveUp)
frame.bind("<Right>", moveRight)
frame.bind("<Down>", moveDown)

left = Label(root, image = leftImage)
left.grid(row=1, column=0)

        
right = Label(root, image = rightImage)
right.grid(row=1, column=2)

up = Label(root, image = upImage)
up.grid(row=0, column=1)

down = Label(root, image = downImage)
down.grid(row=2, column=1)
        


root.mainloop()
And this is my code for my arduino script, still uncompleted, as I am just trying to read the bytes sent right now.

Code: Select all

#define up 8
#define down 9
#define left 10
#define right 11

char letter;

void setup()
{
  Serial.begin(9600);
  
  pinMode(up, OUTPUT);
  pinMode(down, OUTPUT);
  pinMode(left, OUTPUT);
  pinMode(right, OUTPUT);
}

void loop()
{
  while(Serial.available() > 0)
 {
   letter = Serial.read();
   Serial.println(letter);
 } 
  
}
I know SOMEWHAT of what the problem is. When I launch the python script, it works fine until it has to send the character. When I look through control panel, I know the arduino is connected through COM7. I just don't know how to fix these connectivity issues between the pyScript I'm running and the Arduino. I am assuming this is a software issue, as I know the Bluetooth module is working, as I can upload to it when I am not running the pyScript. If I run both at the same time though, the pyScript crashes while the Arduino just simply wont upload.

I know this probably is a trivial question, but its really stumped me. :(
Last edited by Gingey on Sun Jan 12, 2014 5:44 pm, edited 2 times in total.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit Bluefruit EZ-Link 1.0 Issues with pyScript w/ P

Post by adafruit_support_rick »

Code: Select all

#Set up connection with arduino"
port = serial.Serial(
    port=r"COM7",
    baudrate=9600)
I'm not familiar with Tkinter. What does the 'r' before "COM7" indicate?

Gingey
 
Posts: 6
Joined: Fri Nov 08, 2013 3:45 pm

Re: Adafruit Bluefruit EZ-Link 1.0 Issues with pyScript w/ P

Post by Gingey »

Sorry, the r simply means "raw string." Its become a habit for me to use it when describing file paths in python. For example, the file path "C:\Users\Gingey\Desktop\right.png" would be interpreted wrong by python because "\r" is a special character or something. Stack overflow helped me with that problem by just advising that whenever I directed file paths in python to place the r"<String>" before each string to make sure it is interpreted literally or something like that.

Here is my StackOverflow Question on the "r" thing. http://stackoverflow.com/questions/2106 ... ward-slash

I'll keeping trying to see why I can't communicate between the Arduino and Computer. I'll post if I find anything useful.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”