Search Microcontrollers

Monday, April 6, 2015

Stellaris Launchpad - NRF24L01 radio - Part 2

Ok, I had this one in draft for long enough now.
I still need to figure out a few things, so a part 3 will be needed in the future, also I initially had issues with Dynamic Payloads as I forgot to issue the FEATURE = EN_DPL command, hopefully shoudl work better now.


In a previous post we saw some basic concepts and functionality of the NRF24L01 chip.

We managed to establish a SPI communication between the Stellaris and the module, but we did not perform any data transmission across two nodes.
to achieve that we need to add a few functions to our library and decide some basic defaults for it.

I think this automatic ACK system (if you don't know what I am talking about, you really need to read my previous post) is pretty cool and I think it would be fair to use it by default, so the library will assume we are going to use it, should we have any issues with it later on, we might eventually change approach.

While supporting multiple RX pipes is indeed interesting, so I would rather keep that functionality in the library, we can assume that, by default, communication will be through pipe0.

The function nrf_enablePipes accepts a byte (bits 0:5 represent the 6 pipes) does 3 things :

1) Enables the selected pipes
2) Activates the AUTO ACK magic for them
3) configures them for dynamic payload

void nrf_enablePipes(unsigned char pipes)
{
  nrf_writeReg(EN_AA, pipes);     
         // enable AUTO ACK on pipes
  nrf_writeReg(EN_RXADDR, pipes); // enable pipes
  nrf_writeReg( FEATURE, 1<<EN_DPL ); //enable DPL
  nrf_writeReg(DYNPD, pipes); // dynamic payload for pipes
}

About dynamic payload (DPL), the Datasheet says :

(@Nordic)


Another default I picked is to use 5 byte addressing.

Now we need to be able to set the TX address and the various RX addresses for the RX pipes.

 /*
#define RX_ADDR_P0  0x0A
#define RX_ADDR_P1  0x0B
#define RX_ADDR_P2  0x0C
#define RX_ADDR_P3  0x0D
#define RX_ADDR_P4  0x0E
#define RX_ADDR_P5  0x0F
pipe : 0..5
 */
void nrf_setRXAddress(unsigned char pipe, unsigned char *addr)
{
 nrf_writeRegMulti(RX_ADDR_P0+pipe, addr, 5);
}

void nrf_setTXAddress(unsigned char *addr)
{
 nrf_writeRegMulti(TX_ADDR, addr, 5);
}

the writeRegMulti function works like the writeReg, but accepts a buffer and sends n bytes instead of a single one, we need it for setting the addresses since they are 5 bytes long.

As we discussed in the previous post, a node can be set up as PRX or PTX, this is done setting the lowest bit in the CONFIG register : 1 means PRX, 0 means PTX.
The same register is used to specifcy if a CRC is used, int hat case wether is it 1 or 2 byte long,m plus there are 3 bits used to mask the interrupts.

You can find more info on the CONFIG register here.

/**
 * Set crc = 0 to disable crc, 1 for 1 byte ,2 for 2 bytes
 */
void nrf_config(unsigned char maskRXirq, 
                unsigned char maskTXirq,
                unsigned char maskMAXirq,
unsigned char crc,
                unsigned char pwUp,
                unsigned char prx)
{
   unsigned char val = maskRXirq<<6 | 
                       maskTXirq<<5 | 
                       maskMAXirq <<4;
   if (crc>0) val |= 8; else crc--;
   val |= crc <<2 | pwUp<<1 | prx;
   nrf_writeReg(CONFIG,val);
}

When we need to initiate a transmission, we need to set up the node as PTX, to set the TX address to the address of the receiving module, plus the Pipe0 address equal to the TX one.

Additionally we might want to configure the number of transmission attempts (if Auto ACK fails) and the delay between them

/**
 * delay : 0 = 250us, 1=500us ... 15=4000us
 * count : 0..15 auto retransmit if AA fails
 */
void nrf_setRetransmit(unsigned char count, 
                       unsigned char rDelay)
{
 unsigned char val = ((rDelay&0x0f)<<4) | (count&0x0f);
 nrf_writeReg(SETUP_RETR,val);
}

In our experiment we will use node 1 with address "node1" (in ASCII) and node 2 with address "node2" and we will try to have them communicate  @2MBps on the channel 0x10.
Node 1 will try to send a payload containing the data "TEST1234" every 2 seconds and we will use the RGB leds on the two Launchpads to provide some feedback.

For this initial test we will do something simple, however I believe we still need to use two pipes.
The reason for this is that when the PTX sends data, it has to configure the RX pipe0 with the same address of the receiver, therefore it needs to be able to listen on a different pipe, with a unique address, in order to be contacted when it switches back to PRX.

Initially I was thinking to have one of the two nodes running on Arduino, to use a know library such as Mirf to minimize the debug, unfortunately I am not really sure if Mirf allows to be configured properly and if that is the case, I don't know how, while with my library at least I know all the settings.

Ok, I stopped here because I got lost with the DPL feature, as stated at the beginning, should work now, need to experiment a bit more (been doing other stuff for quite some time) and then hopefully a final Part 3 will be posted :) 

Thursday, January 15, 2015

Unpacking my new Telescope

I recently bought a SkyWatcher Maksutov-Cassegrain 150 Pro, with a HEQ5 Pro mount.

I am quite a newbie with this kind of stuff, so I cannot yet review thre equipment, but I can give you my first impressions.

Normally I write about micro-electronics, so this post is a bit "different", still my blog is about geekiness and well, a telescope qualifies in the category :)

The purpose of this post is to show you what you get should you buy the same equipment and also to provide a detailed step-by-step setup guide, since the manual is quite basic on that part.

Anyhow, it's not completely true that microelectronics is not involved... in fact the mount (uses 2 stepper motors) has a serial protocol which the vendor released in open source (twink! twink!).



These are the boxes : 1) tripod with counter-weights, 2) the tube and 3) the mount.
It is always a good idea to make some room before unpacking stuff.



 The tube itself comes with a nice package to protect it during shipping, better save these protections for future use.


Finally, this is all the equipment which I will describe starting from the top left :
1) Manuals, marketing stuff etc in all the first row. Nothing fancy here
2) Two counter-weights (yes, they are HEAVY), the eyepiece /other stuff  holder which is part of the tripod, a box which contained the eyepiece and some other spare parts
3) The tripod
4) Tube (telescope), finder scope, diagonal and eyepiece
5) the mount, goto controller handler, car cigarette power cable, 2 allen wrenches, locking screws, spare mount sled, serial cables, goto controller

  
First step : open up the tripod.
Looks like a stable and sturdy tripod, make sure you open it completely, I did not extend the legs for now.
Notice the tripod is not symmetric, one side is labeled "N" and it should be oriented to north.
On that side there is a metal tab used to lock the azimuth rotation of the mount in respect to the tripod.


The mount comes next, notice the two screws that will be pressing on the previously described tab.
Make sure you undo them properly before placing the mount on the tripod.
Once done start screwing in the bottom rod.


With the mount in place, we want to stabilize the tripod : unscrew the bottom part of the threaded rod, place the eyepiece / stuff holder and then screw back in the bottom part.
Notice that there are 3 small extensions that are supposed to press against the tripod legs and prevent them from folding back.
Also notice there is a U slot in the holder, this will be used to rest the go-to controller, so face it in the direction where you like to have the controller.



Counterweigths: Unlock the clouch that controls the coutnerweight bar so that it extends completely, then lock it again.
Remove the safety screw at the end of the bar and slide in the weights, one at a time, lock the one you inserted first before adding the second, finally put back the safety screw.
At this point it is probably a good idea to have the counterweghts a bit "low", at least like the position you see in the pciture.
This will help for the next steps  as it will ensure that the scope will stay up once we install it and it will not start spinning around.


 You don't need to install the additional sled, I just placed it there to check how the locking mechanism works and to ensure there were no particular details I had to take care of when placing the scope.
This picture shows how your scope is going to be attached to the mount.



One final thing before installing the scope : screw in the two small threaded rods, they are placed on the two opposite sides of the mount.



Now, undo the two holding screws visible in the center / bottom of the picture and carefully slide the scope in.
It's not difficult, but make sure the sled slides in both sides, you don't want your scope to fall on the floor! :)
Lock it roughly in the middle of the sled, you will need to adjust the position later, but not yet.



It's the turn of the finder scope, this is an easy one, just undo the locking scre, slide it in and lock it back.




Time to place the diagonal on the back side of the scope.
Undo the holding screws, remove the caps and fit the metallic part of the diagonal in, push it all the way before tightening the screws again.


Similarly you install the eyepiece on the diagonal.


Place the holder for the go-to controller in the slot we described before


Connect one end of the serial cable (RJ45 plug) to the mount.


And the other end to the controller.


We are now ready to balance the mount, sliding the counterweights as needed and also sliding the tube on the mount (undo the screws and keep the mount in the vertical position while you move the sled. Put it horizontal when you move the weights).

That's pretty much it, now the scope is ready for the finder alignment.
Make sure you do not aim it to the sun!

Overall first impressions, I am quite pleased with the build quality.
The mount looks really sturdy and stable (it is heavy!!).
Setting the thing up was not too difficult and with a bit of practice I think it can be done in few minutes (not including alignment, which I still have to explore).