Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Troubleshooting / Re: /dev/ttyUSB0 or udev confusion on: July 28, 2010, 09:59:18 am
OK OK OK

So i went to RTFM

I added:
Code:
SYMLINK +="ttyUSB%n"
to the udev line, and it does work, although it creates ttyUSB000 and ttyUSB001 which is kinda ugly but i can at least do stuff.

2  Forum 2005-2010 (read only) / Troubleshooting / /dev/ttyUSB0 or udev confusion on: July 28, 2010, 09:12:08 am
[Ubuntu 10.4, arduino-018]

I am running a project with two serial devices on USB ports (one is an arduino, one is a medical monitor). With all the connecting/reconnecting of the devices I was having problems with which device was /dev/ttyUSB0 and which /dev/ttyUSB1. so i created udev rules which assign the arduino to /dev/arduino and the monitor to /dev/usbserial on plugin.

This works for my python script - it can see each device and doesnt get confused.

Now my problem:
I connect the arduino. dmesg says it is on /dev/ttyUSB0. i can also read serial from /dev/arduino. But when i try to upload a new sketch to the arduino, the GUI says it cannot find /dev/ttyUSB0. likewise when i changed the .arduino/preferences file to /dev/arduino it then says it cannot find /dev/arduino.

I cant paste the whole error message since this is my office PC and the f*****s in IT here wont let me connect my laptop to the network. >smiley-sad

Any ideas where to go next (except for removing my udev rules when i want to change a sketch)? weirdly in the menu, the [chose serial port] is greyed out.

Very grateful for a clever person's help.

bf
3  Forum 2005-2010 (read only) / Troubleshooting / Re: Cryptic Message from avrdude [SOLVED] on: July 26, 2010, 11:06:31 am
Well done to Rugged Circuits

Code:
chmod a+wx /home/ben/arduino-0018/hardware/tools/avrdude

And it works.
Fantastico. Thank you!
Ben ;D
4  Forum 2005-2010 (read only) / Troubleshooting / Cryptic Message from avrdude [SOLVED] on: July 26, 2010, 06:47:07 am
<posted by error in hardware so i am cross posting here, sorry!>

Hi All

Running 018 on my nice new Ubuntu 10.04. Got all the libraries installed, and the arduino software is running, compiling sketches. It is also receiving serial output no problem (there is a sketch on the board right now that sends something, that's how i know).

When i try to upload a sketch i get the following cryptic message:

Quote
java.io.IOException: Cannot run program "/home/ben/arduino-0018/hardware/tools/avrdude": java.io.IOException: error=13, Permission denied
     at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
     at java.lang.Runtime.exec(Runtime.java:610)
     at java.lang.Runtime.exec(Runtime.java:483)
     at processing.app.debug.Uploader.executeUploadCommand(Uploader.java:128)
     at processing.app.debug.AvrdudeUploader.avrdude(AvrdudeUploader.java:192)
     at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:86
)
     at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java
:55)
     at processing.app.Sketch.upload(Sketch.java:1498)
     at processing.app.Sketch.exportApplet(Sketch.java:1465)
     at processing.app.Sketch.exportApplet(Sketch.java:1420)
     at processing.app.Editor$46.run(Editor.java:2219)
     at java.lang.Thread.run(Thread.java:636)
Caused by: java.io.IOException: java.io.IOException: error=13, Permission denied
     at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
     at java.lang.ProcessImpl.start(ProcessImpl.java:81)
     at java.lang.ProcessBuilder.start(ProcessBuilder.java:468)
     ... 11 more

I made sure that i have permission to write to ttyUSB etc.

Google only returns this, which doesnt help me much:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?action=print;num=1250280146

Any help much appreciated.

Ben
5  Forum 2005-2010 (read only) / Troubleshooting / Re: Help needed with csv output coding on: March 25, 2009, 05:25:54 pm
Hi.
I have done this and it was easy with python.
you need to install the pySerial module.

http://pyserial.wiki.sourceforge.net/pySerial

there is an example script (miniterm) for reading from the serial port which you can modify easily to write the incoming data to a file.

open a file for writing in the init section
self.f=open('logfile.csv','w')

in the section def reader(self) you add a line
self.f.write(something)
directly beneath every place you see sys.stdout.write (something)
6  Forum 2005-2010 (read only) / Interfacing / Re: Send sketch to arduino with python on: July 12, 2008, 03:20:54 pm
thanks for the replies - for the record the originator of the c module posted his reply:

http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/

I will take a look at the AVRDUDE stuff - if it can be sent via the shell then i think python has the facility to send shell commands.
7  Forum 2005-2010 (read only) / Interfacing / Send sketch to arduino with python on: July 11, 2008, 03:03:07 am
First a compliment to the Arduino developers. I love this device - with a small amount of general programming knowledge and high-school electronics knowledge (20 years ago) i built my little interface in 2 hours last night - with a little help from www.ladyada.com...

Now my question - is there a way to use Python to send the arduino sketch to the device without using the arduino software?

I saw the arduino_serial.py module but it's not clear to me if you can send an entire file with the --send-data command, and if it would work.

Thanks in advance to anyone with the answers.

Ben
8  Forum 2005-2010 (read only) / Interfacing / Re: Monitoring two devices (?interrupts) on: January 14, 2009, 11:39:30 pm
interesting - i didnt know that the static variables in the preamble arent global. you're right that the lastline variable is redundant - i thought about pre-processing the text on the arduino but i will leave it in the python script waiting for the data on the PC.

i will have a bash at rewriting, seems like it will be a complete rehash

thanks for the advice
9  Forum 2005-2010 (read only) / Interfacing / Re: Monitoring two devices (?interrupts) on: January 14, 2009, 05:17:39 pm
here it is in all it's glory

if i delete 'loop 3' it runs fine.
if i leave it in and press buttons, everything freezes. no error message.
thanks

Code:
/*
 *  Dr Ben Fox drbenfox@gmail.com
 * Using arduino and two switches(s1, s2)
 * when both S1 && S2 are HIGH, adds a counter, activates LEDs; pause 250ms
 */


//variables for handling loop 2, switches & LED
int S2 = 8;              
int S1 = 12;
int ledLocal=10;
int ledDistant=9;
int buttonState;
int buttonPresses=0;
int val;
int debounce;
long timestamp;



//variables for handling serial communication
int CR =13;
int LF=10;
int restartCounter =64; //ASCII 64 = @ character
int incomingByte = 0;      // for incoming serial data
char buffered[128];     //storage array for incomingBytes
int bufferIndex=-1;     //index of most recently added Byte to buffered
char lastline[128];     //saves last line so that if the swicthes are activated there is something to send

#include <AFSoftSerial.h>
AFSoftSerial mySerial =  AFSoftSerial(3, 2);




void setup()                    // run once, when the sketch starts
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);           // set up Serial library at 9600 bps
  mySerial.begin(9600)    ;      //set up software serial on pins 2,3

  //Sets up input and output pins, baseline buttonstate
  pinMode(S2, INPUT);
  pinMode(S1, INPUT);
  pinMode(ledLocal, OUTPUT);
  pinMode(ledDistant, OUTPUT);
  buttonState =digitalRead(S2);

  //forces ledDistant to flash to show that device connected
  int WarmUp;
  WarmUp = WarmUpFlash(5,100);

}


void loop()
/* passes thru 4 loops
 1. monitor soft serial port.
 - if text detected from pulse ox, store in buffer until end-of-line, then transmit
 - if receives '@' via serial (from PC) then resets the buttonPresses variable to zero
 2. monitor USB-serial port for communication from the PC
 3, monitor switches ->if both pressed, send
 4. monitor timer ->if active and >500ms, switches off leds
 
 */

{

  /*START OF LOOP 1 - serial monitor
   monitors software serial input, stores everything in a buffer until gets CR/LF sequence,
   then sends entire buffer to USB serial output and resets.
 
   */
  if (mySerial.available()) {
    // read the incoming byte:
    incomingByte = mySerial.read();
      
    
     if (incomingByte ==CR)  ///ie. end of line character
    {
      // prints to USBserial port,
      // prefixes the data with the buttonPresses value
      Serial.print(buttonPresses);
      Serial.print("     ");
      Serial.println(buffered);
 //     char* lastline[]=buffered;
      char buffered[128];
      bufferIndex=-1;

    }

    else if (incomingByte ==LF)
    { //do nothing at all
    }
    else
    { //add the character to the buffer
      bufferIndex += 1;
      buffered[bufferIndex]=incomingByte;
    }

    if (bufferIndex ==126)
    {//empty buffered if it fills to 127 chars (need one extra)
      Serial.println(buffered);
      char buffered[128];
      bufferIndex=-1;
    }

  }

  //END OF LOOP 1



    //START OF LOOP 2
//      if @ character is recieved, do not add to buffer but reset the buttonPresses variable
     if (Serial.available()) {
           incomingByte=Serial.read()
//    while (Serial.available())     {
           Serial.print(incomingByte);
      if (incomingByte ==restartCounter)
      {
      //resets buttonPresses, does not touch the buffer
 
      Serial.println("reset counter?");
      buttonPresses=0;  
      }
    }
    //END OF LOOP2
    
    //START LOOP3
    
    
    
  if (digitalRead(S2) == 1  && digitalRead(S1) == 1)
  {
    val =1;
  }
  else
  {
    val = 0 ;
  }

  delay(10);

  if (digitalRead(S2) == 1  && digitalRead(S1) == 1)
  {
    debounce =1;
  }
  else
  {
    debounce = 0 ;
  }

  if (val == debounce)
  {

    if (val !=buttonState)
    {          //If both are pressed, light up LED and increment count

      if (val == 1)
      {
        buttonPresses++;
        Serial.println(buttonPresses);
        digitalWrite(ledLocal,LOW);
        digitalWrite(ledDistant,LOW);      

        delay(250);   // longish delay to prevent retriggering



      }

    }

    else
    {
      digitalWrite(ledLocal,HIGH);
      digitalWrite(ledDistant,HIGH);
    }
    buttonState=val;
  }

  //LOOP 3





  //END OF LOOPS
}



//WarmUpFlash makes ledDistant/ledLocal flash to prove connection
int WarmUpFlash(int nFlash, int nDuration) {
  int i;
  for (i=0; i<nFlash; i++){


    digitalWrite(ledDistant, HIGH);  
    digitalWrite(ledLocal, HIGH);
    delay(nDuration);                  
    digitalWrite(ledDistant, LOW);
    digitalWrite(ledLocal, LOW);
    delay(nDuration);
  }
  return 1;
}

10  Forum 2005-2010 (read only) / Interfacing / Re: Monitoring two devices (?interrupts) on: January 14, 2009, 04:45:51 pm
hello again

the softserial thang isnt working for me. same afsoftserial

well, it works fine if i have softserial.read and Serial.read in the loop() but as soon as i add any other programming it all goes kaput. i think there may be a problem with the lack of buffering on the softserial

[sobs loudly]


and all i want to do is to be able to reset a buttonPresses variable to zero from the computer...

i would be doing this every few minutes
[/sob loudly]

anyone with a good idea?
11  Forum 2005-2010 (read only) / Interfacing / Re: Monitoring two devices (?interrupts) on: January 11, 2009, 04:29:05 pm
if found this:

http://absences.sofianaudry.com/en/node/18

will check it out ...
12  Forum 2005-2010 (read only) / Interfacing / Re: Monitoring two devices (?interrupts) on: January 11, 2009, 04:06:08 pm
hi i checked out the afsoftserial

according to http://forums.ladyada.net/viewtopic.php?f=25&t=8212&p=40917 the afosftserial module can also only deal with one port, and importantly the afsoftserial port has no buffer, so if the void loop() is bust with something else, i lose the signal.

is there another technique i can try to reset the buttonPresses variable? maybe i need to add a button for a hard-reset  >smiley-sad but i kinda wanted to control this from software
13  Forum 2005-2010 (read only) / Interfacing / Re: Monitoring two devices (?interrupts) on: January 10, 2009, 11:47:28 pm
there are two sources for serial.available()
- sent from the PC over the USB
-sent from an external device through digital pin 0,1

when the device is not plugged into 0 &1 it reads the PC-USB input fine. when i plugin the external device to 0 & 1, the arduino 'ignores' the PC-USB datastream.
14  Forum 2005-2010 (read only) / Interfacing / Re: Monitoring two devices (?interrupts) on: January 10, 2009, 05:47:14 pm
thanks mem:

here's the relevant bit:
     CR=13, LF=10, restartCounter=64 (the @ character) that i want to send in order to reset the variable buttonPresses. you can see a few lines of Serial.print for debugging.

Code:
 /*START OF LOOP 1 - serial monitor
   monitors serial input, stores everything in a buffer until gets CR/LF sequence,
   then sends entire buffer to serial output and resets.
   if @ character is recieved, do not add to buffer but reset the buttonPresses variable
   */
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    //Serial.print("read: ");
    //Serial.print (incomingByte);

    if (incomingByte ==restartCounter)
    {
      //resets buttonPresses, does not touch the buffer
      Serial.println("reset counter?");
      buttonPresses=0;

    }  
    else if (incomingByte ==CR)  ///ie. end of line character
    {
      // prints to serial port,
      // prefixes the  data with the buttonPresses value
      Serial.print(buttonPresses);
      Serial.print("     ");
      Serial.println(buffered);
 //     char* lastline[]=buffered;
      char buffered[128];
      bufferIndex=-1;

    }

    else if (incomingByte ==LF)
    { //do nothing at all
    }
    else
    { //add the character to the buffer
      bufferIndex += 1;
      buffered[bufferIndex]=incomingByte;

    }

    if (bufferIndex ==126)
    {//empty buffered if it fills to 127 chars (need one extra)
      Serial.println(buffered);
      char buffered[128];
      bufferIndex=-1;
    }

  }

  //END OF LOOP 1
15  Forum 2005-2010 (read only) / Interfacing / Re: Monitoring two devices (?interrupts) on: January 10, 2009, 04:59:29 pm
OK i have a series of loops running
thanks for the tip.  smiley-wink

Now i have a new query - i have Device 1 (above) running well.

however, i also want to be able to send the arduino a message from the PC via serial during the loop. when  device 1 is not connected, it works fine. however, anything i send from the PC serial monitor to the arduino when it is receiving/transmitting from device 1 , the PC is ignored.

how do i solve this?
Pages: [1] 2