A Microcontroller Operated SWR Meter

Aus DL8RDS Wiki
Version vom 25. September 2009, 03:04 Uhr von Dl8rds (Diskussion | Beiträge) (First Steps on Arduino)
Wechseln zu: Navigation, Suche

1 Project description

This project is related to the SVXLink project. Since I intend to use T7F transceivers for this project, it is highly interesting to detect troublesome antenna and SWR conditions and to be able to shut off the transmitter. The only way to do that is to read out the SWR digitally. And this can be done using an Analog Digital Converter, either directly on a microcontroller board or over an I2C BUS.

BTW, I want to measure some more values:

  • PA temperature
  • Transmitter power consumption / input current
  • Total system input current

And I want to switch some things, too:

  • Be able to switch the transceiver OFF

But very basically this project can also be seen in an isolated perspective: I want to learn how to use a microcontroller and set up a project that's useful for other OMs as well. Notably interesting will be to use the Sparkfun Low Current readout boards and feed this voltage into the ADC that's contained on the Arduino board. so that I possibly don't even need the I2C BUS for this isolated scenario.

The LCD display is a ANAG Vision AV2020YFBF-SJ

2 Other People's work

3 Shops where to buy the components

4 Project Plan

  • Purchase stuff
  • Get familiar with the Arduino board. See how to read out values and to control actuators.
  • Build a directional coupler. Role model: http://www.dj4uf.de/projekt/swr/swr.htm
  • Make sure the readouts of the forward voltages are within a reasonable range. identify peak voltages.
  • Then take the BeagleBoard and be successful measuring voltages through a Analog Digital Converter (ADC).
  • Then connect the coupler to the ADC and see if it's possible to measure the voltages.
  • Then connect an LCD display to an Arduino board.
  • Then successfully control the LCD display and devise a reasonable display readout
  • Then read the I2C bus from the Arduino board
  • Then calculate the SWR based on the readings from the I2C bus and send them to the LCD display
  • Finally build a nice case
  • Write an article and post it in some fancy electronics magazine :-)

5 Progress

5.1 Purchase Stuff

  • 2009-09-04 The BeagleBoard has an I2C header in the expansion port. So it is just a wonderful idea to use it and read out some things. The only problem: It's operated with 1,8V. So I need a bidirectional voltage translator.
  • 2009-09-05 I decided to get the one from Gravitech.
  • 2009-09-10 My ADC arrived. I'm still waiting to receive the voltage translator. And I have bought some books on Arduino programming. Still need to buy the Arduino board and an LCD display.
  • ToDo: Go shopping

There are some guides on how to connect LCD dislays and Arduinos:

5.2 First Steps on Arduino

My first steps on the Arduino platform are successful! Since I have been working on a Ubuntu Hardy platform, I noticed that I would not be able to compile my programs properly because there are some bugs here and there. Anyway, so I decided to upgrade to the most modern Ubuntu Jaunty distribution and now it works fine: I can start the Arduino development environment without problems. Trying out the first little program, the famous "Blink" program which blinks a LED, compiled perfectly. So I started over and plugged the LED into digital output pin 13 and GND and uploaded the code and there it went. The Arduino went blinking!!!

int ledPin =  13;    // LED connected to digital pin 13

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

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

My next experiment was to send stuff to the serial console back to the computer. Here I tried out some code from the book "Manuel Odendahl, Julian Finn & Alex Wenger. Arduino. Pysical Computing für Bastler, Designer & geeks. O'Reilly, 2009.", page 132 ff.

void setup() 
{
  Serial.begin(9600);
}
void loop()
{
  Serial.println("Hallo");
  Serial.println("--------");
  delay(1000);
}

And after making a connection to /dev/ttyUSB0 with 9600 bit/s and handshake off, I was able to read the Hello by every second. So also the serial connection is damn simple. The next bit was even a bit harder: I want to read out the setting of a poti and send the value to the serial console. That's my first attempt to make a bridge from the real world into the digital world. Here's the setup:

Arduino mit poti.jpg

The poti is a 1 kOhm.

And here's the code:

int potiPin = 0;
int potiVal = 0;

void setup() {
  Serial.begin(9600);
  int potiPin = 0;
}

void loop() {
  int zahl = 10;
  int potiVal = analogRead(potiPin);
  Serial.println("Poti-Wert:");
  Serial.println(potiVal);
  Serial.println("-------------");
  delay(1000);
}

And now when I take a screwdriver and twist around the poti, I am getting different values in my minicom!!!

Poti-Wert:
541
-------------
Poti-Wert:
561
-------------
Poti-Wert:
653
-------------
Poti-Wert:
804
-------------
Poti-Wert:
857
-------------
Poti-Wert:
1018
-------------
Poti-Wert:
1023
-------------
Poti-Wert:
1019

Most remarkable is that the values range from 0 to 1023. So that's just a perfect basis to do further calculations.

Yes, and because I like it small, there's the Arduino Nano. I did roughly the same again based on the Nano. In this case I connected the input from the Poti with the delay of the LED LOW. I can now regulate the blinking frequency. Here's a picture of the setup on my breadboard:

ArduinoNano BlinkPoti.jpg

int potiPin = 0;
int potiVal = 0;
int ledPin = 2;

void setup() {
  int potiPin = 0;
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int potiVal = analogRead(potiPin);
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(potiVal*2);
}

2009-09-19 The following program is there to demostrate how I can talk to the Arduino over the serial interface: After sending a character "B", the blinking goes off, and after sending a "A", it will start again:

int potiPin = 0;
int potiVal = 0;
int blink = 1;
int ledPin = 2;

void setup() {
  Serial.begin(9600);
  int potiPin = 0;
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int potiVal = analogRead(potiPin);
  //Serial.println("Poti-Wert:");
  if (Serial.available() > 0) {
     char b = Serial.read();
     if (b == 65) {
        blink = 1;
     }
     if (b == 66) {
        blink = 0;
     }
  }

  if (blink == 1) {
     digitalWrite(ledPin, HIGH);
     delay(100);
     digitalWrite(ledPin,LOW);
     delay(potiVal*2);
  } else {
     digitalWrite(ledPin, LOW);
  }

  Serial.println(potiVal);
  //Serial.println("-------------");
  delay(10);
}

2009-09-25 After a short setback due to the misunderstood role of the poti that drives the contrast of the lcd panel, I tried it again and I was now successful in driving my LCD panel. I'd never have believed that it is so simple. If you don't see anything on your display but lit characters (nothing black), use a poti and feed a voltage between 0 and 5V into the contrast pin. I found out that in my case, the contrast will be there if I give it exactly 5V. So in my case no need for a poti. But keep in mind that LCDs are very sensitive to heat, so there might be a need to care for that once you mount it into a stable case.

Arduino controls LCD.jpg

Note that I didn't use a resistor to reduce the LCD backlight voltage from 5.0 to 4.2 V. The display can stand that at least for the test.

#include <LiquidCrystal.h>

// Wiring pattern: LiquidCrystal(rs,rw,enable,d0,d1,d2,d3,d4,d5,d6,d7)
LiquidCrystal lcd(12,11,10,9,8,7,6,5,4,3,2);

void setup() {
 lcd.print("arduino");
}

void loop() {}

Yes, and this made me curious if I can also print the digitized value of the poti voltage to my LCD screen. I modified the program a little:

#include <LiquidCrystal.h>

int potiPin = 0;

LiquidCrystal lcd(12,11,10,9,8,7,6,5,4,3,2);

void setup() {
}

void loop() {
 lcd.clear();
 int potiVal = analogRead(potiPin);
 lcd.print(potiVal);
 delay(500);
}

Here's the result. The Arduino displays the poti setting (a value between 0 and 1023) on the LCD display.

Arduino poti2lcd.jpg

This done, I'd consider myself proficient enough to start processing incoming voltages from a directional coupler. Let's no longer worry about the microcontroller. This is all under control and the program shall be written in a few moments. Now I must care for the hardware.

5.3 The Directional Coupler

I'm just about organizing the hardware.

5.4 Next?

  • Come back and see in a few weeks / months...