Sorry for the long radio silence (pun intended) from me. I've only now gotten a chance to try the suggestions. Unfortunately I still have no positive results to report, but I have implemented some suggestions and am looking for more.
Suggestions I implemented:
- Commented out the pinMode(pin, INPUT_PULLUP); line per iwanders since I switched to RadioHead.
- Connected the reset pin on the radio to digital pin 6 on Teensy 3.2 (both client and server boards)
- Added reset coding to the top of the setup for both server and client
- Changed frequency in the setup code from 433.0 to 915.0 to correspond to the RFM69HCW I'm using.
(By the way, I do have a 78 mm long wire antenna connected to each board.)
Here's my current rf69_server code:
Code:
// rf69_server.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing server
// with the RH_RF69 class. RH_RF69 class does not provide for addressing or
// reliability, so you should only use RH_RF69 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf69_client
// Demonstrates the use of AES encryption, setting the frequency and modem
// configuration.
// Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/
// Tested on miniWireless with RFM69 www.anarduino.com/miniwireless
#include <SPI.h>
#include <RH_RF69.h>
// Singleton instance of the radio driver
RH_RF69 rf69;
void setup()
{
// Perform a hardware reset per iwanders. The reset pin on the RFM69HCW is set to Teensy 3.2 digital pin 6
pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
delayMicroseconds(150); // pull high for > 100 uSec
pinMode(6, INPUT); //release
delay(10); // wait 10 milliseconds before SPI is possible
// end of reset
Serial.begin(9600);
// Previously added delay may be unnecessary now:
while (!Serial && (millis() <= 8000));
Serial.println("Hello World");
// pinMode(2, INPUT_PULLUP); // Removed per iwanders
Serial.println("rf69_server set up complete.");
// End of my addition
if (!rf69.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
// No encryption
if (!rf69.setFrequency(915.0)) // Changed original line from 433.0 to 915.0
Serial.println("setFrequency failed");
// If you are using a high power RF69, you *must* set a Tx power in the
// range 14 to 20 like this:
rf69.setTxPower(14); // I uncommented this line.
// The encryption key has to be the same as the one in the client
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);
#if 0
// For compat with RFM69 Struct_send
rf69.setModemConfig(RH_RF69::GFSK_Rb250Fd250);
rf69.setPreambleLength(3);
uint8_t syncwords[] = { 0x2d, 0x64 };
rf69.setSyncWords(syncwords, sizeof(syncwords));
rf69.setEncryptionKey((uint8_t*)"thisIsEncryptKey");
#endif
}
void loop()
{
if (rf69.available())
{
// Should be a message for us now
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf69.recv(buf, &len))
{
// RF69::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
// Serial.print("RSSI: ");
// Serial.println(rf69.lastRssi(), DEC);
// Send a reply
uint8_t data[] = "And hello back to you";
rf69.send(data, sizeof(data));
rf69.waitPacketSent();
Serial.println("Sent a reply");
}
else
{
Serial.println("recv failed");
}
}
}
Here's my current rf69_client code:
Code:
// rf69_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF69 class. RH_RF69 class does not provide for addressing or
// reliability, so you should only use RH_RF69 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf69_server.
// Demonstrates the use of AES encryption, setting the frequency and modem
// configuration
// Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/
// Tested on miniWireless with RFM69 www.anarduino.com/miniwireless
#include <SPI.h>
#include <RH_RF69.h>
// Singleton instance of the radio driver
RH_RF69 rf69;
void setup()
{
// Perform a hardware reset per iwanders. The reset pin on the RFM69HCW is set to Teensy 3.2 digital pin 6
pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
delayMicroseconds(150); // pull high for > 100 uSec
pinMode(6, INPUT); //release
delay(10); // wait 10 milliseconds before SPI is possible
// end of reset
Serial.begin(9600);
// Previously added delay may be unnecessary now:
while (!Serial && (millis() <= 8000));
Serial.println("Hello World");
// pinMode(2, INPUT_PULLUP); // Removed per iwanders
Serial.println("rf69_client set up complete.");
// End of my additions
if (!rf69.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
// No encryption
if (!rf69.setFrequency(915.0)) // Changed original line from 433.0 to 915.0
Serial.println("setFrequency failed");
// If you are using a high power RF69, you *must* set a Tx power in the
// range 14 to 20 like this:
rf69.setTxPower(14); // I uncommented this line.
// The encryption key has to be the same as the one in the server
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);
}
void loop()
{
Serial.println("Sending to rf69_server");
// Send a message to rf69_server
uint8_t data[] = "Hello World!";
rf69.send(data, sizeof(data));
rf69.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf69.waitAvailableTimeout(500))
{
// Should be a reply message for us now
if (rf69.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf69_server running?");
}
delay(400);
}
Results of the radio reset pin connection to pin 6 and the revised code above is still only:
Server, COM5:
Code:
Hello World
rf69_server set up complete.
and Client, COM4 (same computer):
Code:
Hello World
rf69_client set up complete.
Sending to rf69_server
At one point I did receive the message "No reply, is rf69_server running?" but was unable to duplicate it again. As KurtE mentioned previously, once in a while the COM port in which I expect to see the server message prints the client message, or vice versa. When debugging I usually unplug the USBs from both boards, connect the server and program it first, and then connect the client and program it second. Is this recommended procedure?
@iwanders: What is the correct way to include the printRegisters() method? For a start, I inserted rf69.printRegisters(); in the setup after line rf69.setEncryptionKey(key); and then attempted to compile. I received an error stating 'Class RH_RF69' has no member named 'printRegisters'.
@iwanders: You mentioned that the line pinMode(pin, INPUT_PULLUP) is in the RadioHead library's init method and therefore I don't need to include it in my setup. Since I'm new to this, would you please tell me specifically where I should find it?
Where exactly should the RH_RF69.h code be located? I found it on my machine in directory
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\RadioHead\
The first time I compile the sketches, I receive the warning messages below. When I subsequently compile the same sketch in the same window again, I receive no warnings. Is this something I need to be concerned about?
Code:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\RadioHead\RHSoftwareSPI.cpp: In member function 'virtual void RHSoftwareSPI::begin()':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\RadioHead\RHSoftwareSPI.cpp:114:13: warning: variable 'delayCounts' set but not used [-Wunused-but-set-variable]
uint8_t delayCounts;
^
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\RadioHead\RHSoftwareSPI.cpp: In member function 'void RHSoftwareSPI::delayPeriod()':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\RadioHead\RHSoftwareSPI.cpp:162:39: warning: 'count' is used uninitialized in this function [-Wuninitialized]
for (volatile uint8_t count; count<_delayCounts; count++)
^
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\RadioHead\RH_ASK.cpp: In member function 'void RH_ASK::timerSetup()':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\RadioHead\RH_ASK.cpp:161:14: warning: unused variable 'nticks' [-Wunused-variable]
uint16_t nticks; // number of prescaled ticks needed
^
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\RadioHead\RH_ASK.cpp:162:13: warning: unused variable 'prescaler' [-Wunused-variable]
uint8_t prescaler; // Bit values for CS0[2:0]
^
Sketch uses 24,600 bytes (9%) of program storage space. Maximum is 262,144 bytes.
Global variables use 4,960 bytes (7%) of dynamic memory, leaving 60,576 bytes for local variables. Maximum is 65,536 bytes.
Is there anything inside the RH_RF69.cpp or RH_RF69.h that I need to modify?
Considering tinman's statement about power, do I need to worry about having enough power from the 3.3V pin of the Teensy 3.2?