Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Re: PySerial not stable on: November 14, 2012, 12:46:04 pm
I'm using Ubuntu 12.02. Just to be clear, I am aware this is not 100% arduino and that's why I posted in this section. I am trying to communicate with Python which is software on my computer. If I am In the wrong by posting here I would like a moderator to message me.
2  Using Arduino / Interfacing w/ Software on the Computer / Re: PySerial not stable on: November 13, 2012, 08:37:17 pm
What options do I have to check if the data is there to be read?
3  Using Arduino / Interfacing w/ Software on the Computer / Re: PySerial not stable on: November 11, 2012, 08:12:31 pm
The python code reads the alert file off the server which always will exist. The Arduino code is printing parts of the string "sendVal" with the following code:
 
Code:
  if (length(tempC) < 3){
    //Serial.println("length 2");
    Serial.print(sendVal[0]);
    Serial.print(sendVal[1]);
    Serial.println(sendVal[2]);
   
  }
 
  else if (length(tempC) == 3){
    Serial.println("Length 3");
    Serial.println(tempC);
  }
4  Using Arduino / Interfacing w/ Software on the Computer / Re: PySerial not stable on: November 10, 2012, 08:45:02 pm
The only thing I didn't include in the python code was the passwords and url for my website.
5  Using Arduino / Interfacing w/ Software on the Computer / PySerial not stable on: November 10, 2012, 06:48:09 pm
Hey guys I am trying to control some servos from a website I have running. Everything seems to work okay but the python script seems to crash after a certain number of iterations. I either get.

Traceback (most recent call last):
  File "maincontrol1.py", line 76, in <module>
    val3 = ser.readline()
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 453, in read
    buf = os.read(self.fd, size-len(read))
OSError: [Errno 11] Resource temporarily unavailable


or a similar error that says "device reports readiness to read but returned no data".



EDIT: There is also code for the uno that controls the servos. Let me know if that code is needed.

Here is some of the python code:

Code:
import serial
import nltk  
from urllib import urlopen
import time
import os

serialport = "/dev/ttyACM6"
ser = serial.Serial(serialport, 115200)
time.sleep(1)
print "we are connected"

while (1):



#***************************Servo***************************************
# URL for servo position
url = "server url"  
html = urlopen(url).read()     # Read HTML
raw = nltk.clean_html(html) # Gets conent only

#url1 = "server url"
#html1 = urlopen(url1).read()
#html2 = urlopen(url2).read()
#print("while statement")

if(raw != 'off'): # Only want 3 digits
# Send position to arduino
#print("Move to:")
#print(raw)
ser.write(raw)
#time.sleep(.005)
elif(raw == 'off'):
print("Elif statement")
url = "server url"  
html = urlopen(url).read()     # Read HTML
raw = nltk.clean_html(html) # Clean HTML
else:
print("Position out of range or invalid")
#time.sleep(.005)

#print("after if")
#******************************Camera***********************************
# Get state of command
url = "server url"  
html = urlopen(url).read()    # Get HTML
raw = nltk.clean_html(html) # Clean HTML

if (raw == '1'):
print("**Taking Photo**") # Does user want to take pictures
x = 'streamer -c /dev/video1 -o to directory'
y = 'convert image'
z = 'scp file to server'
os.system(x)
os.system(y)
os.system(z)

elif (raw == '0'):
print("**Camera Off**")
#else :
#print("Invalid Camera Value")

#****************Read Temp*************
#***************************Read Values***************************************
alertVal = ser.read()
val1 = ser.read()
val2 = ser.read()
val3 = ser.readline()
#*************************Analyze**************************************
if(alertVal == '1'):
x = 'scp file to server'
os.system(x)
print("alert")
    
#else :
#print(alertVal)

finVal = val1 + val2 + val3
#print(finVal)

#time.sleep(.1)
#print(alertVal)
#print (val1)
#print (val2)
#print (val3)
try:
# This will create a new file or **overwrite an existing file**.
f = open("temp.txt", "w")
try:
f.write(finVal) # Write a string to a file
#f.writelines(finVal) # Write a sequence of strings to a file
finally:
f.close()
except IOError:
pass
#Send the file to the server
x = 'scp file to server'
os.system(x)    

print "goodbye"

***************************************
Here is the arduino code

Code:
#include <Servo.h>
//Must display the string value of the digits produced
//Check for the stars
Servo horServo;  // create servo object to control a servo
Servo verServo;
//*********************THIS does servo, ping, and temp
boolean lastVal;
boolean curVal;
char sendVal[3];
char change;
//char testVal[2];
const int pingPin = 53;
int pos           = 0;    // variable to store the servo position
int i             = 0;
int j             = 0;
int switchPin     = 47;
int tempC         = 0;
int len;

void setup() {

  // initialize serial communication:
  Serial.begin(115200);
  Serial1.begin(115200);
  Serial.println("We are Connected");
  //verServo.attach(9);  // attaches the servo on pin 9 to the servo
  //horServo.attach(10);
  
  //verServo.write(90);
  //horServo.write(90);
  
//  attachInterrupt(0, alert, RISING); //Arduino interrupt library
}

void loop()
{

//***********************Ping Distance Sensor**********************
  long duration, inches, cm;
    // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  

//  Serial.print(inches);
//  Serial.print("in, ");
//  Serial.print(cm);
//  Serial.print("cm");
//  Serial.println();
//*************************************************************************  
  
  
  
  // int incomingByte=0;
  //int outByte[3];
  // int outSum;
  char inByte;

//******************Read Direction Command**************************
 if (Serial.available() > 0) {
      
  // Read Servo Value
    inByte = Serial.read();
    Serial1.println(inByte);
 }
  
//*************Testing Button Read*******************
//  curVal = debounce(lastVal);
//  if (curVal == HIGH){
//    count++;
//  }
  int a = analogRead(A5);
  tempC = convert(a);
 /* Serial.print("Temp: ");
  Serial.println(tempC);
  Serial.print("Reading: ");
  Serial.println(a); */
  
  
 
  if (length(tempC) == 2){
    if (tempC > 90){
      sendVal[0] = '0';
      sendVal[1] = '9';
      tempC = tempC - 90;
    }
    else if (tempC >= 80){
      sendVal[0] = '0';
      sendVal[1] = '8';  
      tempC = tempC - 80;
    }
    else if (tempC >= 70){
      sendVal[0] = '0';
      sendVal[1] = '7';
      tempC = tempC - 70;
    }
    else if (tempC >= 60){
      sendVal[0] = '0';
      sendVal[1] = '6';
      tempC = tempC - 60;  
    }
    else if (tempC >= 50){
      sendVal[0] = '0';
      sendVal[1] = '5';
      tempC = tempC - 50;        
    }
    else if (tempC >= 40){
      sendVal[0] = '0';
      sendVal[1] = '4';
      tempC = tempC - 40;
    }
    else if (tempC >= 30){
      sendVal[0] = '0';
      sendVal[1] = '3';
      tempC = tempC - 30;
    }
    else if (tempC >= 20){
      sendVal[0] = '0';
      sendVal[1] = '2';
      tempC = tempC - 20;
    }
   else if (tempC >= 10){
      sendVal[0] = '0';
      sendVal[1] = '1';
      tempC = tempC - 10;
      
   }
  
  }
  

   else if (length(tempC) == 1){
     sendVal[0] = '0';
     sendVal[1] = '0';
    
   }
  tempC = tempC + '0';
  sendVal[2] = tempC;
  
  if (cm > 10){
    Serial.print("1");
  }
  else Serial.print(0);
  
  
  if (length(tempC) < 3){
    //Serial.println("length 2");
    Serial.print(sendVal[0]);
    Serial.print(sendVal[1]);
    Serial.println(sendVal[2]);
  
  }
  
  else if (length(tempC) == 3){
    Serial.println("Length 3");
    Serial.println(tempC);
  }
  /*Serial.print("Temp: ");
  Serial.println(tempC); */
  //Serial.println(sendVal);
  lastVal = curVal;
  delay(1);
}

/*void alert(){
  Serial.println("1");
  while (Serial.available() == 0);
  int ackVar = Serial.read();
    if (ackVar == '1'){
       Serial.println("1");
    }  
}
*/
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
  delay(5);
  current = digitalRead(switchPin);
}
return current;
}

int length(int someValue){
int valLen = 0;

if(someValue > 9999)
   valLen = 5;
else if(someValue > 999)
   valLen = 4;
else if(someValue > 99)
   valLen = 3;
else if(someValue > 9)
   valLen = 2;
else
   valLen = 1;
  
return valLen;
  
}

int convert(int reading){
  float calc = (reading*205)/307;
  int rCalc = round(calc);
  return rCalc;
}

long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 2;
}




Let me know if there is anything else you need or if I need to reformat my code for the forum just let me know how to do it.
6  Using Arduino / Motors, Mechanics, and Power / Re: Cooked My Motor Shield on: August 29, 2012, 02:55:09 pm
Sorry about that. I am using the R3 Motor Shield on this site. Here is the link: http://arduino.cc/en/Main/ArduinoMotorShieldR3
7  Using Arduino / Motors, Mechanics, and Power / Cooked My Motor Shield on: August 28, 2012, 03:15:19 pm
Hey guys,

I need help understanding how to power the Arduino with an external power source (non-USB). I have the following setup that works when connected to USB:

- Uno R3 on bottom
- Ethernet shield (using for the SD card slot) in the middle.
- Motor shield on top
Peripherals
- Parallax Ping Sensor
- CMPS03 (compass and I believe it has gyros in there too)
- One small DC motor about an inch in length. It came inside an RC car I tore apart so I don't know what the specs are on it.

Anyway I plugged in a 9V to the screw-down Vin and GND terminals (Red to Vin and Black to GND) and got a lot more power to the motor as expected. I ignored the smell of things burning thinking there was just too much current going through the motor. After a short while I noticed that the motor shield was smoking and a piece of it was actually glowing red.

Surprisingly everything still works from what I can tell. Can someone tell me where I went wrong? I'll be happy to point out what part was glowing on a picture or provide further information if necessary.

Lesson learned. . . If it smells funny, shut it down immediately.
Pages: [1]