Creating add-on library for arduino to use Adafruit 16-Channel 12-bit PWM/Servo Driver

5 views (last 30 days)
Hi! I would like to use the Adafruit 16-Channel 12-bit PWM/Servo Driver shield with arduino through Matlab, so I've been trying to add a custom library and I've managed to make it 'work' but not in the expected way, this is the code I'm running with 4 servo motors attached to the shield (it's from the library built-in examples for arduino, it's meant to move all the servos):
a = arduino('COM3', 'Uno', 'Libraries', 'Adafruit/PWMServoDriver')
pwm_shield = addon(a, 'Adafruit/PWMServoDriver')
for i = 0:8:4096
for servo = 1:4
pwm_shield.setPWM(servo,0,i+mod((4096/16)*servo,4096))
end
end
The I2C default address is 0x40. But only the second servo moves... I think it has something to do with the I2C address, because if I change the address to 0x7F (the last) all the servos start to move crazily as soon as i create the shield object
To create the addon library I started from the motorshieldv2 code (the 2 shields are similar, they use the same chip) and tried to modify it according to the pwm driver arduino library, I uploaded here the .m and .h files.
Any help would be appreciated since I spent a lot of time trying to fix the problem but now I'm stuck
  1 Comment
tinh ngo vu
tinh ngo vu on 21 Nov 2018
Hi
help me !
a = arduino('COM5', 'Uno', 'Libraries', 'Adafruit/PWMServoDriver')
Expected libraries to match one of these values:
'Adafruit/MotorShieldV2', 'I2C', 'JRodrigoTech/HCSR04', 'RotaryEncoder', 'SPI',
'Servo', 'ShiftRegister'
The input, 'Adafruit/PWMServoDriver', did not match any of the valid values.
Thanks you!

Sign in to comment.

Answers (1)

Lars Heising
Lars Heising on 12 Feb 2020
Hi,
in addition to the former answerer, you need to understand how the PWM Controller on this Shield works.
The PWM Signal starts on every PIN at the same time. Only the 'zero'-flank is in order to the setup "angle" time.
It is normal that then every motor will start after creating the shield object.
The Shield works very well with the 'Adafruit/MotorShieldV2', 'Servo' and 'I2C', so there is no need to write an extra lib.
Regards.

Communities

More Answers in the  Power Electronics Control

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!