I got it working (sending and receiving numbers), but it is clear I don't understand a part of the code that i copied. Below is the receiver sketch. As I say, it works fine except that if I try to comment out any of the Serial.println commands, or the xyz variable, it stops working. It no longer recognizes changes I make to the transmit data. I don't need them, or want them, but can't figure out how to get rid of them.
// ask_receiver.pde 11/16/19
// -*- 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
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
#include <Arduino.h>
#include <Wire.h>
#include <U8g2lib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h>
#endif
//RH_ASK driver;
RH_ASK driver(1000, 2, 4, 0); // Arduino
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
void setup()
{
#ifdef RH_HAVE_SERIAL
Serial.begin(9600); // Debugging only
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (use I2C scanner to find addresses for I2C devices)
display.clearDisplay();
}
void loop()
{
uint16_t data;
uint16_t xyz = data;
uint8_t datalen = sizeof(data);
if ( driver.recv((uint8_t*)&data, &datalen)
&& datalen == sizeof(data))
{
// Have the data, so do something with it
//uint16_t xyz = data;
} // this } was not included in the example i copied, so i just stuck it in
Serial.println(xyz); // If I comment out this line,or remove xyz, it fails
Serial.println(data);
Serial.println(""); // If I comment out this line, it fails
Serial.println("");Serial.println(""); // If I comment out this line, it fails
delay(100);
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(32,25);
//display.println("Hello,gorld");
display.println(data);
display.display();
delay(100);
display.clearDisplay();
}
From line 950 on of the library, I read and pasted to get things working.
It may be that I goofed things up right off the bat with the {} right after the 'have the data, so do something with it'. that only came with an opening {, and i started guessing where to put the closing bracket, and what to put inside it.
Would someone have a look ?