I plan on building a drone controled by a Leonardo board and control it wireless using another Leonardo. I received them both along with 2 nrf24 as gifts. I am financially limited, that is why i haven't looked for more proper boards.
While testing, I decided to transmit a letter from one of them to the other, the transmitter would be fed by a 9V battery and the receiver would be connected to the PC.
PROBLEM: after programming the Leonardo transmitter, I disconnect it from the PC. When I connect it to the 9V battery, nothing happens, the TX led never lights up. It is as if the programming never went in.
Is this doable? Forget the Drone, I ask if it is possible to programm a Leonardo and make it transmit from a distance on battery.
aimaty:
PROBLEM: after programming the Leonardo transmitter, I disconnect it from the PC. When I connect it to the 9V battery, nothing happens, the TX led never lights up. It is as if the programming never went in.
Which TX LED? Do you wait for Serial to connect, like most Leonardo sketches? That might not work when you don't have it connected to a USB host.
The 9V is a 6lr61, I use them to run DC motors. it can habdle the arduino well enough.
I din't understand the question. "If I wait for the serial to connect", do you mean the serial from the receiver? I simply open up the dialog box to watch what comes up.
The code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "printf.h"
typedef struct{
int lumi;
const char charlumi[13]="Luminosidade";
}sensorII;
int x;
int CE = 7;
int CSN = 8;
RF24 radio(CE, CSN);
const uint64_t pipe1 = 0xE8E8F0F0A3LL;
void setup(){
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipe1);
radio.setRetries(15, 15);
}
void loop(){
sensorII Y;
x=3;
Y.lumi=x;
Serial.println(Y.charlumi);
radio.stopListening();
int msg[1]={10};
radio.write(msg,sizeof(int));
radio.write(&Y, sizeof(Y));
delay(2000);
}
I've got an extra cable and can now connect them both at the same time to the PC, using com 5 and a com 9.
Before moving to the remote I believe I should get them to communicate. But even first, i want to see if the nrf24s are working.
Here I get a problem too. I used the following code and the only message i obtain in each serial is 444444444444444 a lot of times, always repeating:
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
/**
* Channel scanner
*
* Example to detect interference on the various channels available.
* This is a good diagnostic tool to check whether you're picking a
* good channel for your application.
*
* Inspired by cpixip.
* See http://arduino.cc/forum/index.php/topic,54795.0.html
*/
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
//
// Hardware configuration
//
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
//
// Channel info
//
const uint8_t num_channels = 128;
uint8_t values[num_channels];
//
// Setup
//
void setup(void)
{
//
// Print preamble
//
Serial.begin(57600);
printf_begin();
printf("\n\rRF24/examples/scanner/\n\r");
//
// Setup and configure rf radio
//
radio.begin();
radio.setAutoAck(false);
// Get into standby mode
radio.startListening();
radio.stopListening();
// Print out header, high then low digit
int i = 0;
while ( i < num_channels )
{
printf("%x",i>>4);
++i;
}
printf("\n\r");
i = 0;
while ( i < num_channels )
{
printf("%x",i&0xf);
++i;
}
printf("\n\r");
}
//
// Loop
//
const int num_reps = 100;
void loop(void)
{
// Clear measurement values
memset(values,0,sizeof(values));
// Scan all channels num_reps times
int rep_counter = num_reps;
while (rep_counter--)
{
int i = num_channels;
while (i--)
{
// Select this channel
radio.setChannel(i);
// Listen for a little
radio.startListening();
delayMicroseconds(128);
radio.stopListening();
// Did we get a carrier?
if ( radio.testCarrier() )
++values[i];
}
}
// Print out channel measurements, clamped to a single hex digit
int i = 0;
while ( i < num_channels )
{
printf("%x",min(0xf,values[i]&0xf));
++i;
}
printf("\n\r");
}
I'm following maniac bug's instructions to connect the nrf24, not to the SPI (I think), but to the analog pins on the Leo board. Are the SPI those 6 pins (2x3) at the bottom?
Isn't the voltage coming out of the SPI 5V? The nrf24 works on 3,3V or...?
I'm going to try those instructions, just hope to have the necessary items around.
I just tried the code with my Leonardo and with the Uno pin connections - it does not work. It seems that on the Leonardo the SPI connections are only available on the ICSP header - the 6 pins at the rear of the board. I don't have any simple connector for that at the moment.
I presume the NRF24 will work fine on a Leonardo with the appropriate connections. Be careful, however, because the Vcc on the 6 pins is 5v and you need 3.3v for the NRF24.
I might wire up another NRF24 to work with the ICSP connections tomorrow.
At last, we know what's wrong here. Very good. I suppose this is the only downfall with arduino stuff, there is just way too many variations of hardware, no standardization.
My next step is equating if there is a more standardized option to arduino (maybe raspberry suffers from this same evil).
Perhaps I should just let this go, since I also do not enjoy all the hassle with the coding, too many things to know. I'm just disapointed, I guess.
I'll also try to get in touch with Maniac Bug, see if he has any recomendation on the pin configuration.
Many thanks to you! Without your valuable contribution, i might have ended up wasting time and patience hitting a solid wall.
aimaty:
At last, we know what's wrong here. Very good. I suppose this is the only downfall with arduino stuff, there is just way too many variations of hardware, no standardization.
I do think they have done their best at hardware standardization - it's just that the 32U4 MCU in the Leonardo is very different. And I guess it was chosen primarily because it includes USB stuff inside it and does not need extra parts for USB as the Atmega 328 does.
And AFAIK the pinouts on the ICSP pins are standard on all the boards. So if you wire your NRF24 to work with the ICSP pins on a Leonardo it should also work with those pins on an Uno or Mega.
I have now reorganized my connections for one of my NRF24s to use the ICSP header and it works on my Uno and on my Leonardo.
I can now make my two radios communicate while connected to the PC, so I can return to the original problem envolving using the radios remotely, on battery.
You really believe it is not possible due to the type of battey (9V 6LR61)? I also have 2 large 4,5V batteries which I can connect in series.
I'll be trying out some code which does not require pressing any buttons to change roles.