Hello, I am attempting to connect two 900 mhz RF modules using two MEGA 2560's. I downloaded source code online and I setup one Arduino+RF (Unit 1) to send and one Arduino+RF (Unit 2) to receive. I successfully uploaded the code I found online. I uploaded the TX code to UNIT 1 and the RX code to UNIT 2 and had both of them running but I fail to see anything on the serial monitor when I plug in UNIT 2 to usb and examine the serial monitor. I am unsure if my wiring diagram is correct and if this code is correct. On the RX code (UNIT 2 serial monitoring) I do not know what to serial print to see on the serial monitor. These units were discontinued and as a result I cannot find help online.
Materials:
Arduino Mega2560 times 2
RF module: Digi 9Xtend 900 Mhz OEM Module times 2
manual: https://www.sparkfun.com/datasheets/Wireless/Zigbee/xtend-productmanual.pdf
I found a source code library online: GitHub - mswillia/rxtx
Images attached: Wiring diagram, pic of setup
Please let me know what other information needs to be provided and thanks for any and all help. The ultimate goal is to have these numerous units communicate via RF and have one final arduino send via cellular telemetry. This is a hydrological monitoring project.
TX Code
//The data pin for the trainer input
const int inputPin = 18;
//The code is hard-coded for this number of channels.
//I should be able to detect this while decoding the PPM signal though
const uint8_t channels = 6;
//My trainer port output non-inverted logic signals, this may differ.
const int level = HIGH;
int led = 13;
unsigned int offset = 400;
struct RC_Channel {
unsigned int channel[channels];
};
struct RC_Channel rc;
void setup() {
//Our wireless serial device is setup to 57.6k baud
Serial.begin(57600);
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
pinMode(inputPin, INPUT);
}
//Parse the PPM input data
void readTransmitter() {
while(pulseIn(inputPin, level) < 5000);
for (int i = 0; i < channels; ++i) {
rc.channel = pulseIn(inputPin, level) + offset;
-
}*
}
//Encode a frame and write it to the serial output
//Will expand this. Might move to COBS encoding
void sendData() { -
//Our frame header is 0x00 0x00 because it should never come up in our data.*
-
Serial.write((uint8_t)0x00);*
-
Serial.write((uint8_t)0x00);*
-
//Write the number of channels we will send. More important if we dynamicly set the channel count*
-
Serial.write(channels);*
-
//An int is 2 bytes long, so split it and send it over serial*
-
for (int i = 0; i < channels; ++i) {*
_ Serial.write(rc.channel & 0xFF);_
_ Serial.write((rc.channel >> 8) & 0xFF);
* }
}
void loop() {
readTransmitter();
/
* for (int i = 0; i < channels; ++i) {
Serial.print("Channel ");
Serial.print(i);
Serial.print(": ");
Serial.println(rc.channel);
}
/
sendData();_
* //Reset our channel data so in the event a read of the PPM fails we turn things off*
* //Right now this won't happen as the readTransmitter function is a blocking function*
* //This needs to be made better, and receiver side safety should be implemented as well*
* for (int i = 0; i < channels; ++i) {*
_ rc.channel = 0;
* }
}
RX CODE
#include <Servo.h>
const int channels = 6;
int led = 10;
//My trainer port output non-inverted logic signals, this may differ.
const int level = HIGH;
struct RC_Channel {
unsigned int channel[channels];
};
struct RC_Channel rc;
struct RC_Channel defaults;
Servo channel[channels];
void setup() {
//Set up each servo. Currently attached to d2-d8*
* for (int i = 0; i < channels; ++i) {
channel.attach(i+2);
}*_
* pinMode(led, OUTPUT);*
* digitalWrite(led, HIGH);*
* //Our wireless serial device is setup to 57.6k baud*
* Serial.begin(57600);*
* //Default throttle*
* defaults.channel[0] = 500;*
* //Default others*
* for (int i = 1; i < channels; ++i) {*
_ defaults.channel = 1500;
* }*_
* for (int i = 0; i < channels; ++i) {*
rc.channel = defaults.channel*;*
* }*
}
//Wait for the buffer to fill to the specified number of bytes and return the first byte in the buffer
byte blockingRead(unsigned int wait) {
* while (Serial.available() < wait);*
* return Serial.read();*
* //Hackaday Prize Entry: Safety Glasses Are Also Hands-Free Multimeter | Hackaday
}
void loop() {_
* boolean found_frame = false;*
* //Look for the start of a data frame*
* if (Serial.read() == 0x00) {*
* //Check that this really is the start of a data frame*
* if (blockingRead(1) == 0x00) {*
* found_frame = true;*
* //Get the number of channels being transmitted*
* //Note: This is mainly for future use so we won't have to statically set the number of channels*
* int count = blockingRead(1);*
* //Read data for each channel*
* for (int i = 0; i < count; ++i) {*
* int value = blockingRead(2);*
* value |= Serial.read() << 8;*
* Serial.print(value);*
* //Store the value for writing*
_ rc.channel = value;
* }
}
}*_
* //We did not find a data frame, go to a safe mode.*
* if (!found_frame) {
_ for (int i = 0; i < channels; ++i) {_
rc.channel _= defaults.channel;
}
}*_
* //Write values out to servos*
* for (int i = 0; i < channels; ++i) {*
channel_.writeMicroseconds(rc.channel*);
}
}*_