Arduino Radio Spectrum Analyzer prototype on a breadboard: Difference between revisions

From NURDspace
Line 10: Line 10:


==Atmega328 on a breadboard==
==Atmega328 on a breadboard==
There are quite a few good "Arduino on a breadboard" tutorials out there. I suggest you take a look at
* [http://arduino.cc/en/Main/Standalone|Building an Arduino on a Breadboard]


These were the components I bought (or borrowerd here on the nurdpspace):
These were the components I bought (or borrowerd here on the nurdpspace):
Line 31: Line 29:
* A few pizzas
* A few pizzas


The first step will describe the basic setup of an arduino on a breadboard (or rather an atmega328 on a breadboard). For all you who have done this a million times arelady, just skip ahead.
The first step will describe the basic setup of an arduino on a breadboard (or rather an atmega328 MCU on a breadboard). For all you who have done this a million times arelady, just skip ahead, or even better, read it and correct me or give me suggestions on better ways of doing things. I will be eternally grateful.


This first step is just a very basic breadboard setup.  
I'll try not to explain too much, since others already did that better than I can, so instead I will point to some proper sources of information. First of all, take a look at [http://arduino.cc/en/Main/Standalone|Building an Arduino on a Breadboard]. It is a good how-to on setting up an arduino on a breadboard. It might be that after reading that, you don't need me to tell you anything, but hey, I got time to spend tonight, so I'll write this up anyway.
[[File:arduino_breadboard1.jpg]]
 
[[File:Switch.jpg]]
This first step is just a very basic breadboard setup.  The first step in wiring up a breadboard is finding the datasheets, or at least the pin mapping. The information in the datasheats is priceless. You can find the pinmapping of the atmega 328 on http://arduino.cc/en/Hacking/PinMapping168.
[[File:arduino_breadboard2.jpg]]
 
[[File:arduino_breadboard3.jpg]]
In this first image you can see I wired up the ground (GND) and positive lines (VCC) of the breadboard to the MCU. I also hooked up the Analog Reference (AREF), which tells the MCU what the highest voltage is for analog signals.
[[File:arduino_breadboard4.jpg]]
 
At the top of the breadboard I connected the positive and ground lanes to each other, so both sides are properly powered/grounded.
 
I also connected an LED to the digital pin 2 of the MCU, so you can test the MCU later on. I also use it in my programs, so I know that when the led blinks, the program is running.
 
[[File:Switch.jpg|right|300px]] The last part of the first step is the reset switch. If you want to program your MCU, you will need to tell it to reset, so it will be ready for programming. The MCU resets when a current flows away from the reset pin. So what you do is first connect a PULLUP resistor to the pin. This means that you connect a high resistance resistor (10kOhm in this case) to the positive line on the breadboard. This will make sure no current flows away unexpectedly from the reset pin, causing unexpected resets. Next you connect the same reset pin of the MCU to the reset switch, and you connect the other pin of the reset switch to the ground. Now when you press the reset switch, a current will start flowing from the reset pin of the MCU, to the ground, causing the MCU to reset.
To the right you can see an image of what I did with the reset switch. It didn't want to stick in the breadboard because the legs were too short. So I soldered a jumper to each leg of the switch, so it had properly large legs, an fits nicely in the breadboard.
 
[[File:arduino_breadboard1.jpg|none|600px]]
 
Before you can do anything with your breadboard, two more things need to be done: adding a crystal oscillator and adding connections for the FTDI cable (for power and for programming).
 
The crystal oscillator is the hardware clock of the MCU. You need a 16MHz crystal, with two capacitors. The crystal oscillates with 16 million oscillations per second. This is the speed at which the MCU can calculate and also drives the time measurement of the MCU. The crystal is connected to pins 9 and 10 of the MCU. In order to work, both legs of the crystal need to be connected to the ground through a capacitor. The needed capacitance of the capacitors had me stumped for a while. I still don't know the specifics, but on http://arduino.cc/forum/index.php?topic=5677.msg43967#msg43967 there is at least a reasonable explanation. In short, the needed capacitors depends on the crystal's specs, the board you hook it up to (the board itself also has capacitance) and on how important the accuracy of the crystal is to you. In the end I have ended up with two 18pF capacitors.
 
[[File:arduino_breadboard2.jpg|none|600px]]
 
The last bit before you can start programming your arduino is hooking it up to your usb port. We will use the usb (FTDI) cable also for powering the breadboard. I left some free space at the left bottom of the breadboard for the TDFI cable. Just ignore the unconnected resistors in the image for now. They will be used later on. For now, you can see which pins I have connected of the FTDI cable. The red and black wires are 5V and GND respectively. So hook those pins up to the + and - lanes of the breadboard. The yellow and orange wires of the FTDI cable are the TX and RX cable, which take care of transmitting and receiving data from the usb port. These need to be connected to pins 2 and 3 of the MCU.
 
[[File:arduino_breadboard3.jpg|none|600px]]
 
Now you can plug in the FTDI cable (I used some jumpers to connect it) and start programming.
 
[[File:arduino_breadboard4.jpg|none|600px]]
 
If you bought a chip with a preloaded arduino bootloader, you can program it directly using the arduino IDE. If it is still blank, you will first need to burn a bootloader. Bruning a bootloader (which can be done in several ways, I preferred putting my MCU in another arduino board that was lying around) is properly described towards the end of [http://arduino.cc/en/Main/Standalone|Building an Arduino on a Breadboard].
 
If you don't know what to do at all to program your MCU, I suggest you check out http://www.ladyada.net/learn/arduino/lesson1.html.
I you do know how to start the Arduino IDE, some nice examples and good documentation can be found on http://arduino.cc/en/Tutorial/HomePage.
 
If you have the arduino IDE running, make sure you select the "Arduino Duemilanove with atmega 328" board. The port depends on windows or linux, but on linux it is probably /dev/ttyUSB0 for ubuntu based distro's.
 
As code for this board, I use the following code to program my MCU:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(2, OUTPUT);
}
void loop() {
  digitalWrite(2, HIGH);  // set the LED on
  delay(500);              // wait for a second
  digitalWrite(2, LOW);    // set the LED off
  delay(500);              // wait for a second
}
 
Once you see the led blinking, congratulations, you just built and programmed and arduino.


==Connecting the CYWM6935==
==Connecting the CYWM6935==

Revision as of 23:36, 30 January 2013

NURDspace Project
link=File:{{{Name}}}.jpg
Participants
Skills
Status
Niche
Purpose
Tool
Location
Cost
Tool category

{{{Name}}}Property "Tool Name" (as page type) with input value "{{{Name}}}" contains invalid characters or is incomplete and therefore can cause unexpected results during a query or annotation process. Property "Tool Image" (as page type) with input value "File:{{{Picture}}}" contains invalid characters or is incomplete and therefore can cause unexpected results during a query or annotation process. {{{Picture}}} {{#if:{{{Tool}}} | [[Tool Owner::SmokeyD | }} {{#if:{{{Tool}}} | [[Tool Cost::{{{Cost}}} | }}

I am building a Radio Spectrum Analyzer which measures signal strenght in the 2.4GHz band, using a CYWM6935 module and Atmega 328 MCU. I want to set it up in several steps:

Atmega328 on a breadboard

These were the components I bought (or borrowerd here on the nurdpspace):

The first step will describe the basic setup of an arduino on a breadboard (or rather an atmega328 MCU on a breadboard). For all you who have done this a million times arelady, just skip ahead, or even better, read it and correct me or give me suggestions on better ways of doing things. I will be eternally grateful.

I'll try not to explain too much, since others already did that better than I can, so instead I will point to some proper sources of information. First of all, take a look at an Arduino on a Breadboard. It is a good how-to on setting up an arduino on a breadboard. It might be that after reading that, you don't need me to tell you anything, but hey, I got time to spend tonight, so I'll write this up anyway.

This first step is just a very basic breadboard setup. The first step in wiring up a breadboard is finding the datasheets, or at least the pin mapping. The information in the datasheats is priceless. You can find the pinmapping of the atmega 328 on http://arduino.cc/en/Hacking/PinMapping168.

In this first image you can see I wired up the ground (GND) and positive lines (VCC) of the breadboard to the MCU. I also hooked up the Analog Reference (AREF), which tells the MCU what the highest voltage is for analog signals.

At the top of the breadboard I connected the positive and ground lanes to each other, so both sides are properly powered/grounded.

I also connected an LED to the digital pin 2 of the MCU, so you can test the MCU later on. I also use it in my programs, so I know that when the led blinks, the program is running.

Switch.jpg

The last part of the first step is the reset switch. If you want to program your MCU, you will need to tell it to reset, so it will be ready for programming. The MCU resets when a current flows away from the reset pin. So what you do is first connect a PULLUP resistor to the pin. This means that you connect a high resistance resistor (10kOhm in this case) to the positive line on the breadboard. This will make sure no current flows away unexpectedly from the reset pin, causing unexpected resets. Next you connect the same reset pin of the MCU to the reset switch, and you connect the other pin of the reset switch to the ground. Now when you press the reset switch, a current will start flowing from the reset pin of the MCU, to the ground, causing the MCU to reset.

To the right you can see an image of what I did with the reset switch. It didn't want to stick in the breadboard because the legs were too short. So I soldered a jumper to each leg of the switch, so it had properly large legs, an fits nicely in the breadboard.

Arduino breadboard1.jpg

Before you can do anything with your breadboard, two more things need to be done: adding a crystal oscillator and adding connections for the FTDI cable (for power and for programming).

The crystal oscillator is the hardware clock of the MCU. You need a 16MHz crystal, with two capacitors. The crystal oscillates with 16 million oscillations per second. This is the speed at which the MCU can calculate and also drives the time measurement of the MCU. The crystal is connected to pins 9 and 10 of the MCU. In order to work, both legs of the crystal need to be connected to the ground through a capacitor. The needed capacitance of the capacitors had me stumped for a while. I still don't know the specifics, but on http://arduino.cc/forum/index.php?topic=5677.msg43967#msg43967 there is at least a reasonable explanation. In short, the needed capacitors depends on the crystal's specs, the board you hook it up to (the board itself also has capacitance) and on how important the accuracy of the crystal is to you. In the end I have ended up with two 18pF capacitors.

Arduino breadboard2.jpg

The last bit before you can start programming your arduino is hooking it up to your usb port. We will use the usb (FTDI) cable also for powering the breadboard. I left some free space at the left bottom of the breadboard for the TDFI cable. Just ignore the unconnected resistors in the image for now. They will be used later on. For now, you can see which pins I have connected of the FTDI cable. The red and black wires are 5V and GND respectively. So hook those pins up to the + and - lanes of the breadboard. The yellow and orange wires of the FTDI cable are the TX and RX cable, which take care of transmitting and receiving data from the usb port. These need to be connected to pins 2 and 3 of the MCU.

Arduino breadboard3.jpg

Now you can plug in the FTDI cable (I used some jumpers to connect it) and start programming.

Arduino breadboard4.jpg

If you bought a chip with a preloaded arduino bootloader, you can program it directly using the arduino IDE. If it is still blank, you will first need to burn a bootloader. Bruning a bootloader (which can be done in several ways, I preferred putting my MCU in another arduino board that was lying around) is properly described towards the end of an Arduino on a Breadboard.

If you don't know what to do at all to program your MCU, I suggest you check out http://www.ladyada.net/learn/arduino/lesson1.html. I you do know how to start the Arduino IDE, some nice examples and good documentation can be found on http://arduino.cc/en/Tutorial/HomePage.

If you have the arduino IDE running, make sure you select the "Arduino Duemilanove with atmega 328" board. The port depends on windows or linux, but on linux it is probably /dev/ttyUSB0 for ubuntu based distro's.

As code for this board, I use the following code to program my MCU:

void setup() {                
  // initialize the digital pin as an output.
  pinMode(2, OUTPUT);
}

void loop() {
  digitalWrite(2, HIGH);   // set the LED on
  delay(500);              // wait for a second
  digitalWrite(2, LOW);    // set the LED off
  delay(500);              // wait for a second
}

Once you see the led blinking, congratulations, you just built and programmed and arduino.

Connecting the CYWM6935

To connect the CYWM6935 module to the breadboard, I created my own cable. I found a 2.5" Harddisk adaptor plug, which fortunately has pins on one side with the spacing for my flat cables like floppydisk cables, and on the other side has holes with a smaller spacing, exactly the size of the CYWM6935. Using this plug, a flatdable, some simple PCB and a few jumpers, I soldered something together that allowed me to connect the radio module to the breadboard.

I split a floppy cable that was lying around, so it had 10 wires left. On one side I left the connector in place. On the other side I cut off the connector and stripped the wires. I soldered each of these free wires to a PCB. On each of the lanes for these wires, a jumper pin was soldered, so I ended up with a 10-pin connector which fits the breadboard. There is one thing you should know about this connection (and could be done better). If you connect the wires this was, the order of the pins on the breadboard correspond to the CYWM6935 pins in a weird order. Their order is: 2,1,4,3,6,5,8,7,10,9. If you want the pins on the breadboard side, to correspond to the CYWMUSB6935 module in the correct order, you should twist around each pair of wires. This is how the cable looks now.

Cywm6935 connector cable.jpg

Connecting this plug to it, you can plug in the CYWM6935 module directly.

Connector cable with cywm6935.jpg

Programming the Atmega328

Creating desktop software for visualization

I chose to create a Java GUI using JFreeChart to read the data from the Arduino using an FTDI cable on a serial port (or actually USB) and visualize that in the GUI. The program can be found on Github.

This is a screenshot from the app. It allows you to reset the maxima by clicking the button.

Arsa screenshot.png

Assemble everything on a custom PCB