WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: building a IQaudIO rotary encoder control  (Read 7200 times)

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
building a IQaudIO rotary encoder control
« on: October 01, 2015, 01:28:28 PM »
Hi alidaf.

Let us continue the discussion of building a IQaudIO rotary control tcz package here.


The recipe can be found here http://tinycorelinux.net/corebook.pdf but in simple terms you make a "<build directory>" and in here you copy the subdirectories that contain the structure of your newly build rotary encoder.

Then you need to pack it all into a tcz like this:
From the parent directory do:
mksquashfs <build directory> IQaudIO-rotary-encoder.tcz

and make a md5 checksum file
md5sum IQaudIO-rotary-encoder.tcz > IQaudIO-rotary-encoder.tcz.md5.txt


In order to load the package after each reboot do this:
1. Copy the  IQaudIO-rotary-encoder.tcz and IQaudIO-rotary-encoder.tcz.md5.txt to /mnt/mmcblk0p2/tce/optional
2. add IQaudIO-rotary-encoder.tcz to the file /mnt/mmcblk0p2/tce/onboot.lst


Please ask if you have problems.

Steen

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: building a IQaudIO rotary encoder control
« Reply #1 on: October 01, 2015, 01:35:59 PM »
One notice. Make sure it is built for armv6 architecture to make it usable on both armv and armv7 (RPi2) boards and strip binaries to reduce size.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: building a IQaudIO rotary encoder control
« Reply #2 on: October 01, 2015, 02:53:17 PM »
I've created a tcz file but reading through various sources it seems that I should be setting compiler flags, creating a configure and make file. I've done none of that. I just compiled and linked it with gcc and created the package with mksquashfs.

One notice. Make sure it is built for armv6 architecture to make it usable on both armv and armv7 (RPi2) boards and strip binaries to reduce size.


How do I do this? With this command...?

gcc -march=armv6 -mtune=arm6 -O2 -pipe rotencvol-2.3.c -o rotencvol -lwiringPi -lasound -lm

How do I strip binaries? It looks like I need to use make --install-strip but I have no make file so how do I create one?

Thanks.

Today I added volume shaping control to compensate for or accentuate the logarithmic response of alsa. I'm keen to finish this last step so I can start working on lirc and push button (mute and on/off) support.

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: building a IQaudIO rotary encoder control
« Reply #3 on: October 01, 2015, 03:13:31 PM »
I've created a tcz file but reading through various sources it seems that I should be setting compiler flags, creating a configure and make file. I've done none of that. I just compiled and linked it with gcc and created the package with mksquashfs.

One notice. Make sure it is built for armv6 architecture to make it usable on both armv and armv7 (RPi2) boards and strip binaries to reduce size.


How do I do this? With this command...?

gcc -march=armv6 -mtune=arm6 -O2 -pipe rotencvol-2.3.c -o rotencvol -lwiringPi -lasound -lm

How do I strip binaries? It looks like I need to use make --install-strip but I have no make file so how do I create one?

Thanks.

Today I added volume shaping control to compensate for or accentuate the logarithmic response of alsa. I'm keen to finish this last step so I can start working on lirc and push button (mute and on/off) support.

Hi, good to see that you were able to make your tcz.
The interesting part is to know if it is working in piCorePlayer?

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: building a IQaudIO rotary encoder control
« Reply #4 on: October 01, 2015, 03:22:21 PM »

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: building a IQaudIO rotary encoder control
« Reply #5 on: October 01, 2015, 03:51:58 PM »
It works with picoreplayer either with or without the IQaudioDAC. With it, a small workaround is needed as both the Pi card and IQaudioDAC cards are loaded as default.

PiCorePlayer is why I decided to take it on. It's my first C project but if you are interested in looking at the code it is at https://github.com/alidaf/raspberryPi. There is a readme with details on what it does. The internal mapping of the GPIO numbers to the wiringPi numbers is a bit lazy but I will work on it to make it more efficient once I can get the package sorted and streamline a process to get it into the repository.

Thanks. I've had enough for today but back on it tomorrow.

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: building a IQaudIO rotary encoder control
« Reply #6 on: October 02, 2015, 03:46:01 AM »
Regarding the strip command, I think it is something like this.
https://github.com/puppetlabs/Razor-Microkernel/wiki/Building-your-own-TCL-Extension

And maybe simpler presented here.
http://willhaley.com/willhaley/blog/creating-the-encfs-extension-for-tinycore-linux/

Regards
Steen

Thanks.

Unfortunately both of those links, as well as every other reference I have found only deal with existing source code that already have configure files. The Tiny Core wiki still refers to compiletc, which is frustrating. I don't understand what the process is actually doing and why, e.g. export directives, the configure file, make etc. As far as I can tell, the reason for all of these steps is to target specific platforms so the export directives and configure and make contain information that is platform specific. Since I am specifically targeting the Pi, then as far as I can tell, a straightforward compile with gcc should be enough but everything I've found suggests otherwise.

I don't mind providing the package directly but it kind of defeats the purpose of making this easy for people and having a procedure for updates to be easily absorbed into either the Tiny Core or PiCorePlayer repo. I'll keep trying though and thanks for trying to help.

Offline jgrulich

  • Sr. Member
  • ****
  • Posts: 341
    • GRULICH DESIGN - R&D Lab.
Re: building a IQaudIO rotary encoder control
« Reply #7 on: October 03, 2015, 05:52:35 AM »
Hence I've the encoder input at RaspiDAC (raspidac3 overlay) audio card, I'd like to use it as well. It's the last point to be solved and is still not working. Together with the lirc (http://grulich.eu/files/lirc-0.9.0-TC_6.1.tar.gz) which is working at all Raspi versions it will be than nice multimedia device.

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: building a IQaudIO rotary encoder control
« Reply #8 on: October 03, 2015, 06:41:18 AM »
I've posted the package to my github site but I've no idea how to get it to work. If anyone can give it a go then please do and tell me what to do.  https://github.com/alidaf/raspberryPi.git

I've copied it to /mnt/mmcblk0p2/tce/optional/ and edited onboot.lst but presumably I have to create a start-up script as well.

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: building a IQaudIO rotary encoder control
« Reply #9 on: October 03, 2015, 07:58:15 AM »
Actually, just hold off for a bit. I've just tested it on another Pi that I have. ALSA gives the minimum volume as a large negative number that breaks the volume calculation.

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: building a IQaudIO rotary encoder control
« Reply #10 on: October 03, 2015, 04:14:17 PM »
It's working again but if a soft min and/or max is set then the initial volume is relative to the soft values and not the hard values. The executable is in github (https://github.com/alidaf/raspberryPi.git), which can be run from the command line if anyone wants to use it until I can get the packaging sorted. Run sudo ./rotencvol -? to get a list of all of the command line options.

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: building a IQaudIO rotary encoder control
« Reply #11 on: October 05, 2015, 12:23:38 PM »
Hi peeps.

My rotary encoder package appears to be working albeit with limited testing. At the moment it has to be installed by hand until I can get to grips with the package management requirements to get it into the repo. Download the tcz package with the following command.

wget https://github.com/alidaf/raspberryP...encvol-2.7.tcz

and type the following command in a terminal:

cp rotencvol-2.7.tcz /mnt/mmcblk0p2/tce/optional/

This copies the package to the optional packages area.

Now edit /mnt/mmcblk0p2/tce/onboot.lst and add rotencvol-2.7.tcz at the bottom to make it persistent after a reboot.
I use nano so the command would be:

sudo nano /mnt/mmcblk0p2/tce/onboot.lst

Add the line, then press ctrl-x, press y and then return to save the file.

Now load the package:

tce-load -i /mnt/mmcblk0p2/tce/optional/rotencvol-2.7

To run, until I can sort out a startup script run:

sudo /bin/rotencvol -?

This will give you all of the command line options. -q will print the default settings. Try -m to print out the GPIO map.

Pay special attention to the card name and control name switches. You will need to run alsamixer to get these. If you are just running the Pi with no other hardware then the default names should be fine. If you are using anything else then you will need to determine these. For the IQaudioDAC, the control name is 'Digital' (without the apostrophes). For the IQaudioDAC a workaround is needed (givene below) to remove the Pi's sound card otherwise both are loaded as default and it doesn't work.

Also check which GPIO pins you are using and set these with the -a and -b switches if they are not the defaults, which are 23 and 24.

Try running with output on by using the -p switch and messing around with some of the other parameters such as -f <num>. Some switches that produce informational output will terminate the program. The switch -f num shapes the volume profile to overcome the logarithmic output of alsa. Try a value of around 0.1 - 0.5 to get a more linear response. The default value of one will increment volume up from 0 very slowly at first and then in increasingly large steps. Values > 1 will exacerbate this but values < 1 will make the volume increase more quickly at the bottom end. Soft limits can also be set if you have a noisy card and want to ignore some of the lower volumes where there is hiss or deafeningly loud high volumes. The starting volume can also be set but be careful that it is within the soft limits. The default starting volume is 0 since I use headphones but a starting volume of 100 (%) may be better for DACs but the choice is there.

ctrl-c will stop the program if it is running interactively.

Once you are happy run the command with the '&' character at the end of the line. This will force it to the background and free up your prompt. E.g.

sudo /bin/rotencvol -i 20 -p -a 2 -b 3 &
Note the file in /bin is rotencvol, not rotencvol-2.7!

Return to get your prompt back.

You should see the process running with the following command:

ps aux | grep rotencvol

You will get a list of command that are running that contain the word ‘rotencvol’. One of them should be the command you just typed with the process id at the start of the line. To stop the program running you have to kill it with the command:

sudo kill <process id>

Workaround for IQaudioDAC and possibly for other DACs and add-ons.

mount mmcblk0p1 with the command:

sudo mount mmcblk0p1

then edit the file /mnt/mmcblk0p1/config.txt and remove audio=on:

sudo nano /mnt/mmcblk0p1/config.txt

Find the line with 'audio=on'.
Get the cursor onto the line and press ctrl-k.

This will delete the line.
Now press ctrl-u twice.
This will create two copies of the original line.

Put a # in front of one of them to preserve it in case you need to come back and reverse the procedure.
On the other line, delete the 'options=on'.

Press ctrl-x and press y and then return to save the file.

Enjoy.

Offline squeezypeas

  • Newbie
  • *
  • Posts: 22
Re: building a IQaudIO rotary encoder control
« Reply #12 on: October 05, 2015, 12:38:32 PM »
For a more linear response use -f between 0.05 and 0.1, not 0.1 and 0.5!

Offline kingswindsor

  • Newbie
  • *
  • Posts: 1
Re: building a IQaudIO rotary encoder control
« Reply #13 on: April 15, 2016, 06:33:47 PM »
Hello all. I am trying to add a rotary encoder to an RPi 2+ with an IQaudio DAC+ running picoreplayer 2.04 but I can't find any recent posts and I can't make the Squeezypeas guide work for me.  Is anyone aware of any newer guidance I could follow please? Thanks