I am trying to send a value of an integer to the other Arduino using the nrf2401 radio component, I was following a tutorial and it showed that the integer had to be made on both arduinos. I set them both as zero and after the parameters needed for the integer to change are met on the transmitter, the new value does not appear on the receiver serial monitor.
Please post the Tx and Rx sketches, using code tags when you do
Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
#include <stdint.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
// these pins define the pins being used by the Arduino^^
#define TS_MINX 118
#define TS_MINY 106
#define TS_MAXX 950
#define TS_MAXY 933
#define YP A3
#define XM A2
#define YM 9
#define XP 8
// this code calibrates the screen
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define MINPRESSURE 10
#define MAXPRESSURE 1000
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// these define the pins used to activate the screen, i believe that the 300 is the Maximum resistence of the screen
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xf81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//transmitter
RF24 radio(10, 7); // CE, CSN
const byte address [6] = ("TEXTC");
int currentscreen = 0;
bool Camera = 0;
bool tracker = false;
bool Homevar = false;
bool backbutton = 1;
bool welcome = true;
int button = 0;
//bool button = false;
// A touch variable that will switch depending on parameters for radio communication
void Home() {
tft.fillScreen(RED);
tft.setCursor(60, 100);
tft.setTextSize(2);
tft.print("CHOOSE APPLICATION");
tft.fillRect(10, 10, 75, 75, BLUE);
tft.fillRect(125, 10, 75, 75, BLUE);
tft.fillRect(240, 10, 75, 75, BLUE);
// creating buttons for applications, first test out using LED's
}
void Welcome() {
tft.fillScreen(WHITE); //WHat to fill the screen colour with- colours stated above
tft.drawRect(0, 0, 319, 240, WHITE); //the rectangularshape that the screen fills
tft.setCursor(5, 5); //set cursor is where text will begin on the screen, top right corner of the text
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("WELCOME LKAT");
//add parameters
tft.fillRect(50, 180, 210, 40, BLACK);
tft.drawRect(50, 180, 210, 40, GREEN);
tft.setCursor(60, 190);
tft.setTextColor(WHITE);
tft.setTextSize(2);
}
void LEDB() {
tft.setCursor(5, 5);
tft.fillScreen(BLUE);
tft.print("HELLO");
}
void LEDR() {
tft.setCursor(5, 5);
tft.fillScreen(RED);
tft.print("HELLO");
}
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);//00001
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(3); //changing this value between 1 and 0 will change the layout of the text on screen. landscape portarait
currentscreen = 0;
Welcome();
}
bool buttonPressed(const int x, const int y, const int buttonX, const int buttonY, const int buttonWidth, const int buttonHeight) {
return ( (x >= buttonX) && (x <= buttonX + buttonWidth) && (y >= buttonY) && (y <= buttonY + buttonHeight) );
}
void loop() {
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
const char txt []= "Connection made";
radio.write(&txt, sizeof(txt));
delay(1000);
if (p.z > ts.pressureThreshhold) {
Serial.print("\tPressure = "); Serial.println(p.z);
int y = map(p.x, TS_MINX, TS_MAXX, 0, 240);
int x = map(p.y, TS_MINY, TS_MAXY, 0, 320);
button = 1;
radio.write(&button, sizeof(button));
// delay(1000);
if (welcome == true) {
if (currentscreen == 0 ) {
if (buttonPressed(x, y, 50, 180, 210, 40)) {// x and y map variables and then the starting x,y coordinate and then width and then hieght
currentscreen = 1;
welcome = false;
Homevar = true;
Home();
}
}
}
if (currentscreen == 1) {
if( Homevar == true && welcome == false){
if (buttonPressed(x, y, 10, 10, 75, 75)) {// starting xy coord and then width and height
LEDB();
currentscreen=2;
//if(currentscreen==2 && buttonPressed(x,y,0,0,319,240)){//tft.darwRect(0,0,319,240);
}
else if (buttonPressed(x, y, 125, 10, 75, 75)) {
LEDR();
currentscreen=3;
}
else if (buttonPressed(x, y, 240, 10, 75, 75)) {
tft.fillScreen(GREEN);
currentscreen=4;
if(currentscreen=4 ){
}
}
}
}
}
}
Reciever
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define led 10
RF24 radio(7, 8); // CE, CSN
const byte address [6] = ("TEXTC");
int button = 0 ;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0,address);//00001
radio.setPALevel(RF24_PA_MIN);
//radio.startListening();
// tells the module to stop listening out for code, this sets it up as a transmitter
pinMode(led, OUTPUT);
}
void loop() {
radio.startListening();
while (!radio.available());
char txt[32] = "" ;
radio.read(&txt, sizeof(txt));
radio.read(&button,sizeof(button));
Serial.println(button);
//digitalWrite(led, HIGH);
if (button==1){
Serial.println(txt);
}```
Which Arduino boards are you using ?
The transmitter is using a Arduino Uno and the receiver is a elegoo mega
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.