Qs: Simple wireless communication over a 3 meter range

Does anyone know how I can model the SparkFun Nordic Fob on Proteus ISIS Professional 7?

I already ordered two Nordic Fobs and AVR ISP programmer, but I want to be able to simulate the fob and get some programming done before I get the hardware.

Thaer:
Does anyone know how I can model the SparkFun Nordic Fob on Proteus ISIS Professional 7?

Unless you can find a SPICE model for the NRF24L01 wireless chip, I think simulating the wireless connection will be tricky.

Steve’s suggestion of connecting the UARTs of 2 devices to allow modelling without the wireless link is good, but I don’t think applicable in this case (the connection to the wireless chip is via SPI rather than UART).

You could just simulate the ATTINY24, and put a virtual logic analyser to check what it’s outputting. You should also be able to inject a signal to the SPI port. I wouldn’t bother spending too much time with simulation, since there’s no substitute for using real hardware.

MichaelN:

Thaer:
Does anyone know how I can model the SparkFun Nordic Fob on Proteus ISIS Professional 7?

Unless you can find a SPICE model for the NRF24L01 wireless chip, I think simulating the wireless connection will be tricky.

Steve’s suggestion of connecting the UARTs of 2 devices to allow modelling without the wireless link is good, but I don’t think applicable in this case (the connection to the wireless chip is via SPI rather than UART).

You could just simulate the ATTINY24, and put a virtual logic analyser to check what it’s outputting. You should also be able to inject a signal to the SPI port. I wouldn’t bother spending too much time with simulation, since there’s no substitute for using real hardware.

Thank you Micheal for your valuable input. I appreciate it.

Just out of curiosity, how small of a stand alone “fob” can I build ? Can I squeeze one into a 2x2X(.3) cm box? (I may need this later on in the project)

Thaer:
Just out of curiosity, how small of a stand alone “fob” can I build ? Can I squeeze one into a 2x2X(.3) cm box? (I may need this later on in the project)

The existing fob PCB would easily fit into a 2" X 2" size box, but the thickness is an issue due to the battery thickness.

MichaelN:

Thaer:
Just out of curiosity, how small of a stand alone “fob” can I build ? Can I squeeze one into a 2x2X(.3) cm box? (I may need this later on in the project)

The existing fob PCB would easily fit into a 2" X 2" size box, but the thickness is an issue due to the battery thickness.

Sorry, what I meant is… if I completely rebuilt the fob (pcb, electronic components, battery container, etc…), is it technically possible to fit it into a 2 cm x 2 cm x .3 cm box ?

Thaer:
Sorry, what I meant is… if I completely rebuilt the fob (pcb, electronic components, battery container, etc…), is it technically possible to fit it into a 2 cm x 2 cm x .3 cm box ?

Yep, that's what I figured. What I was trying to say is that the thickness will depend on what battery you can find. While some batteries are thinner than 3mm, it will be a challenge to achieve the required thickness when a case is added. The PCB itself won't take up much space, although you need to allow suitable room for the antenna that's etched into the PCB. If in doubt, just copy the layout of the existing fob.

MichaelN:

Thaer:
Sorry, what I meant is… if I completely rebuilt the fob (pcb, electronic components, battery container, etc…), is it technically possible to fit it into a 2 cm x 2 cm x .3 cm box ?

Yep, that's what I figured. What I was trying to say is that the thickness will depend on what battery you can find. While some batteries are thinner than 3mm, it will be a challenge to achieve the required thickness when a case is added. The PCB itself won't take up much space, although you need to allow suitable room for the antenna that's etched into the PCB. If in doubt, just copy the layout of the existing fob.

Thanks Micheal. This’s a good news! Another quick question, which one of these tutorials best fit the Nordic FOB and the AVR ISP Programmer

nRF24L01 Tutorials

Tutorial 0

Tutorial 1 (LPC2148)

Tutorial 1 (PIC18F452)

Tutorial 2 (LPC2148)

Tutorial 2 (PIC18F452)

Tutorial 3 (LPC2148)

Tutorial 3 (PIC18F452)

Tutorial 4 (LPC2148)

Tutorial 4 (PIC18F452)

Guest Tutorials

BASCOM-AVR and nRF24L01?

Source: http://blog.diyembedded.com/

Hello everyone,

I’m very excited today as I got all the components and tools that I need to start working on my first electronics/wireless project (See previous posts in this thread).

I’m hoping that the experts on SparkFun will guide me through this experiment. Micheal N. and Steve have been extremely generous with helping me through the first part. I greatly appreciate their help. I hope this thread will be a great reference to all newbies to the electronics/wireless world.

Update:

Today, as I was connecting the AVR ISP to > the 10-to-6 pin connection to > Nordic FOB. I realized that I didnt know which way the connection from Female-to-Male went. I gave it a try anyway . See the pictures below (Hopefully I didn’t fry my new Nordic FOB)

http://fatherofcents.com/sf/photo_1.jpg

http://fatherofcents.com/sf/photo_2.jpg

My questions:

1 - Is this the right way to connect them?

2 - Is there a rule of thumb on connecting them?

3 - Should I leave the battery in or take it out?

4 -Where do I go from here? If I wanted to make an LED light when I press one of the buttons on the Nordic FOB. (So the LED is on one fob and the the other fob to control the LED0

I have AVR Studio 4, AVR Dude, and the sample Nordic FOB C code.

Thank you

I can’t see any pictures attached…

Anyway, I doubt you fried anything just by plugging the connector in the wrong way. As for the battery, you’d need to leave that plugged in while programming, since that is the power supply for the FOB.

MichaelN:
I can’t see any pictures attached…

Anyway, I doubt you fried anything just by plugging the connector in the wrong way. As for the battery, you’d need to leave that plugged in while programming, since that is the power supply for the FOB.

Can you see them now?

Thaer:
Can you see them now?

Yes, I can see them now. It's hard to see exactly which pins on that adapter cable connect to which. If you can provide a closer image I can check for sure, but you want the connection to be as follows:

(6-pin) (10-pin) (Function)

1 <----> 9 MISO

2 <----> 2 Vcc

3 <----> 7 SCK

4 <----> 1 MOSI

5 <----> 5 RST

6 <----> 4,6,8 or 10 GND

MichaelN:

Thaer:
Can you see them now?

Yes, I can see them now. It's hard to see exactly which pins on that adapter cable connect to which. If you can provide a closer image I can check for sure, but you want the connection to be as follows:

(6-pin) (10-pin) (Function)

1 <----> 9 MISO

2 <----> 2 Vcc

3 <----> 7 SCK

4 <----> 1 MOSI

5 <----> 5 RST

6 <----> 4,6,8 or 10 GND

I can’t tell which pin is pin 1 on the fob. I can’t find any identifying mark. Is the 10-to-6 connector connected correctly to the AVR ISP?

[

Uploaded with [ImageShack.us

[

Uploaded with [ImageShack.us

[

Uploaded with [ImageShack.us](http://imageshack.us)](http://img863.imageshack.us/i/photo3js.jpg/)](http://imageshack.us)](ImageShack - Best place for all of your image hosting and image sharing needs)](http://imageshack.us)](ImageShack - Best place for all of your image hosting and image sharing needs)

OK, you need to plug the 6-pin connector in the other way - then it should work.

Pin 1 on the FOB is marked with a small white mark.

MichaelN:
OK, you need to plug the 6-pin connector in the other way - then it should work.

Pin 1 on the FOB is marked with a small white mark.

Thanks Micheal.

Now I’m able to connect to the fob using AVR Studio

What do I do next? Where do I connect the LED? How do I program one fob to turn on/off LED on the other fob?

If there is a tutorial on how to do this, please let me know.

Thaer:
What do I do next? Where do I connect the LED? How do I program one fob to turn on/off LED on the other fob?

If there is a tutorial on how to do, please let me know.

As per previous messages, 3 of the pins on the programming header (1:MISO, 3:SCK, 4:MOSI) can be used for general-purpose I/O when you don't have the programmer plugged in. You can connect an LED to one of these pins, with the other side of the LED connected to either GND or Vcc via a resistor.

Have a look at the example code as well as the user comments on the Sparkfun Nordic FOB page. Try searching for “NRF24L01” on www.avrfreaks.net.

As for tutorials, it sounds like you need to learn some basic C programming (there’s heaps of tutorials on the net). You also should do some reading of the ATTINY24 datasheet to understand the registers.

This guy has an overview on the NRF24L01, but nothing specifically for Atmel chips:

http://www.diyembedded.com/tutorials/nr … rial_0.pdf

MichaelN:

Thaer:
What do I do next? Where do I connect the LED? How do I program one fob to turn on/off LED on the other fob?

If there is a tutorial on how to do, please let me know.

As per previous messages, 3 of the pins on the programming header (1:MISO, 3:SCK, 4:MOSI) can be used for general-purpose I/O when you don't have the programmer plugged in. You can connect an LED to one of these pins, with the other side of the LED connected to either GND or Vcc via a resistor.

Have a look at the example code as well as the user comments on the Sparkfun Nordic FOB page. Try searching for “NRF24L01” on http://www.avrfreaks.net.

As for tutorials, it sounds like you need to learn some basic C programming (there’s heaps of tutorials on the net). You also should do some reading of the ATTINY24 datasheet to understand the registers.

This guy has an overview on the NRF24L01, but nothing specifically for Atmel chips:

http://www.diyembedded.com/tutorials/nr … rial_0.pdf

Thanks

I learned C programming, all the way from declaring variables, to building functions. The thing is I dont know how to apply it in this situation. Great C tutorials [HERE and [HERE.

I’ll check out AVR freaks and I’ll go through the datasheet, and the tutorial.](http://www.youtube.com/watch?v=mIMhspJzC34)](http://www.youtube.com/watch?v=b00HsZvg-V0)

MichaelN:

Thaer:
What do I do next? Where do I connect the LED? How do I program one fob to turn on/off LED on the other fob?

If there is a tutorial on how to do, please let me know.

As per previous messages, 3 of the pins on the programming header (1:MISO, 3:SCK, 4:MOSI) can be used for general-purpose I/O when you don't have the programmer plugged in. You can connect an LED to one of these pins, with the other side of the LED connected to either GND or Vcc via a resistor.

Have a look at the example code as well as the user comments on the Sparkfun Nordic FOB page. Try searching for “NRF24L01” on http://www.avrfreaks.net.

As for tutorials, it sounds like you need to learn some basic C programming (there’s heaps of tutorials on the net). You also should do some reading of the ATTINY24 datasheet to understand the registers.

This guy has an overview on the NRF24L01, but nothing specifically for Atmel chips:

http://www.diyembedded.com/tutorials/nr … rial_0.pdf

I tried programming the fob using AVR Studio, but when I compile the tester file (below) I get the following errors:

ERRORS:

Nordic-FOB-Tester-v10.c:36: warning: implicit declaration of function 'FDEV_SETUP_STREAM'
Nordic-FOB-Tester-v10.c:36: error: '_FDEV_SETUP_WRITE' undeclared here (not in a function)
Nordic-FOB-Tester-v10.c:36: error: invalid initializer
Nordic-FOB-Tester-v10.c: In function 'main':
Nordic-FOB-Tester-v10.c:42: warning: unused variable 'i'
make: *** [Nordic-FOB-Tester-v10.o] Error 1
Build failed with 2 errors and 2 warnings...

CODE:

/*
    6-19-2007
    Copyright Spark Fun Electronics© 2007
    Nathan Seidle
    nathan at sparkfun.com
    
	Keyboard PS/2 Interpreter
	
	http://www.computer-engineering.org/ps2protocol/
	
	Original Fuses : avrdude -p atmega8 -P lpt1 -c stk200 -U lfuse:w:0xE1:m -U hfuse:w:0xD9:m
	16MHz Fuses : avrdude -p atmega8 -P lpt1 -c stk200 -U lfuse:w:0xEE:m -U hfuse:w:0xC9:m
*/

#include <stdio.h>
#include <avr/io.h>

#define FOSC 1000000 //1MHz internal osc
#define BAUD 4800
#define MYUBRR (((((FOSC * 10) / (16L * BAUD)) + 5) / 10) - 1)

#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask))

#define STAT_LED	0 //PORTB

//Define functions
//======================
void ioinit(void);      //Initializes IO
void delay_ms(uint16_t x); //General purpose delay
void delay_us(uint8_t x);

#include "nordic-nRF24L01.c"

static int uart_putchar(char c, FILE *stream);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
//======================

int main (void)
{
    uint8_t incoming;
	uint8_t i = 0;

	ioinit();

	printf("Nordic Serial\n\n");

	//configure_transmitter();
	configure_receiver();
	
	while(1)
	{
		incoming = rx_send_byte(0xFF); //Get status register
		//printf("rx status=0x%02x\n", incoming);

		if (incoming & 0x40)
		{
			//We have data!
			receive_data();
			//printf("d0=0x%x\n", data_array[0]);

			switch(data_array[0])
			{
				case 0x17: printf("Left button"); break;
				case 0x1E: printf("Bottom button"); break;
				case 0x1B: printf("Right button"); break;
				case 0x1D: printf("Top button"); break;
				case 0x0F: printf("Center button"); break;
				default: printf("No button!"); break;
			}

			printf(" Presses=%d\n", data_array[2]);
		}

		//incoming = tx_send_byte(0xFF); //Get status register
		//printf(" tx status=0x%02x", incoming);

		delay_ms(10);
	}
	
    return(0);
}

void ioinit (void)
{
	//1 = Output, 0 = Input
	DDRB = 0b00000001; //(STAT on PB0)
	DDRC = 0b11111000; //(LIGHT on PC0) (SOIL on PC1) (H-DAT on PC4) (H-SCK on PC5)
    DDRD = 0b11111110; // (RXD on PD0)

    //USART Baud rate: 9600
    UBRR0H = MYUBRR >> 8;
    UBRR0L = MYUBRR;
    UCSR0B = (1<<RXEN0)|(1<<TXEN0);

    stdout = &mystdout; //Required for printf init

    //Init timer 2
	//1,000,000 / 1 = 1,000,000
    TCCR2B = (1<<CS20); //Set Prescaler to 1. CS20=1
	
	init_nRF_pins();
}

static int uart_putchar(char c, FILE *stream)
{
    if (c == '\n') uart_putchar('\r', stream);
  
    loop_until_bit_is_set(UCSR0A, UDRE0);
    UDR0 = c;
    
    return 0;
}

//General short delays
void delay_ms(uint16_t x)
{
	for (; x > 0 ; x--)
	{
		delay_us(250);
		delay_us(250);
		delay_us(250);
		delay_us(250);
	}
}

//General short delays
void delay_us(uint8_t x)
{
	TIFR2 = 0x01; //Clear any interrupt flags on Timer2
	
    TCNT2 = 256 - x; //256 - 125 = 131 : Preload timer 2 for x clicks. Should be 1us per click

	while( (TIFR2 & (1<<TOV2)) == 0);
}

The code is provided on the Nordic Fob page. Why am I getting this error ? How can I fix it?

You’re using the wrong code. The code you’ve got is intended to be used with an Arduino (or similar) to connect to a computer for debugging purposes. The Arduino would need an add-on board for the Nordic chip to allow this to work. You don’t need to worry about any of this at this point, since you’re just using the FOB.

You want to use this code instead:

http://www.sparkfun.com/datasheets/Wire … ic-FOB.zip

Unzip this code to your working folder. In AVRStudio, create a new project “Nordic-FOB-v11”:

http://users.adam.com.au/mnoble/Create%20Project.JPG

Select ATTINY24 and then “Finish”:

http://users.adam.com.au/mnoble/Select%20Device.JPG

From the Project menu, select Configuration Options, and then check the “Use External Makefile” box and select the Makefile that was provided in Nordic-FOB.zip:

http://users.adam.com.au/mnoble/Use%20E … kefile.JPG

Add the 2 source files to the project:

http://users.adam.com.au/mnoble/Add%20S … 0Files.JPG

At this point, you should be able to build without errors (Build → Rebuild All)…

I had done all the steps you mentioned except I was using the wrong C code. :oops:

Thanks for pointing me in the right direction.

I programmed the two fobs with the code provided by Sparkfun.

Now, I’m trying to get a wireless connection going to turn on/off an LED. I connected the LED to every pair of pins possible. I still couldn’t control the LED using the other remote. I noticed when I connect the LED to pin2 and pin6 the LED turns on.

How do I properly connect the LED to one of the fobs, so I’ll be able to control it with the other fob?

I think you need to carefully study the schematic and existing code (particularly nordic-nRF24L01.c) and the datasheets more. You really need to understand how the software and hardware work together. The fact that you didn’t realize you were using the wrong code makes me wonder if you even read it…

The FOB sample code only covers transmission of data when the buttons are pressed. It does NOT have any code for receiving data - you’ll need to add that yourself. You’ll also need to add code for flashing the LEDs etc. As previously discussed, your biggest challenge will be keeping the power consumption down (if you keep the receiver on all the time the battery probably won’t last more than a day or 2).

The “Nordic-FOB-Tester” code (although not written for the ATTINY24) has some simple code that receives data from the FOB and sends the result over a serial port. This should show you how to use some of the functions in nordic-nRF24L01.c such as receive_data().

As for connecting the LEDs, I’m not sure what the problem is- I’ve covered this several times before.

MichaelN:
3 of the pins on the programming header (1:MISO, 3:SCK, 4:MOSI) can be used for general-purpose I/O when you don’t have the programmer plugged in. You can connect an LED to one of these pins, with the other side of the LED connected to either GND or Vcc via a resistor.

To make it even clearer:

http://users.adam.com.au/mnoble/Connecting%20LED.JPG