DEV: [PLUGIN] MPD_OLED for x86 based systems

modified service , mdp_oled starts.
Needed to add sudo -u volumio to avoid that cava won’t work.

#!/bin/bash

service="mpd_oled"
launch_test="mpd_oled_launch_test"

tmp_file_name="/tmp/$service.service"
tmp_file_contents="[Unit]
Description=MPD OLED Display

[Service]
ExecStartPre=/usr/local/bin/$launch_test
ExecStart=sudo -u volumio /usr/local/bin/$service -b 32 -g 1 -P  s -L n -o SSD1306,128X64,I2C,bus_number=$(dmesg | grep -iE "ch341_i2c_probe: created i2c device" | sed 's/^.*[/]//' | sed 's/.*-//') -f 50

[Install]
WantedBy=multi-user.target
"
echo "$tmp_file_contents" > $tmp_file_name

systemctl is-active --quiet $service && systemctl stop $service
cp -n $tmp_file_name /etc/systemd/system
systemctl daemon-reload
systemctl enable $service

Now service is up and running, however no response if I press play and stop.

volumio@volumiox86:~$ systemctl status mpd_oled
● mpd_oled.service - MPD OLED Display
   Loaded: loaded (/etc/systemd/system/mpd_oled.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2022-12-02 13:40:21 CET; 3min 37s ago
  Process: 599 ExecStartPre=/usr/local/bin/mpd_oled_launch_test (code=exited, status=0/SUCCESS)
 Main PID: 607 (mpd_oled)
   Memory: 1.9M
   CGroup: /system.slice/mpd_oled.service
           └─607 /usr/local/bin/mpd_oled -b 32 -g 1 -P s -L n -o SSD1306,128X64,I2C,bus_number=5 -f 50

I can’t execute edit as user volumio as this generates a loop with root login and kills screen respinse to ssh.

I am done for now, before I start programming with a hammer…

Threw hammer away and gave it one final shot and its working…

Updated:

Added a global var prev_number, to avoid errors when the file is being written by the GPIO polling;

void draw_spect_display(U8G2 &u8g2, const display_info &disp_info)
	int number; 
	FILE *file  = fopen("/home/volumio/scripts/status.txt", "r"); // read only
	if (file == NULL ) 
            {   
              printf("Error! Could not open file\n"); 
              number = prev_number;
    } else {
		fscanf(file, "%d", & number );
		prev_number = number;
        fclose(file);
	}
		
	if (  number == 1 ) {
       // do stuff
    } else {
             // do stuff
    }

That’s more like it! How are you reading the GPIO?! :thinking::thinking:

#!/bin/bash
# select pin GND - D0
GPIO=0
# Init Status
STATUS=0;
# Set the GPIO as Input
if [ ! -d /sys/class/gpio/gpio${GPIO} ]; then
  echo "${GPIO}" > /sys/class/gpio/export
fi
echo "in" > /sys/class/gpio/gpio"${GPIO}"/direction

#Read the current status
STATUS=$(cat /sys/class/gpio/gpio"${GPIO}"/value)

Oh! Is this on your Wyse box or a pi?

On the Wyse box off coarse :slight_smile:

but how does the OS know the GPIO is coming though USB adapter? Am I missing something?

OS doesn’t need to know, the driver needs to know.
For the OS there are just GPIO loaded in /sys/class/gpio/gpio

image

How does the OS know to load the CH341 driver for GPIO communication?

Please see:DEV: [PLUGIN] MPD_OLED for x86 based systems - #41 by Wheaten

git clone https://github.com/gschorcht/i2c-ch341-usb.git
cd i2c-ch341-usb
make
sudo make install

You have installed the driver, and Volumio (OS) recognize it by it’s id.

1 Like

Ah, a bit like in Windows then. You install the correct driver and that exposes GPIO to the OS! I’ll shall be doing this soon! Thanks :sunglasses: I didn’t know that that the Ch341 driver also support GPIO as well as I2C!

Me neither, till I stumble upon this:

So now I have a hp-elitedesk-g1-800-mini-intel-core-i5 Running volumio, with i2c and GPIO, and a solid case for 110 Euro.
And a Dell Wyse 3040 Running volumio, with i2c and GPIO, and a solid case for 60 Euro.
Pretty sure it beats the rPi :slight_smile:

I see you found the driver by accident. Good news though! I think you must be the first person in the world to have mpd_oled running on x86 maybe? :blush: We can’t keep hanging around waiting for pis to come back in stock - it’s been a good couple of years now. :open_mouth: Dell Wyse 3040 for the win!

1 Like

And the first that can change the lay-out with a switch :partying_face:

2 Likes

Xmas has come early for you :rofl:

Added, at least I think I did, a pulll request for MPD_OLED on a x86

Hi @Wheaten

Thank you for taking the time to put everything into a document. There is no pull request, but I am not currently accepting changes to the repository.

Some notes on the instructions:

  • The instructions include commands and images that refer to mpd_oled options that are specific to your repository, and this makes the instructions incompatible with the main repository
  • The instructions include commands (in “Configure a copy of the playing audio”) to install the armhf binary package (!). If you have installed mpd_oled from source then the mpd_oled_volumio_mpd_conf_install script should also be installed, and there is no need to install any binary package.
  • I didn’t understand “Get headers to perform make (will break ATO)”. Does this refer to Volumio updates (ATO = OTA?). If this is the case, I think it is very useful for users to also have instructions to restore the system to an updateable state. (Even better is to find a solution that does not break updates, for example I would like to replace mpd_oled_volumio_mpd_conf_install with a simple audio copy plugin)
  • Maybe, Volumio would be open to automatically enabling access to I2C/SPI/GPIO on x86, rather than users having to run commands like sudo addgroup volumio i2c.
  • Maybe Volumio would be open to including modules for common I2C/SPI/GPIO adapters.

Adrian.

Hi @Adrii

Thanks for your reply.
The instruction are just in Alpha state, As I still need to sort out a couple of things.

  • Maybe I will make this a stand alone repo, only for x86. Let’s see if people catch up before I spend a lot of time on this. The added option -L is only a change in main.ccp and display_info.h which has no impact on the main branch as it’s not mandatory.
  • This I need to sort out what armfh is adding that it works “mpd_oled_volumio_install_latest.sh”
  • Already talked with @gkkpch on this matter. The headers have been left out to reduce disk image size. Since it will touch the core image OTA will be blocked for the same. The kernel headers are needed to perform the make. Haven’t found a way yet to work around this
  • I’ve asked @gkkpch to include the driver in the next built. Not sure if we should add a latter of modules as we’re talking over a low budget thing. This one is working with acceptable FPS and drivers for linux.

I’ll be using your guide Tuesday! I’ll feedback any issues I encounter! Thank you for writing it :sunglasses:

Hi @Wheaten

I looked at a udev rule. Plugging in the USB adapter I can see it is appearing as /dev/i2c-8, then

udevadm info /dev/i2c-8

Gives

DEVPATH=/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1/1-1.1:1.0/i2c-8/i2c-dev/i2c-8

Chopping the end off this and adding * gives the rule

SUBSYSTEM=="i2c-dev", DEVPATH=="/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1/1-1.1:1.0/*", SYMLINK+="i2c-99"

Unplug the adapter, add the rule, reload the rules and plug in the device, and it can be accessed through /dev/i2c-99

sudo udevadm control --reload
ls /dev/i2c*
/dev/i2c-0  /dev/i2c-2  /dev/i2c-4  /dev/i2c-6  /dev/i2c-8
/dev/i2c-1  /dev/i2c-3  /dev/i2c-5  /dev/i2c-7  /dev/i2c-99

I guess this rule would work with any any USB adapter providing one I2C bus and plugged into the same port.

Adrian.