okey i figured i had my transmit module wired incorrect (5v to ground, and ground to 5v) could this 'kill' my module?
i changed code many many times already and checked all connected pins (wich are now correct!), lost of testing,
i added a LED on d13 wich flips state on reciving data, but sadly the power led never goes LOW. (this is the UNO on breadbord)
Problem: or im not transmitting, or im not reciving..
note's:
also i added a serial.print function wich prints the inData after it 'should' be transmitted by rf.
i changed pins from rf modules to defauls for VirtualWire (from 4 to 11 for RX, & 12, TX)
here's the codes:
Control Unit
#include <VirtualWire.h>
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
void setup()
{
//setup a serial connection
Serial.begin(57600);
//Setup VirtualWire to transmit on 4
vw_setup(100);
pinMode(13, OUTPUT); //Power LED
digitalWrite(13, HIGH); //Always ON
}
void loop()
{
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';
}
}
}
if(started && ended)
{
// The end of packet marker arrived. Process the packet
vw_send((uint8_t *)inData, strlen(inData));
Serial.println(inData);
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
delay(40);
}
Device
#include <VirtualWire.h>
int m1r = 6; //motor left red wire
int m1b = 5; //motor left black wire
int m2r = 9; //motor right red wire
int m2b = 10; //motor right black wire
void setup()
{
//virtual wire setup
//for recive on pin 4
vw_setup(100);
vw_rx_start();
pinMode(13, OUTPUT); //power LED
digitalWrite(13, HIGH); //Always ON
}
void loop()
{
//variables setup
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if(vw_get_message((uint8_t*)buf, &buflen))
{
move(char(buf[0]));
digitalWrite(13, !digitalRead(13)); //flip POWER led
}
}
//[FUNCTION] ~ move into recived driection (for,bac,lef,rig)
void move(char DIR)
{
//Stop
if(DIR == 'x')
{
analogWrite(m1r, 0);
analogWrite(m1b, 0);
analogWrite(m2r, 0);
analogWrite(m2b, 0);
}
//drive forward
if(DIR == 'f')
{
analogWrite(m1r, 255);
analogWrite(m1b, 0);
analogWrite(m2r, 255);
analogWrite(m2b, 0);
}
//drive backwards
if(DIR == 'b')
{
analogWrite(m1r, 0);
analogWrite(m1b, 255);
analogWrite(m2r, 0);
analogWrite(m2b, 255);
}
//turn left
if(DIR == 'l')
{
analogWrite(m1r, 0);
analogWrite(m1b, 255);
analogWrite(m2r, 255);
analogWrite(m2b, 0);
}
//turn right
if(DIR == 'r')
{
analogWrite(m1r, 255);
analogWrite(m1b, 0);
analogWrite(m2r, 0);
analogWrite(m2b, 255);
}
}
@PaulS:
As a matter of fact, yes. Add some serial output. Are you receiving what you think you are?
okey i dit so, i am outputting the inData from the arduino board. also i added for the device/robot a little code to flip power led (from high to low and from low to high [D13])
What, exactly, is connecting the two Arduinos?
the 'two' arduino's are connected by air..
i got these arduino's:
1x uno
1x uno on a breadboard (http://arduino.cc/en/Main/Standalone)
the broadboard uno has the reciver and is the device with motors, next to him lies the arduino uno with serial connection (usb) to the pc communicating with arduino IDE
Some of the motor control wires control direction, and should be connected to non-PWM pins, with digitalWrite() used to control them. Do the motors do what they are supposed to with a simple sketch on the receiver?
i have tested my motors before without RF communication to controll them with pwm, and it sucseed (PS: im using a half h-bridge)
(if i am not mistaking) if d9 outputs 5v it is outputting a digital 1 or HIGH, wether it is by pwm(255) or by digitalwrite(HIGH)..
( im sorry if i missunderstand, my english isn't the best..)
The move() function on the receiver is passed an array of chars. It expects a char. Fail!
i geus i changed that now.. (look at new code)