We are working on our senior design and one difficulty is having an arduino wirelessly send a a message we preset when pressing a pushbutton.
The message goes to display on an lcd screen connected to a different arduino. We are using two arduinos and tried nrf24l01 modules but we have had poor luck with those.
Can you recommend any tutorial solutions or other wireless communicating devices to transfer text strings.??
Nrf24l01 are easy and cheap modules with decent range. Maybe yours are damaged? Try with simple examples to check if they work.
Other expensive solution is xbee, also easy.
Oh thanks I checked out some of their posts,
The nrf modules work when doing the ping pair example
Also I am on my colleges wifi and the Fenway is Boston Park..
I am trying to modify one example on the forum here is the code compiles but the screen displays only the second string every set # seconds
/*
RadioSend
- CONNECTIONS: nRF24L01 Modules See:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 9
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
Send a series of zeros and ones to the receiver radio.
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
int high[1];
int low[1];
void setup()
{
radio.begin();
radio.openWritingPipe(pipe);
high[0] = 1;
low[0] = 0;
}
void loop()
{
radio.write(high, sizeof(high));
delay(3000);
radio.write(low, sizeof(low));
delay(3000);
}
}
Receiver
/*
RadioReceive
- CONNECTIONS: nRF24L01 Modules See:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 9
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
Receive a series of zeros and ones from the sender radio.
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <SoftwareSerial.h>
#define CE_PIN 9
#define CSN_PIN 10
SoftwareSerial mySerial(8,1); // pin 1 = TX, pin 8 = RX (unused)
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
int received[1];
void setup()
{
pinMode(1,OUTPUT);
mySerial.begin(9600);
delay(500);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}//--(end setup )---
void loop()
{
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
mySerial.write(" "); // clear display
mySerial.write(" ");
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
if ( radio.available() )
{
// Read the data payload until we've received everything
bool done = false;
while (!done)
{
// Fetch the data payload
done = radio.read( received, sizeof(received) );
if (received[0]== 0)
{
mySerial.write("Good Morning"); // print text to LCD
delay(5000);
}
else
{
mySerial.write("I Miss You!"); // print text to LCD
delay(5000);
}
}
}
}
We are working on our senior design and one difficulty is having an arduino wirelessly send a a message we preset when pressing a pushbutton.
The message goes to display on an lcd screen connected to a different arduino.
I don't see any pushbutton in the tranmit code or any lcd in the receive code. If I asssume that the "mySerial" code is for the LCD, that still leaves no pushbutton code in the Tx code. What's up with that ?
The myserial() code is for the LCD because we are using a serial LCD. In that example I was trying to get the transceivers to work without the push-buttons. I wrote a simple code to go from two push-buttons to LCD screen which works below.
The struggle is modifying this with the previous code to transmit the data to the corresponding LCD screen.
#include "nRF24L01.h"
#include "RF24.h"
#include <RF24_config.h>
#include <serLCD.h>
#include <SPI.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
// Attach the serial display's RX line to digital pin 2
SoftwareSerial mySerial(8,1); // pin 1 = TX, pin 8 = RX (unused)
#define buttononePin 6 // first button pin
#define buttontwoPin 7 // second button pin
int button1 = 0; // declares variable for button input values
int button2 = 0; // declares variable for button input values
void setup() {
{
pinMode(buttononePin, INPUT); // declare first button as input
pinMode(buttontwoPin, INPUT); // declare second button as input
mySerial.begin(9600); //set-up serial port
delay(500); // wait for display to boot
}
}
void loop() {
{
button1 = digitalRead(buttononePin); // read first button input value and stores variable
button2 = digitalRead(buttontwoPin); // read second button input value and stores variable
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
mySerial.write(" "); // clear display
mySerial.write(" ");
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
if (button1 == LOW) // if first button pressed
{
mySerial.write("Good Morning!"); // print text to LCD
delay(5000);
}
if (button2 == LOW) //if second button pressed
{
mySerial.write("I miss you! <3"); // print text to LCD
delay(5000);
}
}
}
stramis:
The myserial() code is for the LCD because we are using a serial LCD.
I figured that.
What I was trying to suggest is that you don't use the LCD until you have the Tx and Rx code working - just so that the program is a simple as it possibly can be.
Get things working with the Serial Monitor and then add the LCD stuff later.
The RF24 library has some example sketches, one of which (Remote Leds) monitors switches and lights leds associated with specific switches. You said your NRF24L01 works with the ping pong example (which has a different filename). If it works with that it should work with the switch example. If you use the switch example and combine it with CASE statements, you can send specific LCD messages based on the CASE processing of the received code for lighting the leds (which may be a binary or decimal number that represents the binary value of the switch positions at the Tx end).
As Robin pointed out, you should perform you testing from the bottom up, meaning verify communication first, lcd second. There may be an issue with your use of Tx & Rx pins with the USB cable connected to your computer. I have found that disconnecting the USB and running off external power after loading the sketch solves that issue since the Tx & Rx are linked to the FTDI chip and affected by those outputs.
raschemmel:
There may be an issue with your use of Tx & Rx pins with the USB cable connected to your computer. I have found that disconnecting the USB and running off external power after loading the sketch solves that issue since the Tx & Rx are linked to the FTDI chip and affected by those outputs.
Unfortunately I am waiting on an 9V adapter to test this, but the LED_remote does not seem to work, when i hit either button the serial monitor says:
Now Sending: OK
but on the receiving side, the LED's stay lit the whole time, says got buttons..
Would you know how to troubleshoot this?
The nrf modules work when doing the ping pair example
If the NRF24L01 modules work with one example , they should work with all of them.
The "Remote Leds" example should be the one with six switches at one end and six leds at the Rx end. There is also an example with one or two switches and one or two leds. Are you running the examples with no additional h/w or s/w added to validate the test setup ?
Thanks for all the help, we got a one directional code working with 2 push buttons to the LCD screen. The problem is the radio constantly sends the number we designate when a button is pressed. How do we make it so the receiver only writes to the LCD screen once per button push even with multiple radio firings?!?
I agree with @raschemmel - but if there is a need for an interval between updates don't use delay() - use millis() as illustrated in several things at a time
It is much easier to use millis() right from the start rather than trying to modify the code to replace delay() functions at a later time.
Another option, which eliminates the need for any interval, is to update the LCD only when the data has changed. That way 100 similar messages will only cause one update.
I agree with Robin2, use millis() and update on data change. Try flags first then when that works correctly save it as "FLAGS" then change it to update on data change and compare that with the fiags approach
Thanks for those suggestions! What we ended up doing was adding a simple for loop for the transmit side, so that the receiver side will only read the specific value once per button press.
The next step for us is to make this bi-directional! Unfortunately combining the code does not seem to be a quick solution.. any suggestions there.?!
We do have another pair of nrf24l01 if they should be required.
Transmitter
#include <SoftwareSerial.h>
#include <serLCD.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;
int SW2 = 6;
void setup(void)
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}
void loop(void)
{
if (digitalRead(SW1) == LOW){
for (int x=0;x<4;x++){
msg[0] = x;
radio.write(msg, 1);}
delay(10);
}
if (digitalRead(SW2) == LOW){
for (int x=5;x<9;x++){
msg[0] = x;
radio.write(msg, 1);}
delay(10);
}
}
Reciever
#include <serLCD.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
SoftwareSerial mySerial(8,2); // pin 1 = TX, pin 8 = RX (unused)
void setup(void)
{
mySerial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop(void){
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
mySerial.write(" "); // clear display
mySerial.write(" ");
mySerial.write(254); // move cursor to beginning of first line
mySerial.write(128);
if (radio.available())
{
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 1){delay(100);
mySerial.write("Good Morning!");}
delay(1000);
if (msg[0] == 6){delay(100);
mySerial.write("I Miss You!");}
delay(1500);}
}
}