Hello all,
I'm trying to program two boards to communicate via 433mhz chips. Using radiohead library I'm sending a
"1" to the other and when the other receives the one it causes a servo to rotate. The problem is that either the message isn't being sent or it's not being received. Either way, when I press my button nothing happens.
Receiver Module:
//Flash to receiver module
#include <RH_ASK.h>
#include <SPI.h>
#include <ServoTimer2.h>
const int servo_pin = 11; //Servo Pin
byte message_number = 1; //1 is up and 0 is down
int rf_state = 0; //1 is up and 0 is down //initalize at 0 because reasons
bool debug = true; //Debug
RH_ASK driver(2000,10,10);
ServoTimer2 rangefinder;
void setup()
{
Serial.begin(9600); //Debug
//RadioHead Error Check
if (!driver.init())
{
Serial.println("init failed");
}
//Initialize Servo
rangefinder.attach(servo_pin);
rangefinder.write(1000);
delay(1200);
rangefinder.detach();
}
void loop()
{
Serial.println("Waiting Transmission");
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) //verify if any data is received
{
//driver.printBuffer("Got:", buf, buflen);
Serial.println(buf[0]);
if(buf[0]=="1")
{
if (rf_state == 0)
{
Serial.println("rf_state 0 - moving");
rangefinder.attach(servo_pin);
int i;
for (i = 1801; i > 1000; i -= 25)
{
rangefinder.write(i);
delay(25);
}
rf_state = 1;
rangefinder.detach();
}
if (rf_state == 1)
{
Serial.println("rf_state 1 - moving");
rangefinder.attach(servo_pin);
int i;
for (i = 1000; i < 1801; i += 25)
{
rangefinder.write(i);
delay(25);
}
rf_state = 0;
rangefinder.detach();
}
}
}
}
Use a multimeter to monitor current from the supply to the TX module, you may be able to see it
fluctuate when transmitting, which would give some information.
But first explain exactly what hardware you have and how you've connected it, that's a basic
starting point for troubleshooting...
MarkT:
Use a multimeter to monitor current from the supply to the TX module, you may be able to see it
fluctuate when transmitting, which would give some information.
But first explain exactly what hardware you have and how you've connected it, that's a basic
starting point for troubleshooting...
Transmitter data pin set to pin D9. Button wired as shown (using println commands I can see the button is in fact sending a signal when pressed).
Receiver module set to pin D10, servo on pin D11.
The label says I have 3v going to it, but I have 5v.
It is a bad idea to have a servo running off the same power supply as the Arduino. The electrical noise generated by the motor can reset or damage the Arduino.
Get everything working without the servo (turn on an LED or something), then add the servo with its own power supply and connect the grounds.
Hand drawn diagrams are much preferred over the ones you posted.
zenixnet:
Hello all,
I'm trying to program two boards to communicate via 433mhz chips. Using radiohead library I'm sending a
"1" to the other and when the other receives the one it causes a servo to rotate. The problem is that either the message isn't being sent or it's not being received. Either way, when I press my button nothing happens.
I don't think you should be pressing buttons at this stage. And you shouldn't even be connecting servos at this stage.
Your first objective should simply be to get software communications to work between transmitter and receiver devices.
jremington:
It is a bad idea to have a servo running off the same power supply as the Arduino. The electrical noise generated by the motor can reset or damage the Arduino.
Get everything working without the servo (turn on an LED or something), then add the servo with its own power supply and connect the grounds.
Hand drawn diagrams are much preferred over the ones you posted.
Southpark:
I don't think you should be pressing buttons at this stage. And you shouldn't even be connecting servos at this stage.
Your first objective should simply be to get software communications to work between transmitter and receiver devices.
I recreated it on bread boards. This time just turning on an LED. The button gets pressed on the transmitter and sends the signal, but the receiver still doesn't pick up anything.
I took the hardware configuration above and replaced the servo with an LED and changed the code to just turn it on. I also put in some serial.println to print to the monitor when ever anything is received and sent. It registers the button press and says it's sending a signal but nothing is ever received.
cattledog:
Have you run the radio head library examples between the two modules and confirmed that they are wired and working properly?
I can't get anything when flashing the examples. I hooked up the RF modules without the Arduino (https://www.youtube.com/watch?v=KktetusdYxU) and can get them to turn on a LED so I know the modules are good.
I tried defining pins in the RH_ASK driver and also using the defaults.
Also post a hand drawn (not Fritzing) diagram showing all of your wiring, with pins and connectors labeled.
Receiver example (with pins changed and Serial.print("Receive"); added)
// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
//RH_ASK driver;
//RH_ASK driver(2000,10,9,9,false);
RH_ASK driver(2000,10,9);
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
//Serial.print("Listening");
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
driver.printBuffer("Got:", buf, buflen);
Serial.print("Receive");
}
}
Transmitter example with pins changed
// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
//RH_ASK driver;
//RH_ASK driver(2000,10,9,9,false);
RH_ASK driver(2000,10,9);
// RH_ASK driver(2000, 2, 4, 5); // ESP8266: do not use pin 11
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
const char *msg = "hello";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
Get the simple example working FIRST, before screwing it up completely with extremely ill advised additions.
DO NOT POWER SERVOS OR MOTORS WITH THE ARDUINO.
Get the simple example working FIRST, before screwing it up completely with extremely ill advised additions.
DO NOT POWER SERVOS OR MOTORS WITH THE ARDUINO.
The diagrams are fine!
That's the end goal but what I have right now for testing (with the RH_ASK examples) is just the above minus the servo and button. Just the transmitter and receiver hooked to D10/11.
Are you sure you have it wired correctly? The Amazon page and YouTube video show ATAD as the Middle pin on the TX module. That's the data input. You're wiring your Arduino's D9 (data output) to the far left pin on the TX module.