VirtualWire-MX1508 not compatible

I am trying to use VirtualWire.h with a MX1508 motor driver.
In this test sketch the motor driver works as expected - when the VirtualWire.h and the commands in Setup are inserted the motor driver does not work.
I have determined that it is this line that causes the problem.
vw_setup(2000); // Bits per sec
Can anyone suggest what I might do to correct this.
I am using VirtualWire.h because it is small and seems to be used a lot.
The VirtualWire will be used for 433mhz receiver.
Many thanks in advance.



/*
  test for MX1508 and VirtualWire.h

*/

#include <VirtualWire.h>

#define IN1 9
#define IN2 10


void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  Serial.begin(115200);
  Serial.println("Starting.....");

  // Initialise the IO and ISR
  vw_set_ptt_inverted(false); // Required for DR3100
  vw_set_rx_pin(11);           // Arduino pin (default 11)
  vw_setup(2000);             // Bits per sec
  vw_rx_start();              // Start the receiver PLL running

}
void loop() {

  // Full speed forward
  Serial.println("forward");
  analogWrite(IN1, HIGH);
  analogWrite(IN2, LOW);

  delay(200);

  // Full speed backward
  Serial.println("backward");
  analogWrite(IN1, LOW);
  analogWrite(IN2, HIGH);

  delay(200);

  // 0 to 100% speed in forward mode
  Serial.println("speed forward");
  for (int i = 0; i < 256; i++)
  {
    analogWrite(IN1, HIGH);
    analogWrite(IN2, i);
    delay(200);
  }

  delay(50);

  // 0 to 100% speed in backward mode
  Serial.println("speed backward");
  for (int i = 255; i < 0; i--)
  { digitalWrite(IN1, LOW);
    analogWrite(IN2, i);
    delay(200);
  }

  delay(50);
}

You forgot to tell us which Arduino you are using.

VirtualWire uses Timer1 on some Arduinos, so any analogWrite() associated with that timer will not work.

Sorry.I am using a Uno and a Nano.

Then use analogWrite() on pins other than 9 and 10.

Thank you that worked.
Can you briefly explain why 9 & 10 didn't work on the Uno/Nano?

Timer1 controls pins 9 & 10. See post #2.

got it, many thanks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.