記事一覧

M5Stack X 16ch Servo Driver PCA9685

M5Stack X 16ch Servo Driver PCA9685



Hello everyone! I’m RoboTakao.

Previously I posted an article about using PCA 9685 16 channel PWM servo driver with Arduino.


This time I tried using PCA 9685 with M5Stack.

m5stack_pca9685_01.jpg

pca9685_03.jpg

Connection

m5stack_pca9685_03.png

PCA9685
+5V  Battery +
OE    N/A
SCL   M5Stack SCL (22pin)
SDA   M5Stack SDA (21pin)
GND   M5Stack GND and Battery -
VCC   M5Stack 3.3V (or 5V)


Use with M5Stack
This time I will try using Arduino library of comparable product of Akizuki.

Instruction manual
PCA9685 Datasheet
Arduino library

Download the library and load it with Arduino IDE.
Sketch → Include Library → Install ZIP format libraries

pca9685_04.png

You can now open a sample sketch from the example sketch.

Description of the sketch
I changed a bit from the sample.
First of all, the sample uses two PCA9685, but since this time it is one, the second part is deleted.
In the sample, the minimum pulse width 150 and the maximum pulse width 600 are set at a 60 Hz cycle as a general servo setting, but as I wrote in the previous post, it is beyond the pulse width range of Micro 2BB MG of GWS used this time I changed it because I understood it when I saw the oscilloscope. (We do not know the unit of minimum and maximum pulse width well)

PWM frequency 60 → 50
Min pulse width 150
Max pulse width 600 → 500

I changed the angle slightly.

This sample sketch rotates 180 degrees from zero degrees in increments of 10 degrees and returns to 180 degrees when it becomes 0.

Include M5Stack.h when using with M5Stack

It's super easy.

Operation check

I was able to confirm that the servo moves as expected.




Sketch


#include
#include
#include

PCA9685 pwm = PCA9685(0x40);

#define SERVOMIN 150 //Min pulse width (GWS Micro2BBMG)
#define SERVOMAX 500 //Max pulse width (GWS Micro2BBMG)

void setup() {
pwm.begin();
pwm.setPWMFreq(50);
}

int n=0;

void loop() {
for(int i=0; i<16; i++)
servo_write(i,n);
n=n+10;
if(n>=180)n=0;
delay(500);
}

void servo_write(int ch, int ang){
ang = map(ang, 0, 180, SERVOMIN, SERVOMAX);
pwm.setPWM(ch, 0, ang);
}


M5Stack related posts
1) M5Stack Arduino IDE initial setting (macOS)
2) M5Stack I tried Arduino IDE sample sketches
3) M5Stack I treid Avatar(Arduino IDE)
4) M5Stack LED Blink
5) M5Stack Servo operating

スポンサードリンク

コメント

コメントの投稿

非公開コメント

プロフィール

RoboTakao

Author:RoboTakao
みなさんご訪問ありがとうございます。ロボット作りたいけどお小遣いそんなにないし、簡単でローコストでロボットを作るための私のプロジェクトを紹介します。

ウェブサイトもありますのでそちらもよろしくお願いします。
http://robotakao.jp/

スポンサーリンク