Hallo Leute,
beschäftige mich seit einiger Zeit mit den RFM69 Modulen und arbeite dabei mit der Bibliothek von RadioHead.
Möchte nun die empfangenen Daten auf mein TFT Display (Driver ILI9341) ausgeben.
Bereits bei meinem „Testsketch“ habe ich Probleme das RFM69 Modul und das TFT Display, welche ich beide mit SPI Bus an meinem ESP32 angeschlossen habe, gleichzeitig laufen zu bringen.
#include <Arduino.h>
/* ESP32 RFM69W
GND--------------------------GND (ground in)
VIN--------------------------3.3V (3.3V in)
interrupt D0 pin GPIO17-------DIO0 (interrupt request out)
SS pin GPIO5----------------NSS (chip select in)
SCK SPI pin GPIO18-----------SCK (SPI clock in)
MOSI SPI pin GPIO23----------MOSI (SPI Data in)
MISO SPI pin GPIO19----------MISO (SPI Data out) */
//TFT Display
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
//RFM69
#include <RHReliableDatagram.h>
#include <RH_RF69.h>
#define CLIENT_ADDRESS 2
#define SERVER_ADDRESS 1
// For the Adafruit shield, these are the default.
#define TFT_DC 4
#define TFT_CS 16
#define TFT_RST 2
#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_CLK 18
// Slave Select is GPIO pin 5, interrupt is GPIO pin 17
RH_RF69 driver(5, 17);
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
// Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, SERVER_ADDRESS);
struct messwerte
{
float feuchtigkeit;
float temperatur;
} dht22_sensordaten;
unsigned long testText() {
tft.fillScreen(ILI9341_BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
tft.println(1234.56);
tft.setTextColor(ILI9341_RED); tft.setTextSize(3);
tft.println(0xDEADBEEF, HEX);
tft.println();
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(5);
tft.println("Groop");
tft.setTextSize(2);
tft.println("I implore thee,");
tft.setTextSize(1);
tft.println("my foonting turlingdromes.");
tft.println("And hooptiously drangle me");
tft.println("with crinkly bindlewurdles,");
tft.println("Or I will rend thee");
tft.println("in the gobberwarts");
tft.println("with my blurglecruncheon,");
tft.println("see if I don't!");
return micros() - start;
}
void rfm_initialisierung() {
if (!manager.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
// No encryption
if (!driver.setFrequency(868.0))
Serial.println("setFrequency failed");
// If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
// ishighpowermodule flag set like this:
driver.setTxPower(14, true);
}
void tft_diagnostic() {
// read diagnostics (optional but can help debug problems)
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDMADCTL);
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDPIXFMT);
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDIMGFMT);
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDSELFDIAG);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
Serial.println(F("Benchmark Time (microseconds)"));
delay(10);
Serial.print(F("Text "));
Serial.println(testText());
delay(3000);
Serial.println(F("Done!"));
}
uint8_t data[] = "And hello back to you";
// Dont put this on the stack:
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
void rfm_datenempfang() {
if (manager.available())
{
// Wait for a message addressed to us from the client
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAck(buf, &len, &from))
{
/* Serial.print("got request from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
driver.printBuffer("Got:", buf, len); */
memcpy(&dht22_sensordaten, buf, sizeof(dht22_sensordaten));
Serial.print(dht22_sensordaten.temperatur);
Serial.println("°C");
Serial.print(dht22_sensordaten.feuchtigkeit);
Serial.println("%");
Serial.print("RSSI: ");
Serial.println(driver.lastRssi(), DEC);
// Send a reply back to the originator client
/* if (!manager.sendtoWait(data, sizeof(data), from))
Serial.println("sendtoWait failed"); */
}
}
}
void setup() {
Serial.begin(9600);
while (!Serial)
;
rfm_initialisierung();
tft.begin();
Serial.println("ILI9341 Test!");
tft_diagnostic();
}
void loop(void) {
rfm_datenempfang();
}
Konkret wird auf dem Display leider nichts angezeigt. Die Daten vom RFM69 Modul werden aber empfangen und an die serielle Schnittstelle ausgegeben.
Wenn ich in der setup () Funktion die Funktion rfm_initialisierung() kommentiere funktioniert die Ausgabe des Testextes in der Funktion tft_diagnostic().
Hat jemand von euch eine Ahnung was der Grund meines Problems sein könnte bzw. wo es Interferenzen gibt? Kann eine SPI transaction das Problem sein? Wie könnte ich das Problem beheben?
Vielen Dank bereits im Voraus für eure konstruktive Antworten.