Loading...
  Show Posts
Pages: 1 2 3 [4] 5 6
46  Using Arduino / Programming Questions / Re: Accessing variables in ISR on: November 26, 2012, 04:03:21 pm
Thank you for all your input.
The link that DuaneB posted was very helpful and explained it all. Thanks for that.

Thank you Nick for your comment. However in the project that I am doing, the timing of the ISR is very critical and I cannot stop it no matter what. Is there any way around that. Is there a way to let the ISR do its job (read sensors to volatile variables (ints)) and these variables can be read in the main loop? ( I am not writing to them, just read them in main loop)

Thank you,
47  Using Arduino / Programming Questions / Accessing variables in ISR on: November 26, 2012, 12:10:25 pm
Hello,

Just wondering how do access variables "safely", that are changing inside the ISR? (My ISR is on a 1 ms period)
Is it just declaring the variable volatile enough? what would happen if I am in the middle of a read operation that accesses the variable inside the ISR, and then the ISR kicks in, pausing my read operation and... well giving false data?
Is there a way to safely access variables inside ISR?

Thank you,
48  Using Arduino / Programming Questions / Re: Sending and Receiving 10 Bit integers to/from Arduino and Processing on: November 08, 2012, 04:16:28 pm
Thanks a lot fungus...
49  Using Arduino / Programming Questions / Re: Sending and Receiving 10 Bit integers to/from Arduino and Processing on: November 08, 2012, 03:37:04 pm
How? Example?
50  Using Arduino / Programming Questions / Re: Sending and Receiving 10 Bit integers to/from Arduino and Processing on: November 08, 2012, 03:33:56 pm
This is great!

The problem here is how to assemble it in Processing and Arduino? Its a 2 way comm link

Thanks
51  Using Arduino / Programming Questions / Sending and Receiving 10 Bit integers to/from Arduino and Processing on: November 08, 2012, 03:22:24 pm
I am trying to send and receive 10 bit integers (the range of analogRead()) first from processing to Arduino and then arduino will reply back the same number to processing.
I am aware that Serial.write and Serial.read both send and receive 8 bit (1 Byte) values and I have that working. Now want to add 2 more bits to my Byte. I am sure I am not the first person to ask this.

The idea of bit-shifting is very interesting and I think it will solve my problem, however I need help on doing this; preferably an example code would be nice.
Or maybe help me build on top of the code I already have.

Thanks a bunch,

Processing
Code:
import processing.serial.*;
Serial myPort;

int inByte = 0;
boolean proceed = false;
boolean sending = true;

void setup(){
  println(Serial.list());
  String portName = Serial.list()[0];
  // change [0] for the Arduino serial port
  myPort = new Serial(this, "COM5", 57600);
  myPort.clear();
 
}

void draw() {
  // first contact
  while (!proceed) {
    if ( myPort.available() > 0) {
      inByte = myPort.read();
      if (inByte == 'A') {
        println("Received " + inByte);
        myPort.clear();
        proceed = true;
      }
    }
  }
  // send and receive test
  while (proceed) {
    if (!sending) {
      if ( myPort.available() > 0) {
        inByte = myPort.read();
        println("Received " + inByte);
        myPort.clear();
        sending = true;
      }
    }
    if (sending){
      myPort.write(255);
      sending = false;
    }
  }
}
Arduino
Code:
int inByte = 0;

void setup() {
  // setup Serial comm with computer
  Serial.begin(57600);
  Serial.print('A'); // send letter "A"
}

void loop() {
  if (Serial.available() > 0) {
      inByte = Serial.read();
      Serial.write(inByte);
  }
}
52  Using Arduino / Programming Questions / Re: Problem with saving data from Arduino on: November 02, 2012, 02:59:36 pm
keypressed() is a built in function in Processing. You dont need to call it.
53  Using Arduino / Programming Questions / Re: Problem with saving data from Arduino on: November 02, 2012, 01:58:09 pm
Hi peter,

I understand your point and logically it sound right, but I after the changes I dont have any data in the text file. At least, before I had 2.8 sec out of 3.1 sec of data.
Any more ideas you have on how to fix this.

Thanks
54  Using Arduino / Programming Questions / Problem with saving data from Arduino on: November 02, 2012, 12:32:17 pm
Hello,

I need to save incoming data from Arduino sent in this format at a serial speed of 57600:
The data are all int type.
Code:
        Serial.print(drive, DEC);
        Serial.print(" ");
        Serial.print(distanceAry[index], DEC);
        Serial.print(" ");
        Serial.print(pressureAry[index], DEC);
        Serial.print(" ");
        Serial.print(prSwitchAry[index], DEC);
        Serial.print(" ");
        Serial.println(tempAry[index], DEC);
Here is my processing program:
Code:
    import processing.serial.*;
    PrintWriter output;
    Serial myPort;
    String myData = null;
    String[] Data = new String[5000];
    int numData = 0;
    int n = 0;
    int m = 0;

    void setup() {
      println(Serial.list());
      String portName = Serial.list()[0];
      // change [0] for the Arduino serial port
      myPort = new Serial(this, "COM5", 57600);
      myPort.bufferUntil('\n'); // SerialEvent for new line
      myPort.clear();
      String Name = "Data "+str(month())+"-"+str(day())+"-"+str(year())
        +"_"+str(hour())+"."+str(minute())+".txt";
      // Create file to save the captured data
      output = createWriter(Name);
    }

    void draw() {
      while ( myPort.available () > 0 ) {
        myData = myPort.readStringUntil('\n');
        if ( myData != null ) {
          Data[n] = myData;
          n++;
        }
      }
      while ( myPort.available() <= 0) {
        if ( Data[m] != null) {
          output.print(Data[m]);
          m++;
        }
      }
    }
    void keyPressed() {
      output.flush(); // Writes the remaining data to the file
      output.close(); // Finishes the file
      exit(); // Stops the program
    }
The Arduino sends data when a push button is activated and it sends the data described above for 3.1 seconds. The data in the arrays was captured every 5 ms. (200Hz). The total number of data sequence is 620 rows and in each row there are 5 data.
Here is the problem I have:
First I run the processing program, then I press the push button. The TX light is on for a short time (~3.1 seconds).
Now my code says, if I press any key on keyboard, flush/close the file, and terminate the program, right?... This does not work, and I have to stop the program by clicking the Stop Button in the processing window.
Here is the weird thing: After I close the program, I only have 2.8 seconds of data in the output file. where did the other 300 ms go?
I really appreciate it if you can help me understand this, or you have some idea on how to fix this.
Thanks
55  Using Arduino / Programming Questions / Re: Is this too big for ISR ? on: October 11, 2012, 02:47:52 pm
@ bperrybap:

Thank you very much for your response.
Here is a description of overall system:
first I switch a hydraulic valve, then I drive a "motor" for 300 to 500 ms. This motor is not a conventional motor and its temperature changes from room to 100 deg C during power on and then back down to room temp. This is why I need a fast DAQ. During the time when the motor is being driven, I have to monitor 5 sensor: PressureSensor, LinearSensor, PressureSwitch, MotorTemp, and FluidTemp. I have to monitor these sensor on a millisecond period. There are also some control structure here which makes the system complicated a bit.
- The system gets activated by a pushbotton.
- before driving the system I have to checkLimits. this means check that pressure, linear and motor temperature are below their max value. These sensors all have analogRead functions.
- Once everything is normal (no max detected), I drive the motor. datalogging starts here for all sensors on a ms period.
- during a timed system drive of 300 to 500 ms, I have to checkLimits continuously, to make sure the sensor values do not go over their max values.
- at some point either the timed driving is going to end or the sensor will cause the system drive to stop.
- after this I have to datalog for 3 more seconds

Code snipets:
This is checkLimits:
Code:
int checkLimits() {
 if( getTemperature(tmp) >= MAXtmp )
  {
     return 0;
  } else if( analogRead(Psensor) >= MAXpressure )
  {
    return 0;
  }
  else if( analogRead(Lsensor) >= MAXdistance )
  {
    return 0;
  } else { return 1; }
}

This is for timed while loop:
Code:
unsigned long i = millis() + MAXtime;
while( i >= millis() )
{
   // timed code here
   // Ckeck Limits
   if(checkLimits() == 0) { break; }
}

Please give ideas on how to do all this.

Thanks
56  Using Arduino / Programming Questions / Re: Is this too big for ISR ? on: October 11, 2012, 12:42:25 pm
Thanks for the suggestion Keith, BUT please tell me you have looked at the price...
By the way, I was kind of considering to get this: http://sine.ni.com/nips/cds/view/p/lang/en/nid/209277

Thanks
57  Using Arduino / Programming Questions / Re: Is this too big for ISR ? on: October 11, 2012, 11:13:03 am
@ Nick Gammon:
Thank you for the info on your website.
The temperature change of my system is like this: room temp to 100 deg C and back down to room temp in under 500 ms... as you can see I really need to capture and send this data.

@ bperrybap:
I did what you suggested in other way around: readings in ISR and sending in the loop. I will definitely experiment with your suggestion.

Thank you
58  Using Arduino / Programming Questions / Re: Is this too big for ISR ? on: October 10, 2012, 06:46:00 pm
How about this code for ISR? would it run faster?

Code:
ISR(TIMER1_COMPA_vect) {  //Interrupt at freq of 250Hz
  distance = getDistance(Lsensor);
  pressure = getPressure(Psensor);
  prSwitch = getPswitch(Pswitch);
  temp = getTemperature(tmp);
  Fldtemp = getTemperature(Fluidtmp);
 
  toprint = 0; //reset buffer
  toprint += drive;
  toprint += ' ';
  toprint += distance;
  toprint += ' ';
  toprint += pressure;
  toprint += ' ';
  toprint += prSwitch;
  toprint += ' ';
  toprint += temp;
  toprint += ' ';
  toprint += Fldtemp;
 
  Serial.println(toprint);
}

59  Using Arduino / Programming Questions / Re: Is this too big for ISR ? on: October 10, 2012, 06:29:11 pm
I optimized my analogRead to get the maximum speed out of it.
This page (near the bottom) shows you how to get 77 kHz reading speed out of analog read. So the analog read times is not a concern to me.
https://sites.google.com/site/measuringstuff/the-arduino

@WizenedEE
How did you manage to read that speed on the serial monitor of PC?

60  Using Arduino / Programming Questions / Re: Is this too big for ISR ? on: October 10, 2012, 05:49:30 pm
I am sorry i did not see the last reply you posted.
Is there a way to increase the baud rate then. increase it in a way that PC can receive it?
Pages: 1 2 3 [4] 5 6