I2C and nrf24l01 at the same time?

Hi, I'm new in Arduino.

I'm doing a project using a DC motor controller with I2C controlled by an Arduino Mega. I want to add nrf24l01 transceivers to control the DC motor with a potentiometer connected in another arduino wirelessly. Without the I2C cables connected I received the data, but when I connect the I2C cables it stop to receive and the TX led turned off.

Can I use this two transmissions(I2C and nrf24l01) at the same time? I hope I have explained well. Thanks in advance

Hi, welcome to the forum.

Which library do you use for the NRF24L01 ?
Which pins do you use ?
How is it powered ? The ATmega2560 microcontroller on the Arduino Mega 2560 boards likes to have 5.0V, not 4.5V. If you power it with the USB cable only, the voltage might be too low.

The most common problems are a wrong sketch, or not enough power. With I2C and motors, there could be noise from the motors into the I2C wires, that will stop the sketch.

Peter thanks for your reply,

I'm using Mirf library, and is working very well without the I2C, and the I2C is working very well without the nrf24l01 with a preloaded sketch that move the DC for 3 sec and stop for 1 sec, but I want to control it wirelessly with a potentiometer.

With the I2C cables disconnected when I move the potentiometer the serial monitor in the other arduino registers the position of it. When I connect the I2C cables it stop to receive the data. I asked a proffesor and he said that it could be some interruptions or priority for the I2C or the nrf24l01.

But answering your questions, I'm using a Lipo 3C 5000 mah battery for the motors and a 9V battery for the arduino, my pins for the nrf24l01 are
CE -> 48 (defined in sketch)
CSN -> 49 (defined in sketch)
MISO -> 50
MOSI -> 51
SCK -> 52

The Arduino Wire library for I2C uses interrupts, but as far as I know, the NRF24L01 does everything inside the chip, and does not rely on interrupt timing.
The I2C is at pin 20 and 21, that should not conflict with the SPI bus.

A 9V battery to run an Arduino Mega 2560 with NRF24L01 ? That is almost always too weak.
Do you have a DC power supply ? 7.5V or 9V and connect that to the power jack.

I don't know why the I2C is okay without the NRF24L01 and vice versa. There can be so many causes.

Another common problem is this: Suppose you have the I2C motor driver chip on the same breadboard as the NRF24L01, and the ground current of the motor is also going through that breadboard. Some breadboards have bad contacts, and with three different things going on on that breadboard, it can easily fail. Even with only two things (the I2C motor chip and NRF24L01 chip) on the same breadboard, is something that can easily fail. If you have that, try using two breadboards.

If you have really no idea what to do, you can give all the information:

  • The components, with links to them. Is it an official Arduino board, or a clone from Ebay ? Which motor driver ?
  • How old is the Mega board ? Do you use the newest Arduino 1.6.3 ?
  • The full sketch, with links to the libraries that you use. There are for example more than just one Mirf libraries.
  • A photo of your project so that we can see the wiring.
  • Tell us what happens. It stops receiving when you connect the I2C wires ? But the sketch is still running ? What if you connect just one I2C wire ? What happens if you connect the I2C wires when the motors are disconnected.

This might seem over the top. But you have to do many tests to get closer to the cause of the problem. And I would like to know everything, so it will be almost as if I am standing next to your project (scratching my head).

I solved my problem. It was a preloaded sketch of the motor controller the prevents connections with low voltage and I was only making the connections without powering the motol controller, only for test the data in the serial monitor. Peter you were right about the 9V, I was using a 9V alkaline, it works fine at the begining but it discharged and was at 7 volts. But I changed to a power supply and works very well. Excuse my English, my first language is Spanish.

Peter, tomorrow I will give you more information, I'm working in a big project for college using a T'rex Robot Chassis and the T'rex microcontroller. Thanks for your concern and fast reply.