Show Posts
Pages: 1 ... 2119 2120 [2121] 2122 2123 ... 3270
31801  Using Arduino / Programming Questions / Re: Arduino recieving hexadecimal data on: December 27, 2011, 01:02:36 pm
Quote
I'm trying to create something that I can send "01 FF" to arduino and the 01 part (this is HEX) sets the pin, and "FF" set the analog value of that pin
If you are sending 01 FF as characters, they are not automatically transformed into numbers on the Arduino. You must read a complete packet ("01 FF" needs some start and end of packet markers), collecting the data into a container (either a String or a char array (preferred)). Then, you must parse the data to get the tokens ("01" and "FF"), then you must use strtol() to convert the tokens to numeric values.

If you add start and end of packet markers, you can use code like this co collect the data into a char array:
Code:
#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}
Where it says "Process the packet", use strtok() to get the tokens and strrol() to convert the tokens to values.
31802  Using Arduino / Programming Questions / Re: Programing in arduino? on: December 27, 2011, 11:31:56 am
Quote
if (A) turned on then the first line will be executed
What is A? What does "turned on" mean? First line of what?

Quote
if it turns on again the second line will be executed, and so on.
If A is a switch pin going HIGH, then you need to keep track of the previous state of the pin, so you can tell when a transition occurs (the current state is not the same as the previous state). When a transition occurs, you need to determine whether it is to-pressed or to-released, based on the current state.

When a to-pressed transition occurs, increment a counter. Execute some code, or not, based on the current state and the value of the counter.
31803  Using Arduino / Programming Questions / Re: ARDUINO TIME PROBLEM on: December 27, 2011, 10:41:52 am
The highlighting adds nothing to your post. Knock it off.

Answering the questions would add something to your post. Try doing that instead. In case you've lost track:
How are you sending the time to the Arduino? POST THE CODE!!!

The Arduino code expects an exact number of characters in the response, in a pretty specific format. Prove that you are sending the data in the format that the Arduino expects.
31804  Using Arduino / Programming Questions / Re: Why doesn't this code work (stepper motor)? on: December 27, 2011, 10:13:52 am
So, valid data leads to a valid value in output. If the stepper motor is not stepping correctly, the issue is not with the serial input/processing. It must lie elsewhere.

Add Serial.print() statements to the Stepper library. Make sure that the number of steps to step is correct in the step() method. If it is, but the motor doesn't step correctly, the problem is hardware.

Quote
The stepper works properly with the Demo sketches that come with the IDE.
All the examples are for a 4 wire stepper. Your code assumes a 2 wire stepper. Please explain why, if the 4 wire examples work, you are using only two wires in your sketch.
31805  Using Arduino / Project Guidance / Re: NEWB trying to work with Nano on: December 27, 2011, 09:56:21 am
Quote
i can get everythign to work but its twitching like crazy and no matter the direction i move the accel.. it moves the servo.  i only want to measure one axis. not all three.  how to i make it do that? and how do i stop the twitching effect.?
Which accelerometer?

When the bike is leaned into a corner, is it the x axis you want to measure, the y axis, or the z axis? The answer is that you need to measure more than one, and use them to determine how far the bike has leaned. Doing so is not trivial, since the acceleration vector you are measuring is a composite of multiple inputs - gravity and the bikes acceleration/deceleration being the primary inputs, but bumps in the road are going to be measured, too.

31806  Using Arduino / Project Guidance / Re: A server-backed neon scrolling sign message system and its feasibility? on: December 27, 2011, 09:31:45 am
Quote
how difficult (if it's even possible) do you think it would prove to be?
That would all depend on willing you are to change this:
Quote
I'm not much of a hardware guy (I'm not that great at software either)
Having the Arduino periodically check a web site for data to display is pretty easy, with an Ethernet shield, if you know anything about web programming and client/server programming. It can be a real challenge it you don't.

Extracting one character at a time from the text is simple. Determining which LEDs to light up to form that character is non-trivial, but it needs to be done only once. Making those specific LEDs light up is a combination of programming and engineering (software and hardware). Moving that character along (scrolling) is not too difficult. Adding a second character, once the first one is displayed and moves correctly will be simple. Once you can do two, any number is then quite easy.
31807  Using Arduino / Project Guidance / Re: How to round off the data and Store it into Memory for processing on: December 27, 2011, 09:13:37 am
Quote
How to round off the data
Round off what data? GPSs return strings. You can't round a string. The string needs to be parsed and converted to numbers. You don't want to round the numbers when you store them in memory.
31808  Using Arduino / Programming Questions / Re: how can i? on: December 27, 2011, 09:05:09 am
Quote
i want to add a function to my program that when robot detect a obstacle turn left its axis(like left motor turn back and right motor turn forward) with random angle and go.
Well, you have our permission.

Quote
How can i do?
You have fingers don't you? Start typing.

Quote
how can i a call function that bot left right motor and encoders works at same time?
Code:
theFunctionToDoUsefulStuff();

Seriously, we need to see your existing code and know something about the hardware you currently have.
31809  Topics / Robotics / Re: Solar Powered Coke Fetching Robot - Advice Please on: December 27, 2011, 09:00:13 am
Quote
but I'd like to see if there's a way to get it to recognize and grab a coke from, say, anywhere on the bottom shelf.
What does the robot need to be able to distinguish the coke from? Beer? Pepsi? Lettuce? Ketchup?

Distinguishing a coke from a beer is not as difficult as distinguishing a coke from a Pepsi, since beer cans are not the same size as soda cans. All soda cans are the same size, though.
31810  Using Arduino / Programming Questions / Re: using Serial.XXX function to print float values. on: December 27, 2011, 08:32:29 am
Quote
serial.print(y); // the output of this on serial port should be 1.2345
What is it? What problem do you have?

Look at the documentation for the Serial.print() function. There is an optional second argument that controls the number of decimal places, when the argument is a float.
31811  Using Arduino / Programming Questions / Re: Why doesn't this code work (stepper motor)? on: December 27, 2011, 08:19:18 am
Quote
To check that "output" was an int, I tried multiplying it by 2 and printing the result out to serial. There weren't any errors, so I assume that means output is, in fact, and int.
That the contents of a memory address could be multiplied by 2 and printed to the serial monitor doesn't tell you anything about the validity of the contents of that memory location. If you send <0> and you see 0 on the serial monitor, you might assume that output is indeed populated correctly. If the stepper motor then steps once, you should be concerned that there is still a problem.

If you send <99> and see 198 on the serial monitor, that tells you one thing. If you see some other value, that tells you something else.

You didn't tell us what you saw, so I guess you no longer need help.
31812  Using Arduino / Programming Questions / Re: Trouble using HSC pressure transducer on: December 27, 2011, 08:11:57 am
Code:
  byte pvalHigh, pvalLow;
Local variables are not initialized. Since these variables may, or may not be assigned a value - depending on whether the device responds in a timely fashion - you MUST assign them default values.

Code:
  Wire.requestFrom(PRESSURE_ADDRESS, 2);
  while (Wire.available()) {
    pvalHigh = Wire.receive();
    pvalLow = Wire.receive();
  }
You are expecting that the device has generated a response immediately. I'm not sure that that is a valid assumption. You are also testing that Wire.available() returns at least one, and then reading two bytes. Again, not the correct way to do this.

I would execute a while loop, waiting for two bytes to be available OR for some time to have elapsed. Only when there are two or more bytes would I try to read two bytes. If two bytes do not become available within a reasonable time, then bail out WITHOUT adding to the data string.
31813  Using Arduino / Project Guidance / Re: Temperature control project for a distillery on: December 26, 2011, 10:03:14 pm
Quote
All works at the moment with PID controllers.
Start with a description of why that needs to change.

Quote
What board, sensors (50 to 120 C) and relays would you suggest?
Any Arduino will work. The relays depend on the voltage and amperage being controlled. Perhaps I missed that part...

31814  Using Arduino / Project Guidance / Re: xbee on a car sensor on: December 26, 2011, 10:00:38 pm
Quote
Can xbee be used to communicate between a sensor outside of a car to an arduio in side the car?
For most normal sized cars, yes.

Quote
I want to make a laser curb feeler for my low front bumper.
A wire is cheaper and easier to waterproof. Much cheaper.
31815  Using Arduino / Project Guidance / Re: 2wire signals on: December 26, 2011, 08:36:14 pm
Code:
Serial.print(1);
No. You are trying to read binary data. You must send binary data to be read.
Code:
Serial.write((byte)1);
Pages: 1 ... 2119 2120 [2121] 2122 2123 ... 3270