Using Leonardo remotely on battery

Greetings.

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.

Manu Thanks

A PP3 style 9v battery is pretty much useless for powering and Arduino.

A pack of 6 AA cells should work fine.

...R

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.

Show your transmitter sketch.

  1. The 9V is a 6lr61, I use them to run DC motors. it can habdle the arduino well enough.

  2. 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);
    }

Thank you

I had assumed your comment

PROBLEM: after programming the Leonardo transmitter, I disconnect it from the PC. When I connect it to the 9V battery, nothing happens,

meant that it did work while the Leonardo was connected to the PC and would not work when powered by battery.

Is that correct or was I jumping to conclusions ? ?

...R

If you are not using Serial then you might want to comment out the Serial.begin(9600);

Thanks for your continued support, both of you.

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");
}

A few days ago I got my NRF24s to work first time with the instructions here

I connected the two NRF24s to two Unos.

You might need to check that the SPI pins are the same on a Leonardo as on an Uno. I will try to remember to try one of mine on my Leonardo tonight.

...R

Greetings!

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.

Just retried, and still the same result. On the transmitter serial I get:

*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK Now sending 241096...ok...Got response 4294967295, round-trip delay: 241099 Now sending 242100...ok...Got response 4294967295, round-trip delay: 242103 Now sending 243103...ok...Got response 4294967295, round-trip delay: 243105 Now sending 244106...ok...Got response 4294967295, round-trip delay: 244109 Now sending 245109...ok...Got response 4294967295, round-trip delay: 245112 Now sending 246113...ok...Got response 4294967295, round-trip delay: 246116 Now sending 247116...ok...Got response 4294967295, round-trip delay: 247118 Now sending 248120...ok...Got response 4294967295, round-trip delay: 248122 Now sending 249122...ok...Got response 4294967295, round-trip delay: 249125 Now sending 250126...ok...Got response 4294967295, round-trip delay: 250129 Now sending 251129...ok...Got response 4294967295, round-trip delay: 251132 Now sending 252133...ok...Got response 4294967295, round-trip delay: 252135 Now sending 253135...ok...Got response 4294967295, round-trip delay: 253138

Which is not right, cuz the delay keeps increasing and the response is always the same, very diferente from the Maniac Bug's website results.

On the receiver side I get:

Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...Sent response. Got payload 4294967295...

Weird. I bet these radios are broken.

aimaty: Weird. I bet these radios are broken.

Unless you did something silly with the wiring that is unlikely.

Post the code you are using - from your .ino files, not from any examples that you may be copying

...R

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.

...R

Very very well done!

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.

Best Regards

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.

...R

You are a project saviour!

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.

I don't know what a 6LR61 battery is. I was only commenting on the unsuitablity of the small PP3 style 9v batteries.

Yesterday I plugged my Uno into a pack of 6 AA cells and the NRF24 worked fine.

...R

6LR61 is same as PP3.