Hi,
In the attached flowgraph the timing is correct in both of the time
sinks and the audio output. However, I have been unable to get the
output to the GPIO pin synchronized with the rest of it. It seems to
consume all of the data without waiting for the other output. Any ideas
on what to do?
Your help is greatly appreciated.
--
Barry Duggan
options:
parameters:
author: Barry Duggan
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: ''
description: Morse code generator
gen_cmake: 'On'
gen_linking: dynamic
generate_options: qt_gui
hier_block_src_path: '.:'
id: test0928
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: prompt
sizing_mode: fixed
thread_safe_setters: ''
title: Test 0928
window_size: ''
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [16, 16.0]
rotation: 0
state: enabled
blocks:
- name: baud
id: variable
parameters:
comment: ''
value: speed/1.2
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [400, 20.0]
rotation: 0
state: enabled
- name: repeat
id: variable
parameters:
comment: ''
value: '1200'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [560, 20.0]
rotation: 0
state: true
- name: samp_rate
id: variable
parameters:
comment: ''
value: baud*repeat
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [688, 20.0]
rotation: 0
state: enabled
- name: speed
id: variable
parameters:
comment: ''
value: '12'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [288, 20.0]
rotation: 0
state: true
- name: analog_sig_source_x_0_0
id: analog_sig_source_x
parameters:
affinity: ''
alias: ''
amp: '0.5'
comment: ''
freq: '600'
maxoutbuf: '0'
minoutbuf: '0'
offset: '0'
phase: '0'
samp_rate: samp_rate
type: float
waveform: analog.GR_COS_WAVE
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [678, 454]
rotation: 0
state: enabled
- name: audio_sink_0
id: audio_sink
parameters:
affinity: ''
alias: ''
comment: ''
device_name: hw:CARD=Device,DEV=0
num_inputs: '1'
ok_to_block: 'True'
samp_rate: '48000'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1300, 494]
rotation: 0
state: enabled
- name: blocks_float_to_uchar_0
id: blocks_float_to_uchar
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [945, 121]
rotation: 0
state: true
- name: blocks_multiply_xx_0
id: blocks_multiply_xx
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
num_inputs: '2'
type: float
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [936, 364]
rotation: 0
state: enabled
- name: blocks_repeat_0
id: blocks_repeat
parameters:
affinity: ''
alias: ''
comment: ''
interp: repeat
maxoutbuf: '0'
minoutbuf: '0'
type: byte
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [483, 360]
rotation: 0
state: enabled
- name: blocks_uchar_to_float_0
id: blocks_uchar_to_float
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [668, 364]
rotation: 0
state: enabled
- name: epy_block_0
id: epy_block
parameters:
_source_code: "\"\"\"\nMorse code vector source\n\"\"\"\n\n#
epy_block_0.py\n\
# revised 08/20/2019\n# revised 09/27/2019 to clear input line (code
from\
\ Volker Schroer dl1ksv)\n\nimport numpy as np\nfrom gnuradio import
gr\n\n\
import pmt\n\ntextboxValue = \"\"\n\nMorse = {\n \"A\":
\"1,0,1,1,1\",\n\
\ \"B\": \"1,1,1,0,1,0,1,0,1\",\n \"C\":
\"1,1,1,0,1,0,1,1,1,0,1\",\n\
\ \"D\": \"1,1,1,0,1,0,1\",\n \"E\": \"1\",\n \"F\":
\"1,0,1,0,1,1,1,0,1\"\
,\n \"G\": \"1,1,1,0,1,1,1,0,1\",\n \"H\": \"1,0,1,0,1,0,1\",\n
\"\
I\": \"1,0,1\",\n \"J\": \"1,0,1,1,1,0,1,1,1,0,1,1,1\",\n \"K\":
\"1,1,1,0,1,0,1,1,1\"\
,\n \"L\": \"1,0,1,1,1,0,1,0,1\",\n \"M\": \"1,1,1,0,1,1,1\",\n
\"\
N\": \"1,1,1,0,1\",\n \"O\": \"1,1,1,0,1,1,1,0,1,1,1\",\n \"P\":
\"1,0,1,1,1,0,1,1,1,0,1\"\
,\n \"Q\": \"1,1,1,0,1,1,1,0,1,0,1,1,1\",\n \"R\":
\"1,0,1,1,1,0,1\",\n\
\ \"S\": \"1,0,1,0,1\",\n \"T\": \"1,1,1\",\n \"U\":
\"1,0,1,0,1,1,1\"\
,\n \"V\": \"1,0,1,0,1,0,1,1,1\",\n \"W\": \"1,0,1,1,1,0,1,1,1\",\n
\
\ \"X\": \"1,1,1,0,1,0,1,0,1,1,1\",\n \"Y\":
\"1,1,1,0,1,0,1,1,1,0,1,1,1\"\
,\n \"Z\": \"1,1,1,0,1,1,1,0,1,0,1\",\n \" \": \"0\", #
space\n\
\ \"1\": \"1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1\",\n \"2\":
\"1,0,1,0,1,1,1,0,1,1,1,0,1,1,1\"\
,\n \"3\": \"1,0,1,0,1,0,1,1,1,0,1,1,1\",\n \"4\":
\"1,0,1,0,1,0,1,0,1,1,1\"\
,\n \"5\": \"1,0,1,0,1,0,1,0,1\",\n \"6\":
\"1,1,1,0,1,0,1,0,1,0,1\",\n\
\ \"7\": \"1,1,1,0,1,1,1,0,1,0,1,0,1\",\n \"8\":
\"1,1,1,0,1,1,1,0,1,1,1,0,1,0,1\"\
,\n \"9\": \"1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1\",\n \"0\":
\"1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1\"\
,\n \".\": \"1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,1,1\", #
period\n \
\ \",\": \"1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1\", # comma\n
\"?\"\
: \"1,0,1,0,1,1,1,0,1,1,1,0,1,0,1\", # question\n
\"'\":\
\ \"1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1\", # apostrophe\n
\"/\": \"\
1,1,1,0,1,0,1,0,1,1,1,0,1\", # slash\n \":\":
\"1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,1\"\
, # colon\n \"=\": \"1,1,1,0,1,0,1,0,1,0,1,1,1\",
\
\ # equals\n \"-\": \"1,1,1,0,1,0,1,0,1,0,1,0,1,1,1\"
\
\ # dash or minus\n }\n\n\nclass
mc_sync_block(gr.sync_block):\n\
\ \"\"\"\n reads input from a message port\n generates a vector
of\
\ Morse code bits\n \"\"\"\n def __init__(self):\n
gr.sync_block.__init__(self,\n\
\ name = \"Morse code vector source\",\n in_sig =
None,\n\
\ out_sig = [np.byte])\n
self.message_port_register_in(pmt.intern('msg_in'))\n\
\ self.message_port_register_out(pmt.intern('clear_input'))\n
\
\ self.set_msg_handler(pmt.intern('msg_in'), self.handle_msg)\n\n def
handle_msg(self,\
\ msg):\n global textboxValue\n\n textboxValue =
pmt.symbol_to_string\
\ (msg)\n # print (textboxValue)\n \n def work(self,
input_items,\
\ output_items):\n global Morse\n global textboxValue\n\n
\
\ bit_stream = \"\"\n for in0 in textboxValue:\n #
get\
\ next char\n inChar = str (in0)\n # convert to
upper\
\ case\n ch = inChar.upper()\n # get vector\n
\
\ _dots = str (Morse.get(ch))\n # print (ch, _dots)\n
\
\ bit_stream += (_dots + \",0,0,0,\") # letter space\n\n if
(len(textboxValue)\
\ > 0):\n bit_stream += \"0,0,0,0\" # finish with word
space\n\
\ textboxValue = \"\"\n
self.message_port_pub(pmt.intern('clear_input'),\
\ pmt.intern(''))\n # print (bit_stream)\n\n # get
length\
\ of string\n _len = len(bit_stream)\n # num of elements =
(length+1)\
\ / 2\n _num_elem = int((_len+1) / 2)\n\n # convert and
store\
\ elements in output array\n for x in range (_len):\n y
=\
\ int(x / 2)\n if (bit_stream[x] == '1'):\n
output_items[0][y]\
\ = 1\n elif (bit_stream[x] == '0'):\n
output_items[0][y]\
\ = 0\n else:\n continue # skip commas\n\n
\
\ return (_num_elem)\n\n"
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
states:
_io_cache: ('Morse code vector source', 'mc_sync_block', [], [('msg_in',
'message',
1)], [('0', 'byte', 1), ('clear_input', 'message', 1)], '\n reads
input from
a message port\n generates a vector of Morse code bits\n ', [])
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [189, 364]
rotation: 0
state: true
- name: epy_block_1
id: epy_block
parameters:
_source_code: "\"\"\"\nGPIO pin driver\n\"\"\"\n\n# epy_block_1.py\n#
09/28/2019\n\
\nimport numpy as np\nfrom gnuradio import gr\nimport RPi.GPIO as GPIO
\n\n\
_last_bit = 0\n\nclass gpio_block(gr.sync_block):\n \"\"\"\n reads
keying\
\ data\n drives GPIO line 17\n note: this is a data sink\n
\"\"\"\n\
\n def __init__(self):\n gr.sync_block.__init__(self,\n
\
\ name = \"GPIO pin driver\",\n in_sig = [np.byte],\n
\
\ out_sig = None\n )\n GPIO.setwarnings(False) \n
\
\ GPIO.setmode(GPIO.BCM) \n GPIO.setup(17, GPIO.OUT) \n
GPIO.output(17,\
\ False) # start with it off\n\n def work(self, input_items,
output_items):\n\
\ global _last_bit\n\n for _in_bit in input_items[0]:\n
\
\ if (_in_bit != _last_bit):\n if (_in_bit == 1):\n
\
\ GPIO.output(17, True) \n else:\n
\
\ GPIO.output(17, False)\n _last_bit = _in_bit\n\n
\
\ return len (input_items[0])\n"
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
states:
_io_cache: '(''GPIO pin driver'', ''gpio_block'', [], [(''0'', ''byte'',
1)],
[], ''\n reads keying data\n drives GPIO line 17\n note: this is
a
data sink\n '', [])'
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1130, 121]
rotation: 0
state: enabled
- name: qtgui_edit_box_msg_0
id: qtgui_edit_box_msg
parameters:
affinity: ''
alias: ''
comment: ''
gui_hint: ''
is_pair: 'False'
is_static: 'False'
key: '"text"'
label: Input
maxoutbuf: '0'
minoutbuf: '0'
type: string
value: '""'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [218, 506]
rotation: 180
state: true
- name: qtgui_time_sink_x_0
id: qtgui_time_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
axislabels: 'True'
color1: blue
color10: dark blue
color2: red
color3: green
color4: black
color5: cyan
color6: magenta
color7: yellow
color8: dark red
color9: dark green
comment: ''
ctrlpanel: 'False'
entags: 'True'
grid: 'False'
gui_hint: ''
label1: ''
label10: ''
label2: ''
label3: ''
label4: ''
label5: ''
label6: ''
label7: ''
label8: ''
label9: ''
legend: 'True'
marker1: '-1'
marker10: '-1'
marker2: '-1'
marker3: '-1'
marker4: '-1'
marker5: '-1'
marker6: '-1'
marker7: '-1'
marker8: '-1'
marker9: '-1'
name: '""'
nconnections: '1'
size: '32768'
srate: '48000'
stemplot: 'False'
style1: '1'
style10: '1'
style2: '1'
style3: '1'
style4: '1'
style5: '1'
style6: '1'
style7: '1'
style8: '1'
style9: '1'
tr_chan: '0'
tr_delay: '0'
tr_level: '0.5'
tr_mode: qtgui.TRIG_MODE_AUTO
tr_slope: qtgui.TRIG_SLOPE_POS
tr_tag: '""'
type: float
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
ylabel: Amplitude
ymax: '2'
ymin: '-1'
yunit: '""'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1337, 360]
rotation: 0
state: enabled
- name: qtgui_time_sink_x_1
id: qtgui_time_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
axislabels: 'True'
color1: blue
color10: dark blue
color2: red
color3: green
color4: black
color5: cyan
color6: magenta
color7: yellow
color8: dark red
color9: dark green
comment: ''
ctrlpanel: 'False'
entags: 'True'
grid: 'False'
gui_hint: ''
label1: Signal 1
label10: Signal 10
label2: Signal 2
label3: Signal 3
label4: Signal 4
label5: Signal 5
label6: Signal 6
label7: Signal 7
label8: Signal 8
label9: Signal 9
legend: 'True'
marker1: '-1'
marker10: '-1'
marker2: '-1'
marker3: '-1'
marker4: '-1'
marker5: '-1'
marker6: '-1'
marker7: '-1'
marker8: '-1'
marker9: '-1'
name: '""'
nconnections: '1'
size: '32768'
srate: samp_rate
stemplot: 'False'
style1: '1'
style10: '1'
style2: '1'
style3: '1'
style4: '1'
style5: '1'
style6: '1'
style7: '1'
style8: '1'
style9: '1'
tr_chan: '0'
tr_delay: '0'
tr_level: '0.5'
tr_mode: qtgui.TRIG_MODE_AUTO
tr_slope: qtgui.TRIG_SLOPE_POS
tr_tag: '""'
type: float
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
ylabel: Amplitude
ymax: '2'
ymin: '-1'
yunit: '""'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [990, 208]
rotation: 0
state: true
- name: rational_resampler_xxx_0
id: rational_resampler_xxx
parameters:
affinity: ''
alias: ''
comment: ''
decim: '1'
fbw: '0'
interp: (int)(48000/samp_rate)
maxoutbuf: '0'
minoutbuf: '0'
taps: ''
type: fff
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1091, 352]
rotation: 0
state: true
connections:
- [analog_sig_source_x_0_0, '0', blocks_multiply_xx_0, '1']
- [blocks_float_to_uchar_0, '0', epy_block_1, '0']
- [blocks_multiply_xx_0, '0', rational_resampler_xxx_0, '0']
- [blocks_repeat_0, '0', blocks_uchar_to_float_0, '0']
- [blocks_uchar_to_float_0, '0', blocks_float_to_uchar_0, '0']
- [blocks_uchar_to_float_0, '0', blocks_multiply_xx_0, '0']
- [blocks_uchar_to_float_0, '0', qtgui_time_sink_x_1, '0']
- [epy_block_0, '0', blocks_repeat_0, '0']
- [epy_block_0, clear_input, qtgui_edit_box_msg_0, val]
- [qtgui_edit_box_msg_0, msg, epy_block_0, msg_in]
- [rational_resampler_xxx_0, '0', audio_sink_0, '0']
- [rational_resampler_xxx_0, '0', qtgui_time_sink_x_0, '0']
metadata:
file_format: 1
"""
GPIO pin driver
"""
# epy_block_1.py
# 09/28/2019
import numpy as np
from gnuradio import gr
import RPi.GPIO as GPIO
_last_bit = 0
class gpio_block(gr.sync_block):
"""
reads keying data
drives GPIO line 17
note: this is a data sink
"""
def __init__(self):
gr.sync_block.__init__(self,
name = "GPIO pin driver",
in_sig = [np.byte],
out_sig = None
)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, False) # start with it off
def work(self, input_items, output_items):
global _last_bit
for _in_bit in input_items[0]:
if (_in_bit != _last_bit):
if (_in_bit == 1):
GPIO.output(17, True)
else:
GPIO.output(17, False)
_last_bit = _in_bit
return len (input_items[0])
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio