Show Posts
Pages: [1] 2 3 ... 3236
1  Using Arduino / Networking, Protocols, and Devices / Re: XBEE API Mode Receive (data conversion) on: Today at 10:21:39 am
Code:
      for(size_t i= (rx.getDataLength()-9); i<rx.getDataLength()-1;i++){
        payload[i] = rx.getData(i);
Where you write data into payload is NOT the same as where you read data from the packet.

2  Using Arduino / Networking, Protocols, and Devices / Re: problem with two SoftwareSerial and Adafruit DataLogger on: Today at 10:16:15 am
Code:
   Sensor1Serial.begin(9600);
Do not call begin() on every pass through loop(). Call it ONCE in setup().

Code:
   Sensor1Serial.listen();
  if (Sensor1Serial.available()>0)
  {
You've just started listening. What do you suppose the odds are that data will arrive in the 62.5 nanoseconds between the two instructions?

You don't stand a snowball's chance in hell of listening to two software serial ports at the same time. Either get a Mega or forget this project.
3  Using Arduino / Programming Questions / Re: Strange behavior of funtions and serial connections on: Today at 09:25:05 am
Quote
Would you suggest that I insert more line feeds in the future or shorter function names or did I misunderstand you there?
White space of some kind makes code more readable. Personally, I think every curly brace belongs on its own line.
4  Using Arduino / Programming Questions / Re: Is my sketch frozen or something? No serial output at all. Other sketchs works.. on: Today at 08:44:45 am
Quote
I think there may be a conflict between AltSoftSerial and SPI over the use of Pin 10.
AltSoftSerial doesn't use pin 10. It uses a timer that is also used by PWM on pin 10 (and 9, but obviously PWM and software serial at the same time won't work, so there is no need to mention that PWM on pin 9 won't work).
5  Using Arduino / Programming Questions / Re: Strange behavior of funtions and serial connections on: Today at 08:41:36 am
I got this far:
Code:
  if (!Serial.available())
  {
    readMode();
  }else if (Serial.available()){
Serial.available() does not return a boolean. The value that it returns should not be used that way. Even if you decide to do that, what else could you determine other than that there is, or is not, data to be read? If there is not data, then there must be data. There are NO other choices, and it is not necessary to test again.

Also,thatcrapwithjammingcodetogetherwithoutwhitespacehasgottogo.
6  Using Arduino / Programming Questions / Re: Transmitting at 433MHz from SD txt file - first characters missing? on: Today at 08:25:15 am
Code:
  char buffMsg[] = "########This is a buffer message \n"; 
  vw_send((uint8_t *)bufferMsg, 1);
Fill an array with data. Then, send one byte. Why such a large array, then?

Code:
  while ((data = myFile.read()) >= 0){
       
    char msg[1] = {data};
  //  delay(0);
    vw_send((uint8_t *)msg, 1);
    vw_wait_tx(); // Wait until the whole message is gone
    delay(50);
}
Why do you need a new array to hold one character? Why are you reading and sending the data one character at a time? Why are you pausing after each character?

You can use a scalar variable (data) in place of the (useless) array:
Code:
    vw_send((uint8_t *)&data, 1);

Use Tools + Auto Format. Your
           code is a pain in the
    eyes to read, jerking all over
                                       the place like that.
7  Using Arduino / Programming Questions / Re: Leonardo -- Serial Issues on: Today at 08:16:54 am
Code:
Holding down the reset button on the Leo
Selecting upload in the Arduino IDE to load the exact sketch in this post (with the single quotes changed)
When it says upload complete I release the reset button
Why? The IDE will reset the Arduino at the appropriate time. Stop f**king with the reset switch. Use the Leonardo as intended.
8  Using Arduino / Programming Questions / Re: how to initialize struct constructor with string on: Today at 08:14:14 am
It is not clear what you are trying to do. There is a definition of the structure, and some odd attempts to initialize data in that structure.

Separate the two, and do it properly. There should be a definition that has no attempt to initialize any struct members, and there should be code to initialize the members of an instance of the struct, once you have declared an instance.
9  Using Arduino / Programming Questions / Re: Simple button function not working on: Today at 08:11:08 am
Code:
boolean buttonState( int btpin){                // button function
  boolean cbs= digitalRead(buttonPin[btpin]);
  if(cbs != lastButtonState[btpin]){
    if(cbs==LOW){
      lastButtonState[btpin]=cbs; 
      return cbs;
    }

  }
}
This is crap. EVERY path through the code should return something. What does this function return if the pin state is the same as the last pin state? Garbage, that's what. Whatever was left in that memory location last time it was written to.

What is returned if the current state is different, but is not LOW? Garbage, again. Whatever was left in that memory location the last time it was written to.

You should NEVER write code like this.
10  Using Arduino / Programming Questions / Re: Memory Test on: Today at 08:05:41 am
Quote
I want something that erases all memory, write on the memory and read it back, check if all the blocks are ok.
Reads and writes which kind of memory? The Arduino has three kinds - flash, SRAM, and EEPROM.

Flash is read-only, at run time.
11  Using Arduino / Programming Questions / Re: Is my sketch frozen or something? No serial output at all. Other sketchs works.. on: Today at 08:01:11 am
Code:
            char inChar = (char)input;
Cast a char to a char so you can store it in a char. Why is ANY of that crap necessary?

Code:
            // Fill buffer up to and including a new line (\n)
            buffer[bufpos] = input&127;
            bufpos++;
Doesn't matter that the buffer might be full?

Code:
              // Empty buffer again (whole array)
              for (int i=0; i<75; i++)
              { buffer[i] = 0;}
More code that illustrates that you don't understand the concept of "NULL terminated array of chars". Specifically, you don't seem to understand the that NULL is a stop sign. There is no value in stuffing 75 stop signs in a row. If you don't stop at the first one, why would you stop at the 17th?
12  Using Arduino / Programming Questions / Re: Conditional using a float that is "-0" and how that works on: Today at 07:53:41 am
Code:
float currentDbLevel;
float max_dbLevel = -0.0001;

if (currentDbLevel < max_dbLevel) {
Since currentDbLevel is a local variable, it is NOT initialized. You are wasting your time trying to decipher any meaning from this code, since you are comparing an uninitialized variable to an initialized one.
13  Using Arduino / Programming Questions / Re: Sending a struct over Serial.write() on: Today at 07:50:29 am
Code:
xbee.write(event);
Perhaps you should look at just exactly what this code is doing. There are two overloads for write() - one for arrays and one for other than arrays. Exactly which overload are you using, and how many bytes are you sending?

Until you KNOW that, or force the compiler to generate code where you can KNOW the answers, you are just stabbing in the dark as far as reading the data on the other end. Be careful of your foot when you are stabbing in the dark.
14  Using Arduino / Programming Questions / Re: Arduino Program Stop Working after 1 sec on: July 31, 2014, 08:25:29 am
Code:
Motor::Motor(int pin)
    {
        pinMode(pin, OUTPUT);
        _pin = pin;
    }
When is your constructor called? Before init()? Or after init()? If you don't know, don't diddle with the hardware in the constructor.

Code:
QueueArray <Node> Pattern::setPattern(int amplitude[4],unsigned long duration[4]){
    QueueArray <Node> queue;
    unsigned long nodeDurationSum = 0;
    for (int i=0;i<4;i++){
    Node node;
    nodeDurationSum = nodeDurationSum + duration[i]; //the reference for duration calculation is patternStartTime
    node.setPatternNode(amplitude[i],nodeDurationSum);
    queue.enqueue(node);
    }
    return queue;
}
What happens to the Node instance when this function ends? What effect does that have on the queued data?

This is really complicated, memory intensive code for use on a limited memory Arduino.
15  Using Arduino / Programming Questions / Re: TFT connected = no IP from DHCP. Not connected = Get IP. on: July 31, 2014, 08:16:44 am
Quote
Might be something totaly different but eh, better to much then to little info.
Like maybe running out of memory?

http://playground.arduino.cc/Code/AvailableMemory
Pages: [1] 2 3 ... 3236