Skip to content

Commit

Permalink
Moved project to platformio
Browse files Browse the repository at this point in the history
  • Loading branch information
sh123 committed Mar 16, 2023
1 parent 5bec720 commit 7c11cfb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.vscode
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Simple Arduino Nano HF SWR/POWER meter
Arduino Nano based SWR/POWER meter, which can measure SWR and POWER on HF bands from 10-100 mW up to 110W. It is based on popular design with tandem match on binocular toroids and calibrated by using built in power meter from commercial HF transceiver.

![alt text](images/tandem.jpg)
![alt text](extras/images/tandem.jpg)

Metal box is used as a case with SSD1306 display and two PL connectors, powered from 9V battery

![alt text](images/meter.jpg)
![alt text](extras/images/meter.jpg)
File renamed without changes
File renamed without changes
21 changes: 21 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

[platformio]
description = Arduino SWR power meter
default_envs = arduino_nano

[env]
platform = atmelavr
framework = arduino
lib_deps =
contrem/arduino-timer @ 3.0.0
adafruit/Adafruit SSD1306 @ 2.5.7
check_tool = cppcheck
check_flags =
cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK
check_skip_packages = yes
monitor_speed = 115200

[env:arduino_nano]
board = nanoatmega328
board_build.mcu = atmega328p
board_build.f_cpu = 16000000L
120 changes: 61 additions & 59 deletions nano_swr_meter.ino → src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <timer.h>
#include <arduino-timer.h>
#include <math.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
Expand Down Expand Up @@ -58,34 +58,6 @@ double vswr;

auto timer = timer_create_default();

void setup() {
Serial.begin(9600);

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}

display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(8, 8); // Start at top-left corner
display.print(F("SWR meter"));
display.display();
delay(1000);

display.clearDisplay();
display.display();

for (int thisReading = 0; thisReading < numReadings; thisReading++) {
fwdReadings[thisReading] = 0;
rflReadings[thisReading] = 0;
}

timer.every(screenUpdateMs, updateScreen);
}

double toWatts(int val)
{
int v, v_prev;
Expand All @@ -112,36 +84,7 @@ double toWatts(int val)
return 0.0;
}

void loop()
{
int fwdVal = analogRead(fwdPin);
int rflVal = analogRead(rflPin);

fwdTotal = fwdTotal - fwdReadings[readIndex];
fwdReadings[readIndex] = fwdVal;
fwdTotal = fwdTotal + fwdReadings[readIndex];

rflTotal = rflTotal - rflReadings[readIndex];
rflReadings[readIndex] = rflVal;
rflTotal = rflTotal + rflReadings[readIndex];

readIndex = readIndex + 1;

if (readIndex >= numReadings) {
readIndex = 0;
}

fwdAverage = fwdTotal / numReadings;
rflAverage = rflTotal / numReadings;

gamma = (double)rflVal / (double)fwdVal;
vswr = (1 + abs(gamma)) / (1 - abs(gamma));

timer.tick();
delay(50);
}

bool updateScreen()
bool updateScreen(void *)
{
double fwdWatts = toWatts(fwdAverage);
double rflWatts = toWatts(rflAverage);
Expand Down Expand Up @@ -201,3 +144,62 @@ bool updateScreen()

return true;
}

void setup()
{
Serial.begin(9600);

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}

display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(8, 8); // Start at top-left corner
display.print(F("SWR meter"));
display.display();
delay(1000);

display.clearDisplay();
display.display();

for (int thisReading = 0; thisReading < numReadings; thisReading++) {
fwdReadings[thisReading] = 0;
rflReadings[thisReading] = 0;
}

timer.every(screenUpdateMs, updateScreen);
}

void loop()
{
int fwdVal = analogRead(fwdPin);
int rflVal = analogRead(rflPin);

fwdTotal = fwdTotal - fwdReadings[readIndex];
fwdReadings[readIndex] = fwdVal;
fwdTotal = fwdTotal + fwdReadings[readIndex];

rflTotal = rflTotal - rflReadings[readIndex];
rflReadings[readIndex] = rflVal;
rflTotal = rflTotal + rflReadings[readIndex];

readIndex = readIndex + 1;

if (readIndex >= numReadings) {
readIndex = 0;
}

fwdAverage = fwdTotal / numReadings;
rflAverage = rflTotal / numReadings;

gamma = (double)rflVal / (double)fwdVal;
vswr = (1 + abs(gamma)) / (1 - abs(gamma));

timer.tick();
delay(50);
}

0 comments on commit 7c11cfb

Please sign in to comment.