Displej + nRF24L01
Napsal: 07 úno 2021, 11:45
Ahoj všem, mám takový dotaz. Potřeboval bych připojit k desce mini Pro 2,8"displej SPI s řadičem ILI9341 a bezdrátový modul nRF24L01. Jde to vůbec? Děkuji za odpověď.
České fórum pro všechny nadšence do Arduina a dalších technologií.
https://forum.hwkitchen.cz/
Kód: Vybrat vše
/*
Arduino UNO
nRF24L01
.............
:1 3 5 7 :
:o o o o :
:o o o o :
:2 3 6 8 :
: :
: :
: :
: :
:...........:
1 - GND - GND
2 - VCC - 3V3
3 - CE - 9
4 - CSN - 10
5 - SCK - 13
6 - MOSI - 11
7 - MISO - 12
8 - IRQ - NC
*/
#include <SPI.h>
#include <Wire.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define POT 0 // Pin A0 UNO
Adafruit_BME280 bme; // I2C
struct package
{
float temperature ;
float pressure;
float humidity ;
float pressureicao;
float voltage;
};
typedef struct package Package;
Package data;
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup(void)
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
//radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_MAX);
radio.stopListening();
bme.begin(0x76);
}
void loop()
{
readSensor();
radio.write(&data, sizeof(data));
Serial.println("----Test spojení----");
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" ºC");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100); // 100 Pa = 1 millibar
Serial.println(" mb");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.print("Approx altitude = ");
Serial.print(bme.readAltitude(1013.25));
Serial.println(" m");
Serial.print("Voltage = ");
Serial.print(data.voltage);
Serial.println(" V");
Serial.print("--------------------------------\n\n");
delay(3000);
}
void readSensor()
{
data.humidity = bme.readHumidity();
data.temperature = bme.readTemperature();
data.pressure = bme.readPressure() / 100.0;
data.pressureicao = (((bme.readPressure() / 100.0)-8) / pow(1 - ((0.0065 * 241) / (data.temperature + (0.0065 * 241) + 273.15)), 5.257));
// korekce chyby: -8 hPa
data.voltage = analogRead(POT);
data.voltage = data.voltage * 5 / 1024;
}
Kód: Vybrat vše
/*
Arduino UNO
nRF24L01
.............
:1 3 5 7 :
:o o o o :
:o o o o :
:2 3 6 8 :
: :
: :
: :
: :
:...........:
1 - GND - GND
2 - VCC - 3V3
3 - CE - 9
4 - CSN - 10
5 - SCK - 13
6 - MOSI - 11
7 - MISO - 12
8 - IRQ - NC
ST7789 240x240 IPS
o 01 GND -> GND
o 02 VCC -> VCC (jen 3.3V !)
o 03 SCL -> 3/SCK
o 04 SDA -> 4/MOSI
o 05 RES -> 5
o 06 DC -> 6
o 07 BLK -> NC
*/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Arduino_ST7789.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#define TFT_DC 6
#define TFT_MOSI 4
#define TFT_SCLK 3
#define TFT_RST 5
#define SCR_WD 240
#define SCR_HT 240
Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK);
struct package
{
float temperature;
float humidity;
float pressure;
float pressureicao;
float voltage;
};
typedef struct package Package;
Package data;
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup()
{
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
//radio.setDataRate( RF24_250KBPS ) ;
radio.openReadingPipe(0, address);
radio.startListening();
tft.init(SCR_WD, SCR_HT);
tft.fillScreen(BLUE);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(3);
tft.setCursor(22, 5);
tft.print("TEMPERATURE");
tft.setTextSize(2);
tft.setCursor(35, 220);
tft.print("Voltage:");
}
void loop()
{
if (radio.available())
{
radio.read(&data, sizeof(data));
float temperature = data.temperature;
float voltage = data.voltage;
tft.setTextSize(10);
tft.setCursor(0, 85);
tft.print(temperature, 1);
tft.setTextSize(2);
tft.setCursor(135, 220);
tft.print(voltage);
tft.println(" V");
}
Serial.println("----Test spojení----");
Serial.print("Temperature = ");
Serial.print(data.temperature);
Serial.println(" °C");
Serial.print("Voltage = ");
Serial.print(data.voltage);
Serial.println(" V");
Serial.print("--------------------------------\n\n");
delay(1000);
}