(v99) hardware centric config

Hi. Just registered. Today I started to play with DietPi. Wonderfull stuff sofar!

I’m wondering if it would be possible to add the hardware related things (enable i2c, spi, …). Also the option to load the driver(s) at boot? Like in the official Wheezy and Jessie Raspbian “distro”? Since the official Jessie image has outgrown an 4 Gb SDcard, I was looking for something smaller. DietPi seems the way to go!

I run the RPi headless, with just an i2c 4x20 LCD and a barcode scanner. I changed a few things in config.txt already (added dtparam=i2c_arm=on) and in cmdline.txt (I want ttyAMA0 as console). But this is not enough yet to get i2c up and running. I do not get the /dev/i2c/ devices.

Another question, will my mods to config.txt and cmdline.txt be overridden during an kernel upgrade?
Egbert Jan, NL

Hi Egbert,

Thanks for the feedback, appreciate it.

I’ll need to look into your query indepth over the next few days and get back to you. But yes, i dont see why we cant add the options you mentioned into DietPi-Config.
There might be additional software that needs to be installed, or more configurations we dont know about. I’ll know more when I look into it.

Another question, will my mods to config.txt and cmdline.txt be overridden during an kernel upgrade?

Not by DietPi.
DietPi treats your config.txt and cmdline.txt file as “yours”. We may add additional options to your config.txt file during updates, however, DietPi will never remove or modify your config.txt settings, unless you set them in dietpi-config.
DietPi-Software will apply some settings to config.txt when you install software. EG: You install Kodi, DietPi will automatically increase GPU memory size in relation to your total memory and what Kodi requires.

In terms of Kernel updates (eg: rpi-update, which is out of our control), i’am yet to see this add/modify config.txt items. Everything should be as you have left it.

Thanks for this swift reply. Since you have already the dietpi-software script, adding a HW group might be added to install rpi-gpio, i2c-tools etc. I like the approach very much; kind off modular, easy to extend.

Things are needed in config.txt for sure but might be added via dietpi-config. That is how raspi-config works (I guess). I bet you looked carefully how raspi-config was put together when you started work on dietpi-config :wink:

I’ll try to figure out wat is needed to get my application (written in python) up and running. I need i2c, smbus, gpio and from the distro: build-essential, python, python-dev, python-evdev. probably more. Don’t hold your breath… I’m busy with other things too. If you like, have a look at my wiki: http://wiki.vandenbussche.nl/index.php?title=Price_Scanner.


Replying to myself… A few simple steps to use i2c and python.

To be able to use i2c you need “dtparam=i2c_arm=on” in config.txt and the module “i2c_dev” in /etc/modules. If you want to run the i2c bus at 400 KHz, change the line in config.txt into: “dtparam=i2c_arm=on,i2c_arm_baudrate=400000”. After installing “i2c-tools”, use “i2cdetect -y 1” to see the i2c bus. If thre are any devices on the bus, they will show up with their hex address.

Running pytrhon is just a matter of installing it with apt-get. Depending on your needs, one or more python packages must be installed too. “python-dev” and “python-smbus” come to mind. If you need to add more exotic python libraries, you need “pip” the python installer. Install with “apt-get install python-pip”. Do install “build-essential” too; pip often needs to compile a package. I needed “evdev” and “subprocess32”. Use “pip install evdev subrocess32” to install these.

Dan, this should give you the info howto activate i2c in the DeviceTree, do the load of the related module in “dietpi-config” and to add the python environment to “dietpi-software”. Don’t bother to install all kind of python libraries; python programmers will know what to do.

HtH, best regards,
Egbert Jan

Hi Egbert,

Excellent, thank you for the information, this will save me many hours of research! Really appreciate it.

I’ve also created a Git ticket for this request: https://github.com/Fourdee/DietPi/issues/98. I’ll implement it when i can. Also, as i dont own any i2c/spi devices for my RPi, i may need your help to test these features when they are completed. I’ll keep you updated.

Done. Available in v99: https://github.com/Fourdee/DietPi/issues/98#issuecomment-151568109

Good work. I just upgrded to V99. I still had i2c enabled (the manual way) and I did see it enabled at 400 KHz. It was visible under 1 Display Options. Not an obvious place.I selected it to toggle on/off but dietpi-config throws an error:

"/DietPi/dietpi/dietpi-config: line 226: / 1000 : syntax error: operand expected (error token is "/ 1000 “)”

I cannot start dietpi-config anymore; it keeps throwingthis error. After cleaning up config.txt, I can start dietpi-config again but choosing 1 Display options gives me the error again.
I tried a few things to resolve the issue but to no avail.
Egbert jan

Hmm, seems I had garbage in config.txt. Got it under control again.

Perhaps is mis understood the way dietpi.txt and config.txt play together. I’ll do a fresh install to check. Maybe the FB messages also disappear…

[ 28.018385] raspberrypi-firmware soc:firmware: Request 0x00048003 returned status 0x80000001
[ 28.018408] bcm2708_fb soc:fb: Failed to allocate GPU framebuffer (-22)
[ 28.018417] bcm2708_fb_pan_display(0,0) returns=-22
[ 28.018515] raspberrypi-firmware soc:firmware: Request 0x0004800b returned status 0x80000001
[ 28.018531] bcm2708_fb soc:fb: Failed to set palette (-22,0)
[ 28.018624] raspberrypi-firmware soc:firmware: Request 0x0004800b returned status 0x80000001
[ 28.018639] bcm2708_fb soc:fb: Failed to set palette (-22,0)

Egbert Jan

Hi Egbert,

Yep, could be due to your manual config.txt settings. We do patch existing config.txt, however, your manual entries may have thrown this off.

local rpi_i2cbaudrate_hz=“$(( $(cat /DietPi/config.txt | grep ‘i2c_arm_baudrate=’ | sed ‘s/i2c_arm_baudrate=//g’) / 1000 )) kHz”

This is causing the error. Make sure your config.txt has the following entry:


The GPU allocation issue, have you tried increasing the GPU memory split?

Hi Dan. No time found to do a reinstall. Thanks for the correction of the syntax in config.txt.
Wrt GPU: I do not want GPU… I want to be able to choose for just a console on serial (ttyAMA0) and runlevel 3. When I find a decently priced small HDMI screen, I might go for console on HDMI and maybe go to runlevel 5.

OK. After a reinstall (still v94) and automatic update to v99 all seems ok. No output to ttyAMA0. I had to login via ssh. Should be easy to get ttyAMA0 spit out the same output as ttyX on HDMI. The i2c bus is satisfied; i2cdetect gives the expected output. Selecting a few packages brings in a lot of other packages. All dependencies I think. I think I saw a lot of X. Don’t want that… As said I would like to have a headless device with console output and without X.
Still good to see al works as advertized. TNX, Egbert Jan

Hi Egbert,

Try adding the following to /boot/cmdline.txt:


If your running Wheezy, edit /etc/inittab and uncomment the RPI serial line at the bottom.

I think I saw a lot of X.

Shouldnt do, this is the packages that get installed with i2c: https://github.com/Fourdee/DietPi/blob/master/dietpi/func/dietpi-rpi_i2c_control#L36. This gives me

file i2c-tools libmagic1 libpython-stdlib libpython2.7-minimal
libpython2.7-stdlib libsqlite3-0 mime-support python python-minimal
python-smbus python2.7 python2.7-minimal

Can you post the links for the i2c device you have, and, the serial line connector? I really need to get this hardware so I can test and provide a better implementation.

Sorry for not replying earlier. The BBnotifier seems not to work. I use many 12c devices. It is is just a handy bus. Nearly all the time I use at least a 2x16 or 4x20 LCD display. The interface hardware is a PCF8574. For the console I use a USB <-> serial cable bought from DX.COM. Any USB-Serial cable will do, I guess. The cable I use has 4 wires: in/out, gnd and 5V. Since I feed the RPi via the mini-USB port, I leave the +5 from the USB cable unconnected. The active part is in the USB end of the cable and is powered by the PC/laptop. On the PC i use PuTTY as terminal program.
Best regards, Egbert Jan