Compare commits

..

13 Commits

Author SHA1 Message Date
2d055ef04f screen is working now, TODO fix wiring diagram 2022-07-30 18:31:03 +01:00
8abf5ba17d rotary almost works 2022-07-29 17:50:32 +01:00
1a2adbffdf rotary works 2022-07-29 17:49:26 +01:00
6294807ed3 commented the logic + tidied it up a bit 2022-07-29 17:26:46 +03:00
017f5b29ee yeet 2022-07-29 17:12:00 +03:00
b66ad843a7 lmao 2022-07-29 17:10:43 +03:00
d50b67fed1 started working on controlling freq + the lil control panel 2022-07-29 03:57:38 +01:00
2b086083cd tried some dry optimization(w/o raspi) 2022-07-25 23:11:33 +03:00
efc5ac36f6 Made some starting efforts for controlling the frequency and the modulation 2022-07-25 16:30:01 +03:00
24e30d7e12 removed unnecessary checklist 2022-07-25 15:57:27 +03:00
0fb56b4447 removed ssb 2022-07-21 01:48:03 +01:00
69dfa4bbe8 removed test 2022-07-21 01:47:20 +01:00
d29f17b57b PTT is working now, added fmrds modulation 2022-07-21 01:47:08 +01:00
9 changed files with 199 additions and 251 deletions

View File

@ -1,163 +0,0 @@
[
{
"Артикул": "Зарядно за LiPo акумулаторни батерии",
"Модел": "XK1866 микро USB зарядно LiPo батерии",
"Кол-во": "1",
"Ед. цена": "6.90лв.",
"Сума": "6.90лв."
},
{
"Артикул": "Акумулатор 12V/9Ah VIPOW",
"Модел": "AKU 12/9AH VIPOW",
"Кол-во": "1",
"Ед. цена": "35.00лв.",
"Сума": "35.00лв."
},
{
"Артикул": "Вакуум помпа ZD192",
"Модел": "IN ZD192",
"Кол-во": "1",
"Ед. цена": "5.90лв.",
"Сума": "5.90лв."
},
{
"Артикул": "Step-up DC-DC адаптер",
"Модел": "TV K ADAP USB 5V-12V 1A 5.5*2.1MM",
"Кол-во": "1",
"Ед. цена": "12.90лв.",
"Сума": "12.90лв."
},
{
"Артикул": "Преход SMA M - BNC M",
"Модел": "F1027 SMA M-BNC M",
"Кол-во": "2",
"Ед. цена": "3.80лв.",
"Сума": "7.60лв."
},
{
"Артикул": "Преход SMA M - BNC Ж",
"Модел": "F1028 SMA M-BNC M",
"Кол-во": "2",
"Ед. цена": "3.80лв.",
"Сума": "7.60лв."
},
{
"Артикул": "Преход SMA Ж - SMA Ж",
"Модел": "F1025 SMA Ж-SMA Ж",
"Кол-во": "2",
"Ед. цена": "3.60лв.",
"Сума": "7.20лв."
},
{
"Артикул": "Пасивен балун комплект приемник/предавател QUICK",
"Модел": "OHR BALUN QUICK K-T",
"Кол-во": "1",
"Ед. цена": "9.50лв.",
"Сума": "9.50лв."
},
{
"Артикул": "Букса BNC-RG58-за кримпване",
"Модел": "F411 BNC 50 КРИМ RG58",
"Кол-во": "6",
"Ед. цена": "0.80лв.",
"Сума": "4.80лв."
},
{
"Артикул": "Букса SMA-RG58-No reverse",
"Модел": "F1020 SMA-RG58 NOREV",
"Кол-во": "2",
"Ед. цена": "3.90лв.",
"Сума": "7.80лв."
},
{
"Артикул": "Човка за поялник ZD C1-2",
"Модел": "IN CH ZD C1-2",
"Кол-во": "1",
"Ед. цена": "2.90лв.",
"Сума": "2.90лв."
},
{
"Артикул": "Човка за поялник PK353T",
"Модел": "IN CH PK353T",
"Кол-во": "1",
"Ед. цена": "3.90лв.",
"Сума": "3.90лв."
},
{
"Артикул": "Резистори 9W - Резистори 9W: 1Ω",
"Модел": "R 9W",
"Кол-во": "5",
"Ед. цена": "0.65лв.",
"Сума": "3.25лв."
},
{
"Артикул": "Резистори 9W - Резистори 9W: 0.1Ω",
"Модел": "R 9W",
"Кол-во": "5",
"Ед. цена": "0.65лв.",
"Сума": "3.25лв."
},
{
"Артикул": "Кондензатор полиестерен 100nF/250V MKT",
"Модел": "100N/250V MKP GER",
"Кол-во": "2",
"Ед. цена": "0.60лв.",
"Сума": "1.20лв."
},
{
"Артикул": "Кондензатор керамичен 1nF/100V X7R",
"Модел": "1N/100V X7R GERM",
"Кол-во": "8",
"Ед. цена": "0.13лв.",
"Сума": "1.04лв."
},
{
"Артикул": "Резистори 9W - Резистори 9W: 10Ω",
"Модел": "R 9W",
"Кол-во": "5",
"Ед. цена": "0.65лв.",
"Сума": "3.25лв."
},
{
"Артикул": "Ферит 27х14,5х11мм",
"Модел": "POR T106-2",
"Кол-во": "1",
"Ед. цена": "3.86лв.",
"Сума": "3.86лв."
},
{
"Артикул": "Ферит мини 9,5 х 10,5 х 2мм",
"Модел": "FERIT MINI",
"Кол-во": "5",
"Ед. цена": "0.35лв.",
"Сума": "1.75лв."
},
{
"Артикул": "Ардуино 61 - Релеен модул с две релета",
"Модел": "ARDUINO61 RELAY MODULE 2*10A/250V",
"Кол-во": 1,
"Ед. цена": "5.95лв.",
"Сума": "5.95лв."
},
{
"Артикул": "Ардуино 64 - Контролен панел TM4638",
"Модел": "ARDUINO64 CONTROL PANEL TM4638",
"Кол-во": 1,
"Ед. цена": "9.90лв.",
"Сума": "9.90лв."
},
{
"Артикул": "Ардуино 40 - Енкодер",
"Модел": "ARDUINO40 ENCODER",
"Кол-во": 1,
"Ед. цена": "3.00лв.",
"Сума": "3.00лв."
},
{
"Артикул": "Копче за потенциометър KP3",
"Модел": "KP 3",
"Кол-во": 3,
"Ед. цена": "0.90лв.",
"Сума": "2.70лв."
}
]

BIN
display Executable file

Binary file not shown.

View File

@ -1,2 +1,2 @@
#!/bin/bash
killall ssh.sh
sudo killall rpitx pifmrds

175
main.py
View File

@ -3,72 +3,147 @@ import pigpio
import time
import datetime
import asyncio
import os
from RPi import GPIO
from itertools import cycle
bands = {
"80m":[3.5, 4],
"40m":[7, 7.3],
"20m":[14, 14.35],
"10m":[28, 29.7],
"2m":[144,146],
"70cm":[430,440]
}
# Setup for encoder
band = cycle(bands)
CURRENT_BAND:str = None
def next_band():
global CURRENT_BAND
CURRENT_BAND = next(band)
FREQUENCY = bands[CURRENT_BAND][0]
print(FREQUENCY)
print(CURRENT_BAND)
return FREQUENCY
def prev_band():
global CURRENT_BAND
CURRENT_BAND = list(bands.keys())[list(bands.keys()).index(CURRENT_BAND)-1]
print(CURRENT_BAND)
FREQUENCY = bands[CURRENT_BAND][0] + 1
return FREQUENCY
FREQUENCY = next_band()
clk=17
dt=27
sw=22
GPIO.setmode(GPIO.BCM)
GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
clkLastState = GPIO.input(clk)
async def rotary(clk=clk, dt=dt, sw=sw, step=0.025):
GPIO.setmode(GPIO.BCM)
GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(sw, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
global FREQUENCY, clkLastState
try:
while True:
clkState = GPIO.input(clk)
dtState = GPIO.input(dt)
swState = GPIO.input(sw)
if swState == GPIO.HIGH:
print("yeet")
if clkState != clkLastState:
if FREQUENCY > bands[CURRENT_BAND][1]:
FREQUENCY = next_band()
print(FREQUENCY)
if FREQUENCY < bands[CURRENT_BAND][0]:
FREQUENCY = prev_band()
print(FREQUENCY)
if dtState != clkState:
FREQUENCY += step
else:
FREQUENCY -= step
# print(round(FREQUENCY, 3))
clkLastState = clkState
await asyncio.sleep(.01)
except KeyboardInterrupt:
print("\nBye")
finally:
print("AAAAA")
GPIO.cleanup()
# 1. Hook up the screen and buttons
# * the screen should show the frequency we're at
# * read the buttons
# 2. Encoder [x]
# * Change frequency in the scope of a given band
PTT_IS_ON:bool = False
modulations = cycle(["./modulations/ssb.sh", "./modulations/fmrds.sh"])
PTT_IS_ON = 0
# init GPIO
pi = pigpio.pi()
# button pin
pi.set_mode(10, pigpio.INPUT)
# modulation change pin(change this)
async def run_command(*args):
"""Run command in subprocess.
Example from:
http://asyncio.readthedocs.io/en/latest/subprocess.html
"""
# Create subprocess
process = await asyncio.create_subprocess_exec(
*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
# Status
process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
print("Started: %s, pid=%s" % (args, process.pid), flush=True)
# Wait for the subprocess to finish
stdout, stderr = asyncio.get_event_loop().create_task(process.communicate())
# Progress
if process.returncode == 0:
print(
"Done: %s, pid=%s, result: %s"
% (args, process.pid, stdout.decode().strip()),
flush=True,
)
else:
print(
"Failed: %s, pid=%s, result: %s"
% (args, process.pid, stderr.decode().strip()),
flush=True,
)
# Result
result = stdout.decode().strip()
asyncio.sleep(5)
# Return stdout
return result
async def button_press(gpio:int, level) -> bool:
async def button_press(gpio:int, level):
# TODO: light an LED
global PTT_IS_ON
while True:
if(pi.read(gpio)!=0):
PTT_IS_ON = 1
if(pi.read(gpio)==0):
PTT_IS_ON = 0
await asyncio.sleep(.5)
if(pi.read(gpio)!=0):
PTT_IS_ON = True
if(pi.read(gpio)==0):
PTT_IS_ON = False
await asyncio.sleep(.01)
# async def frequency(gpio):
# # TODO write this function after hooking up the encoder
async def main():
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
global PTT_IS_ON
# TODO change after figuring out the logic
task_created = False
asyncio.create_task(rotary())
print("Ready")
cached_frequency = FREQUENCY
while True:
if PTT_IS_ON == 1:
while PTT_IS_ON == 1:
await run_command("./ssb.sh")
else:
await run_command("./kill.sh")
if FREQUENCY != cached_frequency:
cached_frequency = FREQUENCY
asyncio.create_task(run_command("./display", str(format(round(FREQUENCY,3), "7f"))))
await button_press(10, pigpio.EITHER_EDGE)
if (PTT_IS_ON and not task_created):
asyncio.create_task(run_command(next(modulations), str(FREQUENCY)))
task_created = True
elif (task_created and not PTT_IS_ON):
await asyncio.sleep(1)
asyncio.create_task(run_command("./kill.sh"))
task_created = False
await asyncio.sleep(.5)
if __name__ == "__main__":
asyncio.run(main())
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\n")

2
modulations/fmrds.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
arecord -q -c2 -t wav -f cd | sudo ./modulations/pifmrds -freq "$1" -audio -

BIN
modulations/pifmrds Executable file

Binary file not shown.

View File

@ -1,37 +1,11 @@
#!/bin/sh
#!/bin/bash
echo $1
echo $2
#arecord -q -c2 -t wav -f dat | sudo rpitx -f $1 -i- - -m $2 -s 48000
# Pin logic
#selecting pin
GPIO=19
# "Prepare" it, whatever that means, I just copied it from SO
if [ ! -d /sys/class/gpio/gpio${GPIO} ]; then
echo "${GPIO}" > /sys/class/gpio/export
fi
echo "in" > /sys/class/gpio/gpio"${GPIO}"/direction
arecord -q -c2 -t wav -f dat | sudo rpitx -i - -m RF -f "$1" -s 48000
# old line
#(while true; do cat sampleaudio.wav; done)
# | csdr convert_i16_f \ | csdr fir_interpolate_cc 2 | csdr dsb_fc \ | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff \ | sudo sendiq -i /dev/stdin -s 96000 -f 430000000 -t float e6 -l
while true; do
if 1 == "$(</sys/class/gpio/gpio"${GPIO}"/value)" ]; then
arecord -q -f cd -r 44100 -c2 -D hw:0,7 -t raw | csdr convert_i16_f \ | csdr fir_interpolate_cc 2 | csdr dsb_fc \ | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff \ | sudo sendiq -i /dev/stdin -s 96000 -f "$1" -t float
# REMOVE THIS
else
echo "Not pressed"
# do arecord -l or arecord -L to find your audio card and change hw:0,7 to the corresponding value
# maybe i just need to extract this command and put it in a subprocess... 🤔
fi
sleep .5
done
# this should work
# screen will probably be operated using python, so all we need to do there is to killall ssb.sh, then run a new one with new freq async subproc
# usage: bash ssb.sh "freq"

64
rotary.py Normal file
View File

@ -0,0 +1,64 @@
from functools import wraps, partial
from RPi import GPIO
from time import sleep
from itertools import cycle
clkLastState = GPIO.input(clk)
counter = next_band()
bands = {
"80m":[3.5, 4],
"40m":[7, 7.3],
"20m":[14, 14.35],
"10m":[28, 29.7],
"2m":[144,146],
"70cm":[430,440]
}
# Setup for encoder
band = cycle(bands)
CURRENT_BAND = None
step = 0.025
def next_band():
global CURRENT_BAND
CURRENT_BAND = next(band)
counter = bands[CURRENT_BAND][0]
print(counter)
print(CURRENT_BAND)
return counter
def prev_band():
global CURRENT_BAND
CURRENT_BAND = list(bands.keys())[list(bands.keys()).index(CURRENT_BAND)-1]
print(CURRENT_BAND)
counter = bands[CURRENT_BAND][0] + 1
return counter
async def main_loop(clk, dt, sw):
try:
clkState = GPIO.input(clk)
dtState = GPIO.input(dt)
swState = GPIO.input(sw)
if swState == GPIO.HIGH:
print("yeet")
if clkState != clkLastState:
if counter > bands[CURRENT_BAND][1]:
counter = next_band()
if counter < bands[CURRENT_BAND][0]:
counter = prev_band()
if dtState != clkState:
counter += step
else:
counter -= step
# print(round(counter, 3))
clkLastState = clkState
sleep(0.01)
except KeyboardInterrupt:
print("\nBye")
finally:
print("AAAAA")
GPIO.cleanup()

4
ssb.sh
View File

@ -1,4 +0,0 @@
#!/bin/bash
counter=1
arecord -q -c1 -d 100 -t wav | csdr convert_i16_f \ | csdr fir_interpolate_cc 2 | csdr dsb_fc \ | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff \ | sudo sendiq -i /dev/stdin -s 96000 -f 430000000 -t float e6 -l