Hi guys and girls!
I'm rather new to arduino handicraft. This is my first bigger project and shortly before finish I'm stuck
Shortly about my project:
I have two devices: one measures weather conditions with a bme280 and transmits it with a nrf24l01, the second receives the information and displays it on an e-ink display.
The first device already works as planned. But I can't make the second one work.
I attach the wiring diagrams of both devices and the program code of the problem-maker. In the actual state it receives the information and processes it. But it does not show it on the display.
I tried the wiring only with the display, it worked then. As I use two SPI devices with some shared Pins I thought of a problem with Chip select (CS). And in fact I detected a problem there with a multimeter. So I did the CS manually. I also tried different ways of powering the circuit. Sadly there is no info about the current consumption of the e-ink display. The sheet only says "TBD".
Used components:
- Controller: wemos d1 mini (both devices)
- Sensor: BME280
- Transmission: NRF24L01
- Display: waveshare e-paper 2.7
Has anyone experience with such a circuit or has an advice for me?
I hope I didn't write to much blabla, if any information is still missing please tell me.
Thank everyone in advance for any advice!
Here is the code. I gues most of the lines aren't problem related as they are only message processing and the screen layout.
#include <SPI.h>
#include "RF24.h"
#include "nRF24L01.h"
#define ENABLE_GxEPD2_GFX 0
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeMonoBold9pt7b.h>
//Fuer NTP
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#define ssid XXX
#define password XXX
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
#if defined (ESP8266)
GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ 15, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
#endif
// Initialisierung fuer Funk
#define CE 16
#define CS 5
RF24 radio (CE, CS);
const byte address[6] = "00001";
int cs_radio = 5;
int cs_screen = 15;
void setup() {
Serial.begin(19200);
delay(100);
Serial.println("Set CS");
pinMode(cs_screen,OUTPUT);
pinMode(cs_radio,OUTPUT);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay (500);
}
Serial.println("WLAN verbunden");
timeClient.begin();
Serial.println("NTP initialisiert");
digitalWrite(cs_radio, LOW);
digitalWrite(cs_screen, HIGH);
//Radio Initialisierung
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
Serial.println("Funkverbindung initialisiert");
digitalWrite(cs_radio, HIGH);
digitalWrite(cs_screen, LOW);
display.init(19200);
Serial.println("Display initialisiert");
}
void loop() {
Serial.println("Loop gestartet");
digitalWrite(cs_radio, LOW);
digitalWrite(cs_screen, HIGH);
if (radio.available()) {
char text[40] = {0};
char str_temp[8] = {0};
char str_press[8] = {0};
char str_hum[8] = {0};
radio.read(&text, sizeof(text));
int counter = 0;
int counter_temp = 0;
int counter_press = 0;
int counter_hum = 0;
Serial.println(text);
for (int i=0; i<=sizeof(text); i++) {
if (text[i]=='/') {
counter += 1;
}
else if (text[i]=='#') {
counter = 3;
}
else {
switch (counter) {
case 0:
str_temp[counter_temp] = text[i];
counter_temp += 1;
break;
case 1:
str_press[counter_press] = text[i];
counter_press += 1;
break;
case 2:
str_hum[counter_hum] = text[i];
counter_hum += 1;
break;
case 3:
i = sizeof(text);
break;
}
}
}
Serial.println(str_temp);
Serial.println(str_press);
Serial.println(str_hum);
Serial.println();
digitalWrite(cs_radio, HIGH);
digitalWrite(cs_screen, LOW);
Serial.println("Pins fuer Display gesetzt");
display.setRotation(1); //0 = hochkant
display.setFullWindow();
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_WHITE);
display.fillScreen(GxEPD_BLACK);
// Kopfzeile
display.drawRect(3,3,258,21, GxEPD_WHITE);
display.drawRect(2,2,260,172, GxEPD_WHITE);
char kopfzeile[] = "Dein aktuelles Wetter";
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(kopfzeile, 0, 0, &tbx, &tby, &tbw, &tbh);
uint16_t x = (display.width() - tbw) / 2;
uint16_t y = 17; //(display.height() + tbh) / 2;
display.setCursor(x, y);
display.print(kopfzeile);
display.setCursor(x,y+120);
char Zeit[] = "Zeit:";
display.print(Zeit);
// Uhrzeit
while (!timeClient.update()){
delay ( 500 );
}
Serial.println(timeClient.getFormattedTime());
int hours = timeClient.getHours();
hours += 2;
int minutes = timeClient.getMinutes();
Serial.println(hours);
Serial.println(minutes);
String zeit = String(hours);
zeit += ":";
if (minutes < 10)
{
zeit += "0";
}
zeit += String(minutes);
display.setCursor(x+150,y+120);
Serial.println(zeit);
char ntptime[10];
zeit.toCharArray(ntptime,zeit.length()+1);
display.print(ntptime);
display.setCursor(x,y+30);
char Temp[] = "Temperatur:";
display.print(Temp);
display.setCursor(x,y+60);
char Druck[] = "Druck:";
display.print(Druck);
display.setCursor(x,y+90);
char LuftF[] = "Luftfeuchte:";
display.print(LuftF);
display.setCursor(x+50,y+30);
display.print(str_temp);
display.setCursor(x+50,y+60);
display.print(str_press);
display.setCursor(x+50,y+90);
display.print(str_hum);
Serial.println("Versuche, Display zu aktualisieren");
display.nextPage();
Serial.println("Display aktualisiert");
}
delay(500);
}