Show Posts
Pages: 1 ... 1887 1888 [1889] 1890 1891 ... 3290
28321  Using Arduino / Programming Questions / Re: LEDS, cross fading, mapping question on: March 29, 2012, 01:34:07 pm
Code:
    for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;         
The compiler has already set the elements in readings to 0.

Code:
  printArray(rangevalue, arraysize);
Why? You know what values are in the array at this point.

Code:
  readings[index] = analogRead(anPin);
<snip>
  pinMode(anPin, INPUT);
You set the pin to INPUT after you've read from it. Why? The pin mode should be declared in setup(), not loop(). In any case, this is wrong. The pinMode() function is for digital pins. So, you just set the mode for digital pin 1 (a serial pin, specifically the TX pin) to input. Bad idea.

Code:
if ( vals >= 212 && vals<=240 ){
  digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
      digitalWrite(ledsignal, HIGH);
}
I
   love
       code
            that
                 wanders
                     across
                          the
                               page
                                    for
                                        no
                                            reason.

Code:
vals = rangevalue[midpoint];
vals is a scalar. Why is the name plural? A more meaningful name would be useful.

The variable vals is used and then computed. Why is that?

Quote
but when i try this with my if statement, the mapping from sensor is causing confliction and in turn, causing the crossfade LEDS to flicker. suggestions?
What does "causing confliction" mean?

You are turning the fading LEDs off, but then on the next pass though loop, you resume them fading, and then turn them off again. It's no wonder they don't stay off.

Code:
if(vals >= 212 && vals<=240)
{
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(ledsignal, HIGH);
}
else
{
  analogWrite(led1, outputValue1); // <-- move the analog writes to here
  analogWrite(led2, outputValue2);
  digitalWrite(ledsignal, LOW);
}
would work better.
28322  Using Arduino / Programming Questions / Re: SD Card and Ethernet lead to avrdude: stk500_recv(): programmer is not respondin on: March 29, 2012, 01:16:58 pm
Adding the SD library uses a lot of SRAM. That can do strange things as the sketch is uploaded.

Post your code, so we can see if there are ways to reduce SRAM usage.
28323  Using Arduino / Programming Questions / Re: Need to read up to 43 bytes of data, reading incorrectly. on: March 29, 2012, 12:45:36 pm
Quote
The arduino reference page is useless when it comes to explaining pointers
Because pointers are not unique to the Arduino.

Quote
and my C book is confusing me.  perhaps a literal approach to how this works will help me wrap my head around this one.
Are you familiar with the post office, and the rows of mailboxes that mail is delivered to, for people that don't want mail delivered to their houses?

Memory is arranged like those rows of mailboxes. A pointer is, effectively, a number on a mailbox. The mailbox might, or might not, have a name on it, but it does have a number.

A pointer variable holds the number of the mailbox (the address of the mailbox). You can get the data in the memory location (the mail in the mailbox) using the name on mailbox (a variable) or by pointer (the number on the box).

Notice those boxes without names? They can only be accessed by pointers.

Pointers are useful because you can access a whole string of memory locations by simply incrementing the pointer (changing the number of the mailbox to access).
28324  Using Arduino / Programming Questions / Re: How to measure led volts whit analogread() on: March 29, 2012, 12:35:37 pm
Quote
Thanks
but thats not the issue

Quote
You mean this is not corret, I read values but erroneus, I think because the map.
Personally, I am really confused. You said that there errors in, and misuse of, the map function were not the source of the problem, but now you think maybe they are.

Quote
Pin 9 is connected to potenciometer powering (PWM) the led
Potentiometers are variable resistors. They are not a source of power. If you have a potentiometer, where does PWM come into the picture?

You have described at best one third of the circuit.

Quote
Pin A0 is connected in same pot monitoring
Connected where?

We don't ask these questions to annoy you. We ask them because we can't see your hardware or your schematic.

Describe, or take a picture of, or draw a schematic that shows every wire connected to the Arduino.

Post ALL of your code, and any debug output.
28325  Using Arduino / Interfacing w/ Software on the Computer / Re: More MATLAB Trouble on: March 29, 2012, 12:19:23 pm
Quote
I tried setting the first value of the char array to 0 it didn't work i got the second number continued by the first number.
Because you are not adding data to the array correctly.

This is an example of how it should be done:
Code:
char inData[15];
byte index = 0;

inData[index] = '\0';

while(Serial.available() > 0)
{
   char aChar = Serial.read();
   if(aChar == ",")
   {
      // Use the index characters in inData

      // Get ready for next value
      index = 0;
      inData[index] = '\0';
   }
   else
   {
      inData[index++] = aChar; // Add the char to the array
      inData[index}; // Add a NULL after that character
   }
}

Code:
String input_line [50];
Wow. Talk about a sledge-hammer solution...
28326  Using Arduino / Interfacing w/ Software on the Computer / Re: get the status of plx daq control on: March 29, 2012, 12:10:33 pm
Quote
If I try the if-statement in the setup() there is also no status coming back.
Because you didn't wait for a reply. You expected the reply to be available a few nanoseconds later when the read method was called.

Try this:
Code:
void setup()
{
    Serial.begin(9600);           // baud rate/speed
    Serial.println("CLEARDATA");   // clear data in excel on reset
    Serial.println("LABEL,Time,,,LOAD/Newton"); // columnnames, Time, not TIME -> is instruction
    Serial.println("MSG,Set Metric for Newton - otherwise in Pound");
    Serial.println("USER1,LABEL,Metric");  // user1 new label
   
    Serial.println("USER1,GET");
    unsigned long sentTime = millis();
    while(millis() - sentTime < 60000UL) // Wait up to 60 seconds for a reply
    {
       if(Serial.available() > 0)
       {
          USER1 = Serial.read();
          digitalWrite(13, HIGH);
          break;
       }
    }
}

If, at the end of setup(), the LED is on, then you got some kind of response. Without an LCD or some means to show what that response was, I don't know how you can debug the issue.
28327  Using Arduino / Programming Questions / Re: Serial read on: March 29, 2012, 12:02:36 pm
Quote
Input: I send "Hello world!"
That code is expecting "<Hello world!>", not "Hello world!".

If you are indeed sending "<Hello world!>", and getting a response back that is "chopped up", then it is your receiver that is doing the "chopping up".

Show that code, to.
28328  Using Arduino / Programming Questions / Re: How to measure led volts whit analogread() on: March 29, 2012, 11:56:34 am
You need to describe what you have connected to the Arduino, on which pins. You say that you are using PWM to light the LED, and then you say you are trying to read the voltage to the LED. You can't do both with the same LED.
28329  Using Arduino / Interfacing w/ Software on the Computer / Re: More MATLAB Trouble on: March 29, 2012, 11:49:43 am
Several comments. First, you are collecting the data into a char array. Then, you are wrapping that char array in a String. Why?

There is no reason for hiding the character data in a String object, especially as the atof() function has no idea how to deal with a String.

Second, it is clear that you do not understand the relationship between a char array and a string (with a lower case s). Functions like atof() and the String constructor expect strings. A string is a NULL terminated array of chars. value is an array of chars, but it is not a string, because it is not NULL terminated.

Until you NULL terminate the array of chars, you can not pass the char array to functions like atof() or the String constructor and expect correct things to happen.

If you did understand this relationship, you would know that functions that expect strings stop reading the character data at the NULL, so
Code:
               for(int k =0 ; k<15;k++){value[k]=0;}
is unnecessary. Simply set value[0] to NULL ('\0').

Your parse_data() function declaration should look something like this:
Code:
void parse_data(char *data, float &servo, float &pwm, float &pressure)
{
}
28330  Using Arduino / Interfacing w/ Software on the Computer / Re: get the status of plx daq control on: March 29, 2012, 11:24:43 am
Code:
Serial.println("USER1,GET");
    if (Serial.available() > 0){
    //Serial.println("USER1,GET");
    metric=Serial.read();
    if (metric == '1')
    {Serial.println("y");}
    if (metric == '0')
    {Serial.println("n");}
    else {Serial.println("no serial");}
    }
I want to know the value of the USER1 field, and I demand to know it NOW!!!!

I'm pretty sure that it takes more than a few nanoseconds for the request to get to the PC, get evaluated by the Excel plugin, and to get the answer back to the Arduino.

I'm also certain that you don't want to send the request on every pass through loop.

Finally, I'm pretty sure that Excel can do the conversion faster than the Arduino can. Just send data in one system of units, and let Excel, through the use of formulas, display the data however the viewer wants to see it.
28331  Using Arduino / Programming Questions / Re: Array to String code behaving awkwardly on: March 29, 2012, 11:12:03 am
Quote
Tried in the Serial of Arduino 1.0 working.
Well, that's interesting, since the Serial.flush() function on 1.0 only affects outgoing data.

Quote
the code is too heavy in Arduino 1.0 its about 3842 bytes about 4kb and in 0022 its about 2.7kb
I'm pretty sure that the Arduino can handle the increased "weight".
28332  Using Arduino / Programming Questions / Re: How to "print" serial data to 2.8" TFT ? on: March 29, 2012, 10:59:59 am
Quote
If yes can you please hellp me on defining the buf and len?
buf needs to be a char array:
Code:
char buf[n]; // where n is some number
len is the number of characters the array can hold.

You need to make buf large enough to hold all the data in inputString. Only you know how big it needs to be.
28333  Using Arduino / Programming Questions / Re: Array to String code behaving awkwardly on: March 29, 2012, 10:55:37 am
Quote
Cracked! It's because of the Serial.flush(); it just happened to flush the buffer from what was leftover from the previous Serial entry.
So, try that on Arduino 1.0.
28334  Using Arduino / Programming Questions / Re: How to "print" serial data to 2.8" TFT ? on: March 29, 2012, 10:26:22 am
http://arduino.cc/en/Reference/StringToCharArray
28335  Using Arduino / Programming Questions / Re: How to "print" serial data to 2.8" TFT ? on: March 29, 2012, 10:18:15 am
Quote
Can you please write a example because i dont understand what you candly tell.
I could, but I can tell from your quick post that you did no research, so I won't.

The toCharArray() method is very easy to use.
Pages: 1 ... 1887 1888 [1889] 1890 1891 ... 3290