Go Down

Topic: VirtualWire and AnalogWrite problems (Read 1 time) previous topic - next topic


johnwasser


Any other suggestions?


I don't see any obvious coding errors that might cause a faulure.  There is a chance you are triggering some compiler bug.  If that's the case then the onlt fix is to make changes to the code style in the hopes of finding a path past the bug.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

billroy

Two thoughts:

1. That *"\0" in the array initializer looks fishy to me, somehow.  When you print out redC, greenC, and blueC, do you get what you expect?  If you change *"\0" to just 0, does it change the behavior?

2. You don't need strtol() for a one-byte output value; look into atoi().  Probably not what's causing your problem, though.


-br

PaulS

Quote
That *"\0" in the array initializer looks fishy to me, somehow.

It should be '\0'.

Quote
You don't need strtol() for a one-byte output value; look into atoi().

The atoi() function does not handle HEX values as input. strtol() does.

Quote
Any other suggestions?

Ignore what you get from the VirtualWire class. Hardcode a value for the analogWrite() that is between 0 and 0xFF. What does that do?

carlosraniery

I've made some changes on my RX code to find the problem. By now, my code is like that:

Code: [Select]

#include <VirtualWire.h>

int redPin = 3;

void setup() {
  Serial.begin(9600);
  Serial.print("Rx ON");
 
  vw_setup(1200); // Bits per sec
  vw_rx_start();    // Start the receiver PLL running
  vw_set_rx_pin(11);

  pinMode(redPin, OUTPUT);
}

void loop() {
 

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) {
   
    pulse();
   
    //char redC[3] = {(char)buf[0], (char)buf[1], '\0'};
    //long int red = strtol(redC, NULL, 16);
    setRed(255);
    //analogWrite(redPin, (int)red); 
   
  }
}

void pulse() {
   for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
      setRed(fadeValue);
      delay(30);                           
    }
 

    for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
      setRed(fadeValue);       
      delay(30);                           
    }
}

void setRed(int value){
   analogWrite(redPin, value);
}


When I call the method setRed() with 255 or 0 everything goes fine. But when I call it with any intermediate value, the arduino stops working (the pulse method is not executed). This crash is random, sometimes after 1 execution, other times after 10 executions.

Go Up