Support for Adafruit 16 channel pwm board

I would like to use the Adafruit 16 channel pwm board on the Rock Pi 4, but the device tree overlay is not implemented in the kernel. I tried to compile the version from the Raspberry, but that didn’t work. Sadly I’m not familiar with the device tree compilation. Could someone help me to get this to work?

Hi,

I think you can follow this one:

https://github.com/radxa/kernel/blob/release-4.4-rockpi4/arch/arm64/boot/dts/rockchip/overlays/at24c02-overlay.dts

It should be something like below:

/dts-v1/;
/plugin/;

/ {
	model = "ROCK PI 4B";
	compatible = "rockchip,rockpi","rockchip,rk3399";

	fragment@0 {
		target = <&i2c2>; /* Assume you connect the device to I2C2 */

		#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			pca: pca@40 {
				compatible = "nxp,pca9685";
				#pwm-cells = <2>;
				reg = <0x40>;
				status = "okay";
			};
	};
};

You may also need to enable the pca9685 driver in kernel config.

Thanks, I didn’t notice this dts file because of the different name. The file was already in my boot directory, so I simply uncommented the following line in hw_intfc.conf:

intfc:dtoverlay=at24c02

But after a reboot there is still no device on address 0x40. I’ve also compiled a new kernel with the PWM_PCA9685 config option, but also no device appears on address 0x40. But when I connect the board there appears a device on address 0x50 with i2cdetect -y 2:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

I’ve already tried to control the servos using the 0x50 address, but that didn’t work. Any ideas what could be the problem?

The PCA9685 is very flexible with regard to its addresses and could well have the address 0x50, but the address must not change automatically. lol
As far as I know the addresses from 0x50 to 0x57 are used by all FRAM and EEPROM ICs.

I’ve already tried the board on a Raspberry Pi 3 and there it appeared on address 0x40. So I think this is just an EEPROM from the board. Any ideas why the PCA9685 chip is not recognized?

Excuse me, that was my fault! I read over what you did. You have unlocked exactly one I2C EEPROM available on the Rock Pi.

# Set "on" to enable the optional hardware interfaces while set "off" to disable.

intfc:pwm0=off
intfc:pwm1=off
intfc:uart2=off
intfc:uart4=off
intfc:spi1=off
intfc:spi2=off
intfc:i2c2=off
intfc:i2c6=off
intfc:i2c7=on

# Devicetree Overlay Enable, uncomment to enable .dtbo under /boot/overlays/.

# EEPROM on I2C2
#intfc:dtoverlay=at24c02

I did not touch the EEPROM for my test, but changed the off in the line with “intfc:i2c7=off” to an on.

I’ve just tested that. I set intfc:i2c7 to on and commented out the line intfc:dtoverlay=at24c02 again and rebooted. But I can still only see the 0x50 address on i2c bus 2. Any other ideas?

Edit: Sorry, I didn’t realise that this simply activates i2c bus 7. I can see the address 0x40 on bus 7 now. I will now test if I can get some servos to run.

@SunWukong Sadly the code I used on the Raspberry does not work on the Rock Pi 4 because it relies on the wiringpi library that is not compatible with this board. Are there any examples how to control pca9685 boards using the mraa library? I didn’t find anything so far.

The UP board is definitely not a Raspberry Pi Clone and seems to work with the Adafruit HAT. And here they also work with the libmraa.

If you are using Ubuntu , you’ll need to install the MRAA library.

https://wiki.up-community.org/Adafruit#Using_Adafruit_16-Channel_PWM_.2F_Servo_HAT_on_UP

1 Like

I’ve now installed libmraa as described here and it works with the Python test program. But I need to control the board from a Java application. There should be a package libmraa-java, but that package isn’t found in the Radxa repository. How can I install the java package?

1 Like

The rockpi4-dtbo package should have jave support already. Just check the libmraa java examples.

https://github.com/intel-iot-devkit/mraa/tree/master/examples/java

I’ve installed both rockpi4-dtbo and libmraa-rockpi4, but there is no libmraajava.so:

find /usr/ -name “mraa
/usr/local/include/mraa.hpp
/usr/local/include/mraa
/usr/local/include/mraa.h
/usr/local/bin/mraa-gpio
/usr/local/bin/mraa-uart
/usr/local/bin/mraa-i2c
/usr/local/lib/libmraa.so
/usr/local/lib/python2.7/dist-packages/_mraa.so
/usr/local/lib/python2.7/dist-packages/mraa.py
/usr/local/lib/libmraa.so.2.0.0
/usr/local/lib/pkgconfig/mraa.pc
/usr/local/lib/libmraa.so.2
/usr/local/share/mraa
/usr/local/share/mraa/examples/c/hellomraa.c

For the moment I’ve compiled the library myself. But to write guides it would be much simpler if I could just provide an apt-get line to be executed. Do I miss a package? Or can I simply add the official mraa repository to install the java package?