Go Down

Topic: Radiohead problems (Read 473 times) previous topic - next topic

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.

Receiver Module:

Code: [Select]

//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();
        }
      }
    }
}


Transmitter Module:

Code: [Select]

//Flash to transmitter module

#include <RH_ASK.h>
#include <SPI.h>

const int buton_sw = 3; //toggle button
int button_state = 0;
int lastButtonState = 0;

RH_ASK driver(2000,9,9);

void setup()
{
    //pinMode(wakePin, INPUT_PULLUP);
    pinMode(buton_sw, INPUT_PULLUP);
    //pinMode(LED_BUILTIN, OUTPUT);
    Serial.begin(9600); //Debug
    if (!driver.init())
      {
      Serial.println("init failed");
      }
}

void loop()
{
  button_state = digitalRead(buton_sw);
  if (button_state != lastButtonState)
  {
    if (button_state == HIGH || button_state == LOW)
      {
      const char *msg = "1";
        Serial.println("Button Press"); //Debug
        Serial.println("Transmitting..."); //Debug
        Serial.println(msg[0]);
        driver.send((uint8_t *)msg, strlen(msg));
        Serial.println(msg[0]);
        driver.waitPacketSent();
        delay(200);
        Serial.println(msg[0]); //Debug
      }
      lastButtonState = button_state;
  }
 
}

gfvalvo

This is wrong:
Code: [Select]
if(buf[0]=="1")

Try:
Code: [Select]
if(buf[0]=='1')

aarg

I don't think you can receive and transmit on the same pin:
RH_ASK driver(2000,10,10);
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

zenixnet

This is wrong:
Code: [Select]
if(buf[0]=="1")

Try:
Code: [Select]
if(buf[0]=='1')
Changed to '1' and it still doesn't work.

I don't think you can receive and transmit on the same pin:
RH_ASK driver(2000,10,10);

I had the receiver on 10,10 and transmitter on 9,9 but I see what you're saying. I fixed it and still noting.

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...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

zenixnet

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.

Receiver:


Transmitter: NOTE The label for GND and Data is backwards for the transmitter module.


jremington

#6
Dec 07, 2017, 11:17 pm Last Edit: Dec 07, 2017, 11:18 pm by 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.

aarg

Changed to '1' and it still doesn't work.

I had the receiver on 10,10 and transmitter on 9,9 but I see what you're saying. I fixed it and still noting.
What did you do to "fix" it?
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

zenixnet

What did you do to "fix" it?
RH_ASK driver(2000,10,9);

Southpark

#9
Dec 08, 2017, 02:17 am Last Edit: Dec 08, 2017, 02:32 am by Southpark
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.

zenixnet

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.
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.

gfvalvo

Post your current code. TX and RX.

cattledog


Have you run the radio head library examples between the two modules and confirmed that they are wired and working properly?



zenixnet

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.

Here is what I have: https://www.amazon.com/gp/product/B017AYH5G0/ref=oh_aui_search_detailpage?ie=UTF8&psc=1

jremington

Quote
I can't get anything when flashing the examples.
Which examples? Post them.

Also post a hand drawn (not Fritzing) diagram showing all of your wiring, with pins and connectors labeled.

Go Up