Raspberry Pi turn on AV Receiver CEC - linux

I have an AV Receiver that I want to turn on from standby using cec-client on raspberry pi. The physicall setup is as follows:
RPI --HDMI--> AV Receiver
TV <--ARC_HDMI--> AV Receiver
Scanning my HDMI devices with echo "scan" | cec-client -s -d 1 I get following output:
opening a connection to the CEC adapter...
requesting CEC bus information ...
CEC bus information
===================
device #0: TV
address: 0.0.0.0
active source: no
vendor: Samsung
osd string: TV
CEC version: unknown
power status: standby
language: ger
device #1: Recorder 1
address: 1.0.0.0
active source: no
vendor: Pulse Eight
osd string: CECTester
CEC version: 1.4
power status: on
language: eng
device #5: Audio
address: 3.0.0.0
active source: no
vendor: Harman/Kardon
osd string: H/K AVR
CEC version: 1.4
power status: standby
language: ???
As you can see, my AV Receiver has the device number #5 and physical address 3.0.0.0
I tried following already, using cec-o-matic as reference:
echo "on 3.0.0.0" | cec-client -s -d 0
echo "on 5" | cec-client -s -d 0
echo "tx 15:04" | cec-client -s -d 0
But neither command turns on the AV Receiver. The same commands addressing the TV work without an issue.
After a lot of trial and error, I found out that rebooting my Raspberry Pi actually turns on the receiver! Nice, at least something. Investigating further I found out that in /boot/config.txt one can add/set the hdmi_ignore_cec_init=1 parameter to indicate whether the Raspberry Pi should send an active source message while rebooting. Depending on whether this is set to 0 or 1 my AV receiver turns on when I boot/reboot my RPI.
Now, I obviously don't want to reboot my RPI whenever I want to turn on my AV Receiver. So my question is what is the specific CEC-message the Raspberry sends on boot, so I can replicate it with the cec-client with something along the lines of echo "tx <specific-cec-message>" | cec-client -s -d 1
I already tried monitoring cec traffic on boot with cec-client -f cec.log, but monitoring starts too late and misses the send signal from RPI on boot.
The easiest way to find this out would probably to have a second Raspberry Pi monitoring the bus while the other one boots, but I only have 1 RPI, so I can not test it myself.
Does anyone have an idea, or at least a source for me? Big Thanks for taking the time!
In case it matters here also the specific device models.
TV: Samsung ue55f8090
AVR: Harman Kardon AVR 156
RPI: Raspberry Pi 4 Model B Rev 1.4
RPI_OS: Raspbian GNU/Linux 10 (buster) armv
RPI_KERNEL: Kernel: 5.10.103-v7l+

After more digging, I finally found a solution to my specific problem.
For my setup, as described in my question, one can turn on the Harman Kardon AVR 156 by broadcasting an active source message with the physical address of the TV.
echo "tx 1f:82:00:00" | cec-client -s -d 1
A breakdown of the CEC Frame:
1 = Recording 1 (Raspberry Pi)
F = Broadcast
82 = Active Source
00 00 = ID (TV)
I hope this helps anyone stumbling on this in the future!

Related

Debian 9 Dummy Output after resume from suspend (snd_hda_intel codec)

I have an external monitor that I plug-in my Dell laptop after turn it on. The sound works before and after plug it in the Laptop, So the headphone works too, plugin it in and out too. The problem is when I resume Debian after suspend. The sound has gone, and some times when increasing and decreasing volume one of the three options appears in the screen: Headphone unplugged, HDMI output (or something like), or Dummy Output.
I will show now what happens when Dummy Output is displayed and some outputs of commands.
$ lspci | grep Audio
Output:
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)
$ lsmod | grep hda
Output:
snd_hda_ext_core 28672 1 snd_soc_skl
snd_hda_intel 36864 0
snd_hda_codec 135168 1 snd_hda_intel
snd_hda_core 90112 4 snd_hda_intel,snd_hda_codec,snd_hda_ext_core,snd_soc_skl
snd_hwdep 16384 1 snd_hda_codec
snd_pcm 110592 6 snd_hda_intel,snd_hda_codec,snd_hda_ext_core,snd_hda_core,snd_soc_skl,snd_soc_core
snd 86016 7 snd_compress,snd_hda_intel,snd_hwdep,snd_hda_codec,snd_timer,snd_soc_core,snd_pcm
$ sudo dmesg | grep snd
Output (when rebooting):
[ 13.341580] snd_hda_intel 0000:00:1f.3: bound 0000:00:02.0 (ops i915_audio_component_bind_ops [i915])
[ 13.461226] snd_hda_intel 0000:00:1f.3: CORB reset timeout#1, CORBRP = 0
[ 13.462799] snd_hda_intel 0000:00:1f.3: no codecs found!
$ sudo alsactl init
Output:
alsactl: init:1757: No soundcards found...
Complete Alsa Information script:
https://alsa-project.org/db/?f=ff03c7d8dac369fc1211822de963b337c132420c
So it looks like the sound card is there but alsa does not recognize it.
Many forums/sites recommend to blacklist snd_hda_codec_hdmi (that would be the case when the problem is with connecting/desconnecting HDMI for the external monitor), and also put a line:
options snd-hda-intel model=generic
in a file, e.g., /etc/modprobe.d/alsa-base-blacklist.conf.
But it didn't work.
Other sites suggest to disable and enable sound in BIOS. Didn't work.
Can anyone help me solve this forever issue?

Bluetooth LE Signal Strength Linux

Hello is there any way to get the signal strength of near by bluetooth le devises in linux? Or any good libraries for nodejs, php or mono (I do know some c++ or python but would prefer to say away from them) if a tool does not exisst but would be fairly easy to write.
On Linux, the way to do this is with the hcitool command. However, you have to be connected to get the rssi of a device. If you want to achieve this from the command line, try:
#hcitool rssi AA:BB:CC:DD:EE:FF
If you want to see the actual C code to achieve this, take a look at the bluez tools/hcitool.c file, under the cmd_rssi function.
static void cmd_rssi(int dev_id, int argc, char **argv)
{
...
}
For Bluetooth Low Energy, I only know one way to do this, and that is using the #btmon command. Run btmon in the background then scan for Bluetooth Low Energy devices:
#./btmon &
# hcitool lescan
The results displayed on the monitor should be similar to this:
> HCI Event: LE Meta Event (0x3e) plen 12
LE Advertising Report (0x02)
Num reports: 1
Event type: Scan response - SCAN_RSP (0x04)
Address type: Public (0x00)
Address: AA:BB:CC:DD:EE:FF (<Vendor Name>)
Data length: 0
***RSSI: -34 dBm (0xde)***
AA:BB:CC:DD:EE:FF <Device Name>
Note that when using btmon you do not have to connect to get the rssi of a BLE device.
No need to connect when using btmgmt
$ sudo btmgmt find
Discovery started
hci0 type 7 discovering on
hci0 dev_found: 50:8C:FD:99:0A:EC type LE Random rssi -80 flags 0x0000
AD flags 0x06
eir_len 23
…
The relative signal strength indicator is rssi -80, but the list is much longer containing more information about this and other devices.
To spy on your Bluetooth neighbourhood showing only unique MAC addresses with their strongest RSSI, run the following command:
$ sudo btmgmt find |grep rssi |sort -n |uniq -w 33
hci0 dev_found: 40:43:42:B3:71:11 type LE Random rssi -53 flags 0x0000
hci0 dev_found: 44:DA:5F:EA:C6:CF type LE Random rssi -78 flags 0x0000
hci0 dev_found: 7F:7D:08:6B:E0:37 type LE Random rssi -74 flags 0x0000
hci0 dev_found: A4:58:0F:21:A1:8C type BR/EDR rssi -79 flags 0x0000
You can use a combination of:
sudo hcitool lescan --duplicates & ;
sudo hcidump --raw
that will provide you the raw dump of all the bluetooth packets which contain all relevant information you must be interested in such as : UUID, Major, Minor, RSSI, TxPower. You will have to run some kind of script to parse and filter LE packets and make them into readable form.
One of the scripts written with Bash and S editor was provided by jjnebaker here with the problem and solution discussed here
The Other option is to use PyBluez using the example code here
But you might find the solution provided by Switchdoc labs useful according to your needs as well. here
This works for c language, but has an error when casting the bytes that have the information about de rssi signal.
https://github.com/glock45/intel-edison-playground/blob/master/scan.c
this line 121:
printf("%s - RSSI %d\n", addr, (**char**)info->data[info->length]);
should be:
printf("%s - RSSI %d\n", addr, (**int8_t**)info->data[info->length]);
I found these by looking inside bluez-version/monitor/*.c, where btmon program is. You can see the data types and structs, hcidump.c is very useful and packets.c, and main.c too, but there are many to learn about the hci sockets.
I also found a program I was able to edit to do what I wanted as well
I through it up on my github account
https://github.com/tholum/bluez/blob/master/blue.py
i found several solutions, but most were too slow for my needs to use as a tracking function.
check out https://github.com/abandonware/noble containing some examples.
my standalone scanner is also based on abandonware's module and can be found here:
https://github.com/efeuentertainment/BLE-continuous-RSSI-scan
node index.js BLEMAC
continuously lists the RSSI with an update frequency of about 2 per second / depending on BLE device.
also fast updates based on bash is:
sudo hcitool lescan --duplicates &
combined with one of the following lines:
continuous updates
sudo hcidump | grep "E6:4E:57:09:74:E4" -A 4
sudo btmon | grep "E6:4E:57:09:74:E4" -A 7
only the next received update
sudo hcidump | grep -m 1 "E6:4E:57:09:74:E4" -A 4 | grep "RSSI"
sudo btmon | grep -m 1 "E6:4E:57:09:74:E4" -A 7 | grep "RSSI"
hope that helps. it's an old thread but my search engine lead me here anyway.
try :
$ bluez-test-discovery
output :
[ 18:7A:93:05:E4:B1 ]
Name = AMIYJ_E4B1
Paired = 0
LegacyPairing = 0
Alias = AMIYJ_E4B1
Broadcaster = 0
UUIDs = dbus.Array([dbus.String(u'0000fff0-0000-1000-8000-00805f9b34fb')], signature=dbus.Signature('s'), variant_level=1)
Address = 18:7A:93:05:E4:B1
RSSI = -65
Class = 0x000000
gives you : RSSI = -65
For connected devices you can use btmgmt conn-info
e.g.
$ sudo btmgmt conn-info -t 2 E4:0C:E6:59:B6:FC
Connection Information for E4:0C:E6:59:B6:FC (LE Random)
RSSI -78 TX power 0 maximum TX power 0
(You have the code for that command at https://github.com/bluez/bluez/blob/150bbff449c787f26b7de3e6006bdb2ea6365b08/tools/btmgmt.c#L3984-L4030 ).
I think you may also be able to use BlueZ's DBus RSSI property of the org.bluez.Device1 interface :
int16 RSSI [readonly, optional]
Received Signal Strength Indicator of the remote
device (inquiry or advertising).
but that didn't work for me:
$ dbus-send --print-reply=literal --system --dest=org.bluez /org/bluez/hci0/dev_E4_0C_E6_59_B6_FC org.freedesktop.DBus.Properties.Get string:"org.bluez.Device1" string:"RSSI"
Error org.freedesktop.DBus.Error.InvalidArgs: No such property 'RSSI'
Maybe because the property is optional. Some other properties did work for me:
$ dbus-send --print-reply=literal --system --dest=org.bluez /org/bluez/hci0/dev_E4_0C_E6_59_B6_FC org.freedesktop.DBus.Properties.Get string:"org.bluez.Device1" string:"Name"
variant eono BTC 01

RS232 console communication - set baudrate to 1 MBaud

Within a bash script, I use the following:
$ stty -F /dev/ttyUSB0 921600 raw
$ echo -n "some test data" >/dev/ttyUSB0
and it works as expected.
Using a PL2303 USB to RS232 adapter:
$ lsusb
...
Bus 006 Device 010: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 006 Device 011: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Now I tried to do the same with 1 MBd, but got an error:
$ stty -F /dev/ttyUSB0 1000000 raw
stty: /dev/ttyUSB0: unable to perform all requested operations
Also the same message when I try with 500 kBd. Trying 250 kBd the error message is different:
$ stty -F /dev/ttyUSB0 250000 raw
stty: invalid argument `250000'
Try `stty --help' for more information.
As seen here, it's a problem in the PL2303 linux driver.
I'm working on Kubuntu 12.04, 32 Bit. Unfortunally, I don't know how to fix that driver on my system (getting driver source, patch em, compile, install … hmm, maybe I learn a bit and give it a try - advice is welcome).
But maybe there is an updated driver avaliable which is easy to install?
Or does someone know an alternate USB to RS232 adapter which works at 1 MBd (hardware flowcontrol via rts/cts is needed, which works pretty well with the PL2303)?
After the realization that »Prolific and FTDI are competitors«, I bought Ftdi US232R-10 which is a FT232R based device and specified for 1 MBd transfer rate.
With this adapter I'd successfully tested communication at 1 MBd by transfering some GiB data without any error (including usage of Rts/Cts hardware flow control).
Configuring this device using stty like:
$ stty -F /dev/ttyUSB0 1000000 raw
works successfully.

How do I configure JACK audio server to automatically use a specific card?

I'm running Ubuntu 12.04 studio on a HP Pavilion dm1 4200sg netbook. It's pretty much a fresh install. I try to start jackd server by running
jackd -R -d alsa
and it fails with output:
JACK server starting in realtime mode with priority 10
control device hw:0
control device hw:0
audio_reservation_init
Acquire audio card Audio0
creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
control device hw:0
ALSA: Cannot open PCM device alsa_pcm for playback. Falling back to capture-only mode
Cannot initialize driver
JackServer::Open() failed with -1
Failed to open server
Running aplay -l gives the following output:
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: SB [HDA ATI SB], device 0: STAC92xx Analog [STAC92xx Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
I find that by running
jackd -R -d alsa -d hw:1
jackd starts successfully. I would like to configure my machine so that hw:1 is the default option (i.e. to make the original 'jackd -R -d alsa' command work). Can anyone help me to do this?
I've tried editing ~/.asoundrc to be
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
but this doesn't seem to work. I'm well out of my comfort zone here and any help would be appreciated. Thanks!
I've found a workaround. It doesn't configure JACK server but alters the order the sound cards are listed.
I first entered into the terminal:
sudo lshw -c multimedia
which showed which modules the two cards were using. They were both using 'snd-hda-intel'.
I then entered into the terminal:
cat /proc/asound/card0/id
cat /proc/asound/card1/id
Which gave ids 'Generic' and 'SB' for cards 0 and 1, respectively.
I then added the following two lines to the end of the file '/etc/modprobe.d/alsa-base.conf'
options snd-hda-intel id=SB index=0
options snd-hda-intel id=Generic index=1
After rebooting the machine, card 'SB' was loaded into position 0 and
jackd -R -d alsa
correctly started.
First, in a terminal window, run this command:
cat /proc/asound/cards.
You’ll see output a bit like this:
0 [SB ]: HDA-Intel - HDA ATI SB
HDA ATI SB at 0xfcef8000 irq 16
1 [DSP ]: H-DSP - Hammerfall DSP
RME Hammerfall DSP + Digiface at 0xfcff0000, irq 20
2 [NVidia ]: HDA-Intel - HDA NVidia
HDA NVidia at 0xfe57c000 irq 32
The “name” of each soundcard is in square brackets.
With this information, you can now refer to a particular device as, for example hw:DSP now you can execute the command:
jackd -d alsa -d hw:DSP
And thats all, taken from:
http://www.jackaudio.org/faq/device_naming.html
EDIT: added code tags
First, open up alsa-base.conf:
sudo gedit /etc/modprobe.d/alsa-base.conf
Find the following line:
"options snd-hda-intel index=-2"
And change it to:
"#options snd-hda-intel index=-2"
Restart your machine and try again. You may have to set the proper sound device (alsa) for your programs.

AVR ISP MKII, avrdude, Ubuntu 11.10

So, I have had this working on Ubuntu before. But then I upgraded to 11.10. Now, no such luck.
Note: if you are still messing with getting this to work on eclipse, you might want to try this command line stuff... if it doesnt work here, its not going to work in eclipse.
I have this error:
avrdude: stk500v2_command(): command failed
avrdude: stk500v2_command(): unknown status 0xc9
avrdude: stk500v2_program_enable(): cannot get connection status
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
I have tried with all different configurations.
ie: -B 1 ,10, 1000,
-F doesn't help becuase then you just get back 000000 or whatever as your serial.
Also, I should mention, clearly from the output below, you can see that it gets to the programmer and even to the target board and reads its voltage out.
You can also see the target chip reset. (ie: i have tested on a number of devices includeing a DB101 and you can see when it resets)
The full output is like this:
> avrdude -c avrispmkII -P usb -p m1281 -B 100 -v
avrdude: Version 5.10, compiled on Jun 29 2010 at 03:44:14
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is "/etc/avrdude.conf"
User configuration file is "/home/david/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : usb
Using Programmer : avrispmkII
Setting bit clk period : 100.0
avrdude: usbdev_open(): Found AVRISP mkII, serno: 000200037289
AVR Part : ATMEGA1281
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 10 8 0 no 4096 8 0 9000 9000 0x00 0x00
flash 65 10 256 0 yes 131072 256 512 4500 4500 0x00 0x00
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : STK500V2
Description : Atmel AVR ISP mkII
Programmer Model: AVRISP mkII
Hardware Version: 1
Firmware Version Master : 1.13
Vtarget : 5.1 V
SCK period : 100.37 us
avrdude: stk500v2_command(): command failed
avrdude: stk500v2_command(): unknown status 0xc9
avrdude: stk500v2_program_enable(): cannot get connection status
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.
I already have the udev stuff set up:
ie:
cat /etc/udev/rules.d/60-avrisp.rules
SUBSYSTEM!="usb_device", ACTION!="add", GOTO="avrisp_end"
# Atmel Corp. JTAG ICE mkII
ATTR{idVendor}=="03eb", SYSFS{idProduct}=="2103", MODE="660", GROUP="dialout"
# Atmel Corp. AVRISP mkII
ATTR{idVendor}=="03eb", SYSFS{idProduct}=="2104", MODE="660", GROUP="dialout"
# Atmel Corp. Dragon
ATTR{idVendor}=="03eb", SYSFS{idProduct}=="2107", MODE="660", GROUP="dialout"
LABEL="avrisp_end"
The board AND the programmer work with AVR studio on another machine.
Apparently a lot of people have this issue on Linux. :(
Dont really want to have to dig up a winblows box.
I had a really hard time getting mine to work as well. In the end, I tripped over http://wiki.dataflow.ws/Electronix/AvrIsp2OnOSX and found that I had actually missed a package. After installing uisp
sudo apt-get install uisp
I ran
sudo avrdude -c avrispmkII -p m168 -P usb: -B 8 -v -U lock:w:0x3f:m -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0x0:m
And got a nice pretty green LED.
Just for the record (same error message) and because I also spent some time fiddling with my AVR ISP MKII:
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
It did work OK for me only after adjusting the timing using the -B parameter! Looks like even a current mini PC is just too fast.
Avrdude now works for me reliably under straight Debian 7. Also, it works under Windows 8 with WinAVR driver installed, then VirtualBox VM running a Debian 7 non-UI installation, after passing through the AVRISP to the VM in VirtualBox.
avrdude -c avrispmkII -P usb -p t13 -B 10 -v
...

Resources