Show Posts
Pages: 1 ... 1889 1890 [1891] 1892 1893 ... 3266
28351  Using Arduino / Programming Questions / Re: Clearing the Serial Buffer? on: March 20, 2012, 06:47:54 pm
How can can I block until the Serial.print has, in fact, sent out the characters?
See the comments in the original post. Serial.flush() now blocks until all outgoing data has been sent.
28352  Using Arduino / Programming Questions / Re: Errors in my code. Help Please ! on: March 20, 2012, 06:43:05 pm
Well, OK, that works. I use break, instead. Seems clearer, to me.
28353  Using Arduino / Programming Questions / Re: Stepper Code - Start Stop on: March 20, 2012, 06:40:51 pm
The loop() function is called in an endless loop, for the for loop will be executed every time. Typically, if you want something done once, you put that code in setup().

You could create a global flag:
bool beenThereDoneThat = false;

Then, in loop:
     digitalWrite(dirpin, LOW);     // Set the direction.

     for (i = 0; i<25; i++)       // Iterate for 25 microsteps.
        digitalWrite(steppin, LOW);  // This LOW to HIGH change is what creates the
        digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
        delayMicroseconds(200);      // This delay time is close to top speed for this
     }                              // particular motor. Any faster the motor stalls.

     beenThereDoneThat = true;
28354  Using Arduino / Project Guidance / Re: Level Sensor Height Change conversion to gallons on: March 20, 2012, 06:27:40 pm
As liquid is added to the kettle the sensor will show an increase in distance, (counts up).
If the sensor is measuring the distance to the liquid, how does adding liquid INCREASE the distance?
28355  Using Arduino / Programming Questions / Re: Errors in my code. Help Please ! on: March 20, 2012, 06:23:50 pm
    while (Serial.available()&& MsgComplete == false)
      char c =;
      CmdInStr += c;
      if(c == '*')//msg end
       MsgComplete = true;
    } //while
If you see a * in the incoming stream of data, make note of that fact and keep reading. Well, OK. I would think that you would want to break out of the while loop if you found an end of packet marker.
28356  Using Arduino / Programming Questions / Re: Clearing the Serial Buffer? on: March 20, 2012, 06:09:42 pm
Just read and discard any pending serial data.

Though why you would want to this escapes me. You should have start and end of packet markers. If a packet is bad, you wouldn't know that until you had read the whole packet, so anything still in the buffer is (part of) the next packet.

What you are doing is the equivalent of finding a type on a page, and turning the page, expecting to find a new paragraph at the top of the page. It doesn't work that way.
28357  Development / Other Software Development / Re: serial.write(0x00); gives an error on: March 20, 2012, 06:03:04 pm
Actually, isn't the problem that the literal constant 0x00 is typed - but as an int?
No, it is not typed. However, in the absence of directives the the contrary, literals that can be interpreted as ints will be. Whether the value fits in an int, or not. The problem is that the literal can be interpreted as an int, but there is no write() method that takes an int, so the compiler needs to be told more information, so it can choose the right overloaded method to call.
28358  Using Arduino / Networking, Protocols, and Devices / Re: Udp/EthernetUdp error on: March 20, 2012, 05:59:18 pm
There are example sketches that come with the Ethernet library with the Arduino IDE. Have you looked at them?
28359  Using Arduino / Networking, Protocols, and Devices / Re: xbee and wireless shield affecting Led brightness? on: March 20, 2012, 05:56:19 pm
however when i connect a wireless shield
Dies this shield use SPI? If so, that involves pin 13.
28360  Using Arduino / Storage / Re: SDcard shield Uno -> Mega 2560 on: March 20, 2012, 05:52:44 pm
That shield uses SPI. On the UNO, that is on pins 11, 12, and 13.
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using the SPI library.
On the Mega, that is on pins 51 to 53.
SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI communication using the SPI library.

Note that the CS pin is not necessarily the one you want to use, but that the pin MUST be set to OUTPUT, even if it is not the pin you use.

You'll need to jumper from the hardwired pins the shield used to the correct pins on the Mega.
28361  Using Arduino / Interfacing w/ Software on the Computer / Re: Auto find serial port, script problem on: March 20, 2012, 05:45:45 pm
How can I tell if a port is used without attempting to connect to it?
I don't think you can. You can, though, use a try block around the attempt to connect, and then have a catch block that catches the exception, if one is thrown. The problem you are seeing is that the exception is thrown, but nothing catches it.
28362  Using Arduino / Programming Questions / Re: How to use serialEvent ? on: March 20, 2012, 05:02:16 pm
String sBuffer = "";
If you know how big the array is that the String function should wrap, why do you need a String object? Storing data in a char array directly would be faster.

  while (Serial.available())
    char ch = (char);
    sBuffer += ch;  // add it to the buffer
    if (ch == CRC_EOP) EOP_SEEN = true;
If you see a CRC_EOP, set a flag and keep reading. Is that right? Wouldn't you want to break out of the loop and send the data to wherever avrisp() sends it?

What does avrisp() do? Perhaps the issue is that it is blocking for so long that data gets lost before avrisp() returns, and you get back to reading serial data.

You might try modifying the HardwareSerial class to increase the buffer size, to see if that makes any difference.
28363  Using Arduino / Programming Questions / Re: Save txt on: March 20, 2012, 04:51:59 pm
can I do this?
Sure. Just set the commands up to start notepad.exe.
28364  Using Arduino / Programming Questions / Re: Mock Security Pad issue on: March 20, 2012, 04:43:24 pm
byte attempt[2]; // Entered Code; What people entered
    for (x=0; x<10; x++){
      attempt[0] = 0;
That's probably not good.

int time = 0; // set time measure "millis()"
      time = millis(); // make time variable equal how long pgrams been running
Nor is that. Look at the documentation for the millis() function again.

      attempt[y] = state[x];//If they are, set Attempt[0] to whichever state it was
You are storing HIGH in attempt[0]. Is that what you want? I would think that you would want to store the pin number or the array position, not the state of the pin at that position in the array.

Since HIGH is one, if any switch is pressed, the value will match pass[0].
28365  Using Arduino / Programming Questions / Re: Difference between printing an array and printing individual characters on: March 20, 2012, 04:31:35 pm
to finish off with a null, however this didn't make any difference (it still didn't work)
The NULL is not sent. It's a marker that says keep processing elements in this array until you see me.
Pages: 1 ... 1889 1890 [1891] 1892 1893 ... 3266