Using library for a chip embedded in Arduino

I recently acquired an Arduino Primo, which comes packed with a ton of IoT-related chips. Among other stuff, it has embedded an Esp8266 wifi microchip and a Nordic nRF52 processor (with bluetooth, nfc and a 2.4Ghz transceiver) I am trying to make a 2.4 Ghz remote controller of a cheap drone communicate with the Arduino through either the Esp8266 or the nRF52 chips.

Since I have not access to the specs and datasheet of the remote controller I intend to reverse-engineer the protocol it uses and then program the arduino accordingly. To get the signal from the controler I need to listen to it from a chip in "promiscuous mode", that is checking all frequencies around 2.4 to find in which one it sends the data. I am following some tutorials. Concretely:

-This one for the nRF24L01 chip which is fully compatible with the nRF52 as seen here -This one for the Esp8266.

My problem is, when installing the Arduino libraries for programming these chips I cant compile and run them on my Arduino Primo, even though they are embedded. How do I tell the Arduino to refer the code to any of those microchips?

Why do you say you can't compile them? What code are you attempting to compile and what error messages do you receive?

What gives you the idea that the NRF52 can act like an NRF24? I thought the NRF52* chips were wireless enabled microcontrollers, not just trancievers like the NRF24?

The nrf52 can work as a nfr24 among other things. I forgot to put the link, the question is updated now.

I am trying to compile and run this code (for nrf52) and this code for the esp8266.

I select Arduino Primo as my board, and of course it fails to compile. When selecting ESP8266 as board it fails also...

What gives the idea that it's failing to compile? Do you get an error message? If so what?

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :)

juanluisrto: I am trying to make a 2.4 Ghz remote controller of a cheap drone communicate with the Arduino through either the Esp8266 or the nRF52 chips.

Wouldn't it make a lot more sense to start with a simple Arduino Uno and an nRF24L01+ module for which there are lots of tutorials and lots of people with experience to help you.

Keep the complex device for some task that requires its capabilities.

...R

I found the code here. Now it compiles and launches with a few modifications, but it is still not working. It is probably due to the initialization of the
RF24 myRF24(9, 10); which asks for the chip enable and select for the nrf24L01 (or nRF52 in my case, since it is compatible) as explained here

My circuit is just de Arduino Primo connected to the computer.

The code looks like this.

#include "RF24.h"
#include "printf.h"

// print mode is a bit over-done, but will be paying off in future versions, 
// when other print modes like printing values and such come in
#define PRINT_MODE_BYTES 0
#define PRINT_MODE_BITS 1
#define PRINT_MODE_COUNT 2

// had two boards for testing, one UNO and a Mega2560
// and was too lazy to comment / uncomment all the time
//#if defined(__AVR_ATmega2560__)
//	RF24 myRF24(49, 53);
//#elif defined(__AVR_ATmega328P__)
//	RF24 myRF24(9, 10);
//#endif

RF24 myRF24(9, 10); // Im suppossed to initialize this to the pins attached to chip enable and select. But the chip is embedded so I don't know which one should I choose.

// buffer for reading incoming messages
const uint8_t maxBufferSize = 32;
uint8_t myBuffer[maxBufferSize];
uint8_t bufferSize = 16;

// channel to listen to
uint8_t channel = 60;

// there are two address modes: 0x55 and 0xAA
boolean addressMode = true;

// there are (presently) two print modes: bits and bytes
uint8_t printMode = 0;

// some flags for the state
boolean isRunning = false;
boolean isListening = false;

// for a heartbeat to show that the program is still running
// when there is no transmissions
boolean hasHeartbeat = false;
uint8_t heartbeatCounter = 0;
long timer;
long timerThreshold = 1000;


// initialize buffer
void initBuffer() {
	memset(myBuffer, 0, bufferSize);
} // void initBuffer() {


void setup() {
	// use high speed serial
	Serial.begin(250000);

	// needed for the "printDetails()"
	printf_begin();
	

	initBuffer();

	// start the radio
	myRF24.begin();


	myRF24.setChannel(channel);

	// disable error control features
	myRF24.disableCRC();

	// disable sending out acknowledge messages
	myRF24.setAutoAck(false);


	myRF24.setDataRate(RF24_1MBPS);


	myRF24.setAddressWidth(3);

	// print out the radio settings
	myRF24.printDetails();

	Serial.println("OK.");
} // void setup() {


// print only zeroes and ones
void printBits() {
	// initialize output string
	String readerStr = "";

	for (int i=0; i < bufferSize; i++) {
		for (int j=0; j<7; j++) {
			readerStr += (((myBuffer[i] << j) & 128)?1:0) + " ";
		} // for (int j=0; j<8; j++) {
		
		// no need for a delimiter at the end of the last bit
		readerStr += (((myBuffer[i] << 7) & 128)?1:0);
	} // for (int i=0; i < bufferSize; i++) {

	// output of the string
	Serial.println(readerStr);
} // void printBits() {


// print the bytes
void printBytes() {
	// initialize output string
	String readerStr = "";

	// loop through the buffer
	for (int i=0; i < bufferSize - 1; i++) {
		// leeding spaces to make things look nicers
		if (myBuffer[i] < 10) {
			readerStr += "  ";
		} else if (myBuffer[i] < 100) { // if (myBuffer[i] < 10) {
			readerStr += " ";
		} // else if (myBuffer[i] < 100) {

		// add a byte and a delimiter
		readerStr += String(myBuffer[i]) + " ";
	} // for (int i=0; i < bufferSize - 1; i++) {
	
	// no need for a delimiter at the end of the last byte
	readerStr += String(myBuffer[bufferSize - 1]);
  
	// output of the string
	Serial.println(readerStr);
} // void printBytes() {


// toggle between the two addresses 0x55 and 0xAA
void toggleAddress() {
	if(isListening) {
		myRF24.stopListening();
	} // if(isListening) {
	
	if(addressMode) {
		// DEC 170
		// BIN 10101010
		myRF24.openReadingPipe(0, 0xAA);
		myRF24.openReadingPipe(1, 0xAA);
	} else { // if(addressMode) {
		// DEC 85
		// BIN 01010101
		myRF24.openReadingPipe(0, 0x55);
		myRF24.openReadingPipe(1, 0x55);	
	} // } else { // if(addressMode) {
	
	addressMode != addressMode;
	
	if(isListening) {
		myRF24.startListening();
	} // if(isListening) {
} // void toggleAddress() {


void loop() {
	// are we in running mode?
	if(isRunning) {
		// are we listening?
		if(!isListening) {
			// if no, then start it
			myRF24.startListening();
			isListening = true;
		} // if(!isListening) {

		// heartbeat, prints a dot every second to show we're still alive, might as well be a blinking LED
		if (hasHeartbeat) {
			// get the present time
			timer = millis();

			// stay here until there is an incoming transmission or the timer is up
			while (!myRF24.available() && ((millis() - timer) < timerThreshold)) {
				asm("nop");
			} // while (!myRF24.available() && ((millis() - timer) < timerThreshold)) {

			// print a dot and after each 10 dots add a new line
			if (heartbeatCounter++ >= 10) {
				Serial.println(".");
				heartbeatCounter = 0;
			} else { // if (heartbeatCounter++ >= 10) {
				Serial.print(".");
			} // } else { // if (heartbeatCounter++ >= 10) {
		} // if (hasHeartbeat) {

		// minimal approach:
		// if there is anything available
		// read it
		// print it
		// initialize buffer
		if (myRF24.available()) {
			// read it
			myRF24.read(myBuffer, bufferSize);

			// print it
			switch(printMode) {
				case(PRINT_MODE_BYTES):
					printBytes();
					break;
				case(PRINT_MODE_BITS):
					printBits();
					break;
			} // switch(printMode) {

			// initialize buffer
			initBuffer();
		} // if (myRF24.available()) {

	} else { // if(isRunning) {
		// are we listening?
		if(isListening) {
			// if yes, then stop it
			myRF24.stopListening();
			isListening = false;
		} // if(isListening) {
	} //  else { // if(isRunning) {
	
	// get some user input
	// a			toggle address between 0x55 and 0xAA
	// b+ / b-		increase / decrease buffer size
	// h			toggle heartBeat
	// p			toggle print mode (bits / bytes)
	// s			start / stop
	if(Serial.available()) {
		// check first char
		char inChar = Serial.read();

		if (inChar == 'a') {
			toggleAddress();

		} else if (inChar == 'b' && Serial.available()) { // if (inChar == 'a') {
			// check second char
			inChar = Serial.read();

			if (inChar == '+') {
				if (bufferSize < maxBufferSize) {
					bufferSize++;
				} // if (bufferSize < maxBufferSize) {
			} else if (inChar == '-') { // if (inChar == '+') {
				if (bufferSize > 0) {
					bufferSize--;
				} // if (bufferSize < maxBufferSize) {
			} // else if (inChar == '-') { // if (inChar == '+') {

		} else if (inChar == 'p') { // if (inChar == 'a') {
			if (printMode < PRINT_MODE_COUNT) {
				printMode++;
			} else { // if (printMode < PRINT_MODE_COUNT) {
				printMode = 0;
			} // } else { // if (printMode < PRINT_MODE_COUNT) {

		} else if (inChar == 'h') {
			hasHeartbeat = !hasHeartbeat;

		} else if (inChar == 's') { // if (inChar == 'a') {
			isRunning = !isRunning;

		} // if (inChar == 'a') {
	} // if(Serial.available()) {
}

I bought the Primo thinking that it would be fairly easier to program its embedded microcontrollers than if they were added externaly. It doesnt appear to be the case, but the Primo is what I have now.

In the other hand, I think my question is more general. Since I am completely new to Arduino I suspect that I am missing something important. I guess that there are many boards with in-built chips and microcontrollers. Isn't there supossed to be a fairly easy way to program them using the libraries created especifically for those chips?

Thanks for your help

This Simple nRF24L01+ Tutorial may help. I know it works on an Uno and on a Mega and Leonardo with suitable allowance for the different location of the SPI pins. However I have no idea whether it will work with your board.

...R

Hi, Have you read this link?

https://store.arduino.cc/usa/arduino-primo

Read the documentation and down load the Schematic, it will show you how the different components are connected.

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom... :)