Archive

Archive for the ‘electronics’ Category

nRF24L01+ basic operation. My notes

November 16th, 2014 No comments

This is a brief note I am taking while reading how to operate nRF24L01+ using a microcontroller. This post is not meant to be a tutorial, but I publishing it anyway as someone might find it useful.

Connectivity

  • 3.3V (absolute max 3.6V) supply power
  • It seems that data lines are 5V tolerant (to clarify, supply power is NOT 5V tolerant)
  • SPI communication, 4 lines
    • CSN – SPI Chip Select
    • SCK – SPI Clock
    • MOSI – nRF24L01 data input
    • MISO – nRF24L01 data output
  • There is a CE chip enable pic, which activates RX or TX mode
  • Doesn’t seem I need any pull resistors on the data line. The lines will be connected directly to the microcontroller

Operation

There are 4 types of operational modes in the module, Power Down, Standby-I, TX and RX. Standby-I seems to be the ‘normal’ operating mode and you just need to switch to TX or RX to do your task. Power Down is used to save power and the trade-off is that you need about 1.5ms to go back to Standby-I.

After reset, the module defaults to Power Down mode.

Controlling the module

The module is controlled through a register which is accessed using SPI write and read commands.

SPI Commands

  • Just before starting an SPI command, the CSN should be switched from HIGH to LOW
  • As the command is shifted out from MOSI, the STATUS register of nRF24L01 is shifted from the MISO
  • SPI communication is Most Significant Bit first – Least Significant Byte first

Incoming search terms:

  • hk-t6 schematic (1)
Categories: electronics Tags:

Autoroute PCBs in KiCad offline

October 31st, 2014 No comments

Few months back, the autorouter in KiCad stopped working. KiCad was using the free online autorouter http://www.freerouting.net/ which is now not working. The author was kind enough to open-source it and you can find it in various locations in the Internet.

Now if you want to use it directly, you can use pre-compiled files. I found them in this GitHub repository, look into the binaries directory. Download the file you are interested in. Since I am working in Ubuntu I downloaded the .jar file. Then to be able to run it, you have to install Java. I used this package

sudo apt-get install openjdk-8-jre-headless

First make sure you export your KiCad board file as .dsn from FILE>EXPORT>Specctra DSN

Then run

java -jar FreeRouting.jar

Open you .dsn file and click Autorouter!FreeRouter KiCad Offline

 

 

Incoming search terms:

  • kicad autorouter (16)
Categories: electronics, general Tags:

HOW TO: Make your own USB cable for HK-T6A calibration

April 27th, 2012 44 comments

Hey!

About a month ago I managed to go ahead and buy my first quadcopter (split the cost with two of my colleagues 🙂 ) and all the required equipment. I will do another post on that because it is really interesting!

I played around with RC airplanes some 10 years ago. There are some things changed now. Controllers are different. You are able to buy a 6 channel radio for under 30 Euros! Wow… Anyway, so I bought this controller from Hobbyking, named HK-T6A. However, I missed the fact that I needed a USB cable as well. To cut the story short, I had everything I needed to fly the brand new quad, but the controller needed calibration. Since the USB calibration cable was out of stock it would take some time to arrive. The cheap cables in ebay were shipped from China so it would take an additional month to get it. We had a problem!

Looking around in the internet, my attention was drawn to a picture of the transmitter communication socket. It was indicating TX/RX so I thought “wait a minute… could this be just serial comms?”. And so it was 🙂

What you need…

The only device you need is a simple USB-to-Serial (TTL) converter. If you are into digital electronics you should have a couple of them in your desk drawer. My personal favorite is CP2102. Take a look at my older post which I talk about this device. They cost only a couple of dollars including delivery from ebay. Check it out. You will also need 4 simple wires.

CP2102 USB-to-serial ttl module

The HK-T6 transmitter with the CP2102 and 4 wires. That is all you need!

Now take look at the trainer port of the controller.

The 4-pin din connection port of HK-T6

Connect everything together, really simple:

GND<–>GND
5V<–>5V
TX<–>TX
RX<–>RX

This is my temporary setup. It works!

Make sure your controller is switched off though. Then connect the CP2102 on your USB port of your PC. It could take some short time until your PC first finds the appropriate drivers and power the controller. You should see a red light on your transmitter. That means it is receiving power from the USB of your PC.

If something is not working, try switching the TX with RX lines. I mix them up all the time!!! You are now ready to calibrate your controller. Choose the software of your choice. I prefer Digital Radio. It is much better that T6Config. Note that this will work with FlySky CT6B since it is essentially the same controller.

Let me know if you need any help.

Incoming search terms:

  • how to make hk-t6 calibration cable (66)
  • hk-t6a (42)
  • HOW TO: Make your own USB cable for HK-T6A (34)
  • hk-t6a v2 usb cable (30)
  • hk-t6a usb cable (26)
  • how to make a cable for the HK-T6A (23)
  • HK T6A (22)
  • hk-t6a programming cable (21)
  • Make your own USB cable for HK-T6A (21)
  • hk-t6a cable (21)
Categories: electronics Tags: , ,

Using TMP100 temperature sensor with your PIC – PR5

January 31st, 2012 No comments

In this post I will describe how you can connect the TMP100 temperature sensor from TI to your PIC as well as receive temperature data. The sensor I am using is a generous sample from TI. Compared to the DS18S20 that I used before, this sensor is much faster, it takes 40ms to take a measurement with 0.5 degrees accuracy. The communication protocol is I2C. It could be a bit difficult connect it to your circuit since it is using a SOT-23-6 package.

For this project, I will be using my PIC prototyping board which carries a 18F4520. But you can pretty much use the C18 code in this post, with any PIC having a hardware I2C module.

Package problems!

Because SOT-23-6 is so small the first thing I needed was to create an adapter to make TMP100 compatible with my breadboard. This was a perfect excuse for improving my CNC skills :). So I created an adapter in EAGLE, cut it out using the CNC and then solder the sensor and 6 pins. The sensor is now breadboard ready!

The TMP100 adapter

 Connection

The connection is really simple. Add two pull-up resistors to the SDA and SDL lines. I used 10kOhm. The datasheet also suggests an optional capacitor on the supply.

TMP100 pinout

 

TMP100 Schematic

As you can see from the schematic there are two pins called ADD1 and ADD0. Those pins determine the I2C address of the sensor. You can find more details in the datasheet. I connected those two lines to GND therefore the address of the sensor I am using is 0x90. That’s all on the hardware side.

TMP100 – Point Register

I2c is the language this sensor talks :). So we need to use your PICs I2C hardware capabilities. Initialize your communications using

OpenI2C(MASTER,SLEW_OFF);

This sensor has a Point Register (PR)which (guess what!) points to the address of the register you want  to read or write 🙂 Before doing anything else we should point PR to the temperature register. To do that we have to initiate an I2C communication, send the address of the sensor and tell that sensor whether we like to write or read from it. This is done using a single byte. You see, the address is 7-bits starting from the MSB and bit 0 indicates whether is read or write operation (0=Write 1=Read). Let’s do an example. Our sensor’s address is 0x90. We wish to read something from the sensor so the byte should be 0x91. If we wish to write something to the sensors it should be 0x90. That’s it.

Therefore to write to point PR to the temperature register we should issue the following

StartI2C();
WriteI2C(0x90); // Call the sensor with WRITE
WriteI2C(0x00); // Write Temp reg to point register;
StopI2C();

Notice the 0x00? That is the address of the temperature register. The sensor is now ready to give us some temperatures.

TMP100 – Read that temperature

To read the temperature off the sensor, we need to call it using its address and READ (what we said above, remember?) and the sensor will transmit two bytes of data back. We read that using the appropriate I2C commands shown below. We have to acknowledge the reception of the bytes to let TMP100 know that we are ready for the next byte. Temperature is read as follows

StartI2C();
WriteI2C(0x91);
first_byte = ReadI2C();
AckI2C();
second_byte = ReadI2C();
StopI2C();

The temperature is made out of two bytes. If you don’t care about getting any decimals you can just use the first byte. The 4 most significant bits of the second byte contain information on the decimal value of the temperature.

TMP100 – C18 Library

I made a really simple library for tmp100 in C18. Just include the tmp100.h file to your project and make sure you initiate the I2C (the OpenI2C() command shown in this post) before calling any functions.

 

OK that is pretty much. You should be able to get some measurements out of that little sensor. If you need further help take a look at the example below

#pragma config OSC = HSPLL
#pragma config WDT = OFF
#pragma config PWRT = ON
#pragma config LVP = OFF
#pragma config PBADEN = OFF
 
#include <p18cxxx.h>
#include <i2c.h>
#include <usart.h>
#include <delays.h>
#include <p18f4520.h>
#include <stdio.h>
#include "tmp100.h"
 
void main(void) {
 
    unsigned int raw_tmpr;
    char str_tmpr[8];
 
    OpenUSART(USART_TX_INT_OFF &
              USART_RX_INT_OFF &
              USART_ASYNCH_MODE &
              USART_EIGHT_BIT &
              USART_CONT_RX &
              USART_BRGH_HIGH,
              21);
 
    Delay10KTCYx(250);
 
    OpenI2C(MASTER,SLEW_OFF);   // Initialize I2C module
    tm_setconf(0x60);   // Set sensor to full sensitivity
 
    while(1)
    {
        Delay10KTCYx(500);
        raw_tmpr = tm_gettemp();    // Get 2 bytes of temperature
        tm_tostr(raw_tmpr,str_tmpr);    // Convert the temperature to text
        printf("Temperature is %s\r",str_tmpr); // And output through USART
    }
    return;
}

I connected the USART TX/RX line using my CP2102 and used the cutecom program on Ubuntu to read the output on my PC. The screenshot below shows the terminal

The terminal on Ubuntu

Incoming search terms:

  • tmp100 (45)

1-Wire (OneWire) C18 library

November 17th, 2011 6 comments

So yesterday I wanted to get some temperature measurements from a DS18S20 thermometer to my PIC prototyping board. This thermometer uses the 1-Wire communication protocol so I searched around to find a 1-Wire library for the C18 compiler I am using. Maybe I am wrong but I couldn’t find any. So I created one, hence this post.

I had a post about the 1-Wire protocol a while back so you can read that if you are not familiar with it. To implement this protocol we need to work with precision timing. Ideally this could be written in asm. However, for convenience reasons I wrote this in C. I don’t really mind the minor performance penalty 🙂

Just to be clear, this is a library for the 1-Wire protocol, not for any of the supported devices. The library contains 3 main functions:

  • 1-Wire Reset
  • 1-Wire Write
  • 1-Wire Read

Using these three operations we can have full communication with any 1-Wire device. Let me demonstrate first and then I will write about how you can use it in your project.

A brief demonstration

To demonstrate this operation, I connected a DS18S20 thermometer and connected the DQ line on my PIC’s Port C Pin 1. The procedure I will follow is:

  • Issue a Reset pulse and observe the Presence of the thermometer
  • Issue the Skip Rom command (0xCC)
  • Issue the Convert T command (0x44)
  • Wait for 1+ second
  • Issue a Reset pulse and observe the Presence of the thermometer
  • Issue the Skip Rom command (0xCC)
  • Issue the Read Scratchpad command (0xBE)
  • And read the next two bytes which represent the temperature

Lets see the C code I loaded on my board Read more…

Incoming search terms:

  • ds18b20 c18 (18)
Categories: electronics Tags: , ,

Serial Interface Between PIC and PC – PR4

October 4th, 2011 2 comments

This one is really useful.

Most of the times you are developing a project, you will need some sort of monitoring or visual output to understand the status of your program. Sure some LEDs blinking are great but some times you need more. This is where the good old serial communication comes in. Through this communication you will be able to send information in the form of data or text, to and from your computer. You can use it as a debugging tool to monitor what is going on in your microcontroller during execution time. Or you can use this communication to send data to the PIC for processing and then receive the result back. I am sure you will appreciate the usefulness of this as soon as you implement it.

And all this happens by sending a sequence of zeros and ones… Read more…

Incoming search terms:

  • cp2102 (76)
  • cp2102 pic (24)
Categories: electronics, projects Tags: , ,

PIC and 5110 Interface with SPI hardware – PR3

September 26th, 2011 11 comments

This is the first “official” project I am doing with my PIC prototyping board. This project is about interfacing and using a simple Graphic LCD. So to follow this project you need a PIC to have SPI hardware, in order to communicate with the device. The GLCD (Nokia 5110) I am using is well known in the community and it is a cheap device. I bought it off ebay for about 5 Euros. Read more…

Incoming search terms:

  • nokia 5110 lcd pic (32)
  • interface pic18f con lcd (13)
Categories: electronics, projects Tags: , , , ,

PIC Prototyping Platform – PR2

September 7th, 2011 No comments

Hey,

In PR1 project, I talked about creating a stable prototyping platform that would save me from the trouble of setting up the microcontroller and all its required components. However, since then, I worked on tidying up this design into a more usable design (I wanted to play around with creating PCB actually 😀 ). So I designed the board sent it for fabrication and finally put it together. Read more…

Categories: electronics, projects Tags: , ,

Components for the Prototyping board arrived!

September 1st, 2011 3 comments

Hey guys,

A couple of days ago, the components for my new PCB arrived so I was able to test my design. The result was successful! Personally this was a simple board carries a lot of “firsts” for me. To begin with, it was the first time I ever designed a board on EAGLE that became an actual PCB. This might sound stupid but its different to make a design for home production (using chemicals) and a design that includes 2 layers, vias, solder masks, silkscreens, correct drill holes etc. I am not saying its hard, I am just saying its different so there are new things to consider.

Another “first” was the soldering of a TQFP package which as it turns out its not that hard (actually its like magic ;))! I had to buy some solder paste and a tweezers to make my life easier. I am suggesting to check out Surface Mount Soldering guide if you are interested.

Anyway, for a first attempt, I believe the results are pretty good. I made a simple blinking LED program which works, the power switch and reset button work, so I am assuming the design is OK.

I will make another post soon to include the schematics and stuff if anyone is interested and hopefully start producing some projects on this proto board. Finally here are a couple of pictures of the board:

Looking good!

Dimensions are 5cm x 5cm

Low Cost PCB Fabrication

August 13th, 2011 2 comments

Hey guys. I am really excited today because my first ever PCBs arrived from the fabrication house! I always wanted to have my own PCB printed but I was deterred by the price. So I used other methods such as developing my own board which can get quite messy or just sticking with the traditional prototyping boards. Few weeks back, I read a post from Kenneth, which led me to this fabrication house. They actually offer 10 PCBs maximum sized 5cm*5cm, for only $9.90 and $4 for delivery! This is really really cheap! Read more…

Incoming search terms:

  • iteadstudio pcb (25)
Categories: electronics Tags: ,