# AS5600 + drv8302 + SunnySky V2806 Shake

**URL:** https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523
**Category:** hardware support
**Tags:** bldc, as5600, arduino\_uno, drv8302
**Created:** [June 28, 2023, 5:37pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523 "2023-06-28T17:37:42Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![konoe-akitoshi](https://community.simplefoc.com/user_avatar/community.simplefoc.com/konoe-akitoshi/32/5111_2.png) [@konoe-akitoshi](https://community.simplefoc.com/u/konoe-akitoshi)
#### Post date: [June 28, 2023, 5:37pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/1 "2023-06-28T17:37:42Z")

</div>

First of all, I would like to express my gratitude to the individuals responsible for creating this fantastic library. I am a university student in Japan, so I apologize in advance for any shortcomings in my English.

The system I am using consists of an Arduino Uno, a DRV8302 motor driver, an AS5600 magnetic sensor, and a SunnySky V2806 motor. The code I am using is based on a sample code provided in the [documentation](https://docs.simplefoc.com/drv8302_example). The code I have implemented is nearly identical to the sample code.

```auto
/* ----- Pin setting -----
   PC4 - Analog 4 - Encoder SDA
   PC5 - Analog 5 - Encoder SCL
*/

#include <SimpleFOC.h>

// DRV8302 pins connections
// don't forget to connect the common ground pin
#define INH_A 5
#define INH_B 9
#define INH_C 11
#define INL_A 6
#define INL_B 10
#define INL_C 3
#define EN_GATE 8
#define M_PWM 6
#define M_OC 5
#define OC_ADJ 7

// motor instance
BLDCMotor motor = BLDCMotor(11);

// driver instance
BLDCDriver6PWM driver = BLDCDriver6PWM(INH_A, INL_A, INH_B, INL_B, INH_C, INL_C, EN_GATE);

MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

// commander interface
Commander command = Commander(Serial);
void onMotor(char *cmd) { command.motor(&motor, cmd); }

void setup()
{

  // configure i2C
  Wire.setClock(400000);
  // initialise magnetic sensor hardware
  sensor.init();

  // link the motor to the sensor
  motor.linkSensor(&sensor);

  // DRV8302 specific code
  // M_OC - enable over-current protection
  pinMode(M_OC, OUTPUT);
  digitalWrite(M_OC, LOW);
  // M_PWM - enable 6pwm mode (can be left open)
  pinMode(M_PWM, OUTPUT);
  digitalWrite(M_PWM, LOW);
  // OD_ADJ - set the maximum over-current limit possible
  // Better option would be to use voltage divisor to set exact value
  pinMode(OC_ADJ, OUTPUT);
  digitalWrite(OC_ADJ, HIGH);

  // configure driver
  driver.voltage_power_supply = 12;
  driver.init();
  motor.linkDriver(&driver);

  // choose FOC modulation
  motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

  // set control loop type to be used
  motor.controller = MotionControlType::torque;

  // controller configuration based on the control type
  motor.PID_velocity.P = 0.2;
  motor.PID_velocity.I = 20;

  // velocity low pass filtering time constant
  motor.LPF_velocity.Tf = 0.01;

  // angle loop controller
  motor.P_angle.P = 20;

  // angle loop velocity limit
  motor.velocity_limit = 50;
  // default voltage_power_supply
  motor.voltage_limit = 12;

  // use monitoring with serial for motor init
  // monitoring port
  Serial.begin(115200);
  // comment out if not needed
  motor.useMonitoring(Serial);

  // initialize motor
  motor.init();
  // align encoder and start FOC
  motor.initFOC();

  // set the initial target value
  motor.target = 2;

  // define the motor id
  command.add('M', onMotor, "motor");

  _delay(1000);
}

// velocity set point variable
float target_velocity = 5; // 2Rad/s ~ 20rpm

void loop(){
  // iterative setting FOC phase voltage
  motor.loopFOC();

  // iterative function setting the outer loop target
  // velocity, position or voltage
  // if target not set in parameter uses motor.target variable
  motor.move(target_velocity);

  // user communication
  command.run();
}

```

Based on the serial monitor output, it appears to be functioning correctly, as shown below. However, in reality, the FAULT LED lights up and the operation comes to a halt, as demonstrated in the video ([https://youtu.be/jb0efc9v35U](https://youtu.be/jb0efc9v35U)).

```auto
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CCW
MOT: PP check: fail - estimated pp: 78.77
MOT: Zero elec. angle: 0.67
MOT: No current sense.
MOT: Ready.

```

I also attempted to run the “magnetic\_sensor\_i2c\_example” code, which was mentioned in a previous question, but it didn’t seem to have any noticeable issues. I am unsure why this behavior is occurring.  
I would greatly appreciate your assistance in resolving this matter.

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [June 28, 2023, 6:22pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/2 "2023-06-28T18:22:28Z")

</div>

> [@konoe-akitoshi](#):
>
> express my gratitude to the individuals responsible for creating this fantastic library.

Akitoshi (Saeki San?),

Welcome to the SimpleFOC forum, we hope you find what you need.

> [@konoe-akitoshi](#):
>
> FAULT LED lights up and the operation comes to a halt

Could you please let me know which driver board are you using? I’m not sure which fault LED is lighting up. From the youtube video it appears one of the Chinese aliexpress boards, but the video is unclear and I don’t see which LED is that.

Thank you for using the library. I’m sure we will figure out what the problem is. Your English is excellent.

I would like to suggest you first try running an open loop and lower the voltage limit to about 2V. Please also specify/tell us about your power supply, BLDC motor parameters, etc. Most probably you over-current the board.

Cheers,  
Valentine

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [June 29, 2023, 3:34pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/3 "2023-06-29T15:34:57Z")

</div>

> [@konoe-akitoshi](#):
>
> `MOT: PP check: fail - estimated pp: 78.77`

This is definitely a problem. It means the sensor is not working correctly. Do you have I2C pull-ups on SDA and SCL lines?

Is the sensor powered and working correctly? You could try a sketch to just read the sensor first, to make sure it is working…

---

<div class="post-metadata">

### Author: ![konoe-akitoshi](https://community.simplefoc.com/user_avatar/community.simplefoc.com/konoe-akitoshi/32/5111_2.png) [@konoe-akitoshi](https://community.simplefoc.com/u/konoe-akitoshi)
#### Post date: [June 29, 2023, 3:56pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/4 "2023-06-29T15:56:04Z")

</div>

Hello @Valentine !  
My name is Aktioshi Saeki.  
In Japan, we use “san” for honorific titles, but it is nice to meet someone I know.

I apologize for the lack of necessary information.  
This is the board I am using.

> **[高出力モーター駆動モジュール,ブラシレスモーター,pmsmドライブ,st foc,ベクトル制御,アンプボード,DC 5.5-45v,15a,drv8302...](https://ja.aliexpress.com/item/4000126430773.html?spm=a2g0o.order_list.order_list_main.5.7ebb585aVvcwNN&gatewayAdapt=glo2jpn)**
>
> Smarter Shopping, Better Living! Aliexpress.com

I am also using a [SunnySky V2806 KV400](https://sunnyskyusa.com/products/sunnysky-v2806-motor).  
I will try open loop.  
Thanks. 🙇‍♂️

---

<div class="post-metadata">

### Author: ![konoe-akitoshi](https://community.simplefoc.com/user_avatar/community.simplefoc.com/konoe-akitoshi/32/5111_2.png) [@konoe-akitoshi](https://community.simplefoc.com/u/konoe-akitoshi)
#### Post date: [June 29, 2023, 4:05pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/5 "2023-06-29T16:05:16Z")

</div>

Hi @runger !  
Thanks for your advice.  
I have tested the hall sensor.  
The code is pasted at the bottom.

```auto
2.19	0.00
2.19	0.00
2.19	0.00
2.19	0.00
2.19	0.00
2.19	-1.11
2.19	1.04

```

When I let the motor go around it changes roughly 2.19-8.52.  
This seemed right to me.

```auto
#include <SimpleFOC.h>

// MagneticSensorI2C(uint8_t _chip_address, float _cpr, uint8_t _angle_register_msb)
// chip_address I2C chip address
// bit_resolution resolution of the sensor
// angle_register_msb angle read register msb
// bits_used_msb number of used bits in msb register
// 
// make sure to read the chip address and the chip angle register msb value from the datasheet
// also in most cases you will need external pull-ups on SDA and SCL lines!!!!!
//
// For AS5058B
// MagneticSensorI2C sensor = MagneticSensorI2C(0x40, 14, 0xFE, 8);

// Example of AS5600 configuration 
// MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

void setup() {
  // monitoring port
  Serial.begin(115200);

  // configure i2C
  Wire.setClock(400000);
  // initialise magnetic sensor hardware
  sensor.init();

  Serial.println("Sensor ready");
  _delay(1000);
}

void loop() {
  // iterative function updating the sensor internal variables
  // it is usually called in motor.loopFOC()
  // this function reads the sensor hardware and 
  // has to be called before getAngle nad getVelocity
  sensor.update();
  
  // display the angle and the angular velocity to the terminal
  Serial.print(sensor.getAngle());
  Serial.print("\t");
  Serial.println(sensor.getVelocity());
}

```

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [June 29, 2023, 4:47pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/6 "2023-06-29T16:47:49Z")

</div>

> [@konoe-akitoshi](#):
>
> I will try open loop.

Saeki San,

Sure, please try open loop, then let us know. For the open loop, make sure you run your motor at about 10 to 20% of your power supply voltage, else you will over-current and trip the board. Also, I see you set the current trip protection to the max, so this probably also contributes to the board and LED tripping.

Your motor has very low resistance and requires high current (20A) so make sure you don’t push too much current else you will burn the board, your board can supply only 15A. This is probably why the fault LED was lighting up. You either need a smaller motor, or a motor with higher resistance, or a more powerful board, or carefully adjust the current for SimpleFOC to stay under the board trip level.

Once you get the open loop running, we will investigate the sensor as @runger pointed out, once you are sure the sensor works, then you can combine the sensor and close the loop.

You need to take small steps and make sure at each step your code and components are working, else debugging a closed loop from scratch may be too difficult for you.

Please let me know if you need open loop sample code. I’m attaching it below. You need to modify the power supply voltage if it is different from 12V. Please edit and put your own. Let us know if any problems.

Cheers,  
Valentine

```auto
#include <SimpleFOC.h>

#define INH_A 5
#define INH_B 9
#define INH_C 11
#define INL_A 6
#define INL_B 10
#define INL_C 3
#define EN_GATE 8
#define M_PWM 6
#define M_OC 5
#define OC_ADJ 7

BLDCMotor motor = BLDCMotor(1);

BLDCDriver6PWM driver = BLDCDriver6PWM(INH_A, INL_A, INH_B, INL_B, INH_C, INL_C, EN_GATE);

float power_supply_voltage = 12;
float target_velocity = 2.0;
float target_voltage = 2.0;

void setup() {

  // DRV8302 specific code
  // M_OC - enable over-current protection
  pinMode(M_OC, OUTPUT);
  digitalWrite(M_OC, LOW);
  // M_PWM - enable 6pwm mode (can be left open)
  pinMode(M_PWM, OUTPUT);
  digitalWrite(M_PWM, LOW);
  // OD_ADJ - set the maximum over-current limit possible
  // Better option would be to use voltage divisor to set exact value
  pinMode(OC_ADJ, OUTPUT);
  digitalWrite(OC_ADJ, HIGH);

  driver.voltage_power_supply = power_supply_voltage ;
  driver.pwm_frequency = 15000;
  driver.init();
  motor.linkDriver(&driver);
  motor.voltage_limit = target_voltage; // [V]
  motor.velocity_limit = 100; // [rad/s]
  motor.controller = MotionControlType::velocity_openloop;
  motor.init();
  _delay(1000);

}

void loop() {
  motor.move(target_velocity); 
}

```

---

<div class="post-metadata">

### Author: ![konoe-akitoshi](https://community.simplefoc.com/user_avatar/community.simplefoc.com/konoe-akitoshi/32/5111_2.png) [@konoe-akitoshi](https://community.simplefoc.com/u/konoe-akitoshi)
#### Post date: [June 29, 2023, 5:40pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/7 "2023-06-29T17:40:43Z")

</div>

@Valentine  
Thank you for presenting the sample.  
When I ran the sample, the motor seemed to shake.  
I also changed the name of the motor to “BLDCMotor motor = BLDCMotor(14);”.

 ![image](https://community.simplefoc.com/uploads/default/original/2X/d/db35fd732a6c31d5ba563096397965023e930128.png)

```auto
float target_velocity = 4.0;
float target_voltage = 4.0;

```

Here’s what it looks like after the change.  
Why … 😢

[![](https://img.youtube.com/vi/ERz60cmdq4c/maxresdefault.jpg "2023年6月30日") ](https://www.youtube.com/watch?v=ERz60cmdq4c)

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [June 29, 2023, 5:51pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/8 "2023-06-29T17:51:58Z")

</div>

@konoe-akitoshi

> [@konoe-akitoshi](#):
>
> ran the sample, the motor seemed to shake.

You need to change the velocity and voltage targets until you get a smooth motion.

float target\_velocity = 2.0;  
float target\_voltage = 2.0;

Try modifying the velocity and voltage to probably:

float target\_velocity = 4.0;  
float target\_voltage = 4.0;

What is your power supply voltage?

Also, does the LED light up?

Please read this:

[https://community.simplefoc.com/t/gimbal-motor-overheating/1034/6](https://community.simplefoc.com/t/gimbal-motor-overheating/1034/6)

Cheers,  
Valentine

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [June 29, 2023, 5:56pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/9 "2023-06-29T17:56:15Z")

</div>

> [@konoe-akitoshi](#):
>
> ```auto
> float target_velocity = 4.0;
> float target_voltage = 4.0;
> 
> ```

Your motor is definitely spinning but the driver is tripping, so your code is working but your overcurrent protection is too sensitive.

Please increase or remove the overcurrent protection on the driver.

> [@konoe-akitoshi](#):
>
> BLDCMotor motor = BLDCMotor(14);

For open loop the number of pole pairs doesn’t matter. It will change the speed so please go back to

> [@konoe-akitoshi](#):
>
> BLDCMotor motor = BLDCMotor(1);

else you will get different speeds, your motor is trying to turn too fast because your pole pairs is incorrect. Also, your motor has 7 pole pairs, not 14.

For the close loop you must put

> [@konoe-akitoshi](#):
>
> BLDCMotor motor = BLDCMotor(7);

for the open loop you must up

> [@konoe-akitoshi](#):
>
> BLDCMotor motor = BLDCMotor(1);

The number of pole pairs = magnets / 2.

Cheers,  
Valentine

---

<div class="post-metadata">

### Author: ![konoe-akitoshi](https://community.simplefoc.com/user_avatar/community.simplefoc.com/konoe-akitoshi/32/5111_2.png) [@konoe-akitoshi](https://community.simplefoc.com/u/konoe-akitoshi)
#### Post date: [June 29, 2023, 6:29pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/10 "2023-06-29T18:29:09Z")

</div>

@Valentine Thank you for your advice.  
I guess I did not understand about the open loop…  
I tried it as you taught me.  
I changed it like this.

```auto
float target_velocity = 8.0;
float target_voltage = 8.0;

```

Is this behavior correct?

[![](https://img.youtube.com/vi/y5_FA3vR_nA/maxresdefault.jpg "2023年6月30日") ](https://www.youtube.com/watch?v=y5_FA3vR_nA)

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [June 29, 2023, 6:33pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/11 "2023-06-29T18:33:04Z")

</div>

@konoe-akitoshi

> [@konoe-akitoshi](#):
>
> I changed it like this.
> 
> ```auto
> float target_velocity = 8.0;
> float target_voltage = 8.0;
> 
> ```
> 
> Is this behavior correct?

I cannot see if the FAULT light up from the video, can you make another video where the whole driver board is visible? I want to see the LED.

Also, lower the voltage and speed to 4.

```auto
float target_velocity = 4.0;
float target_voltage = 4.0;

```

It seems we are making good progress, yes.

Cheers,  
Valentine

PS: Do you have an oscilloscope in your lab in Kyoto? It will help if you disconnect the motor, and only run the driver board without a motor and measure the output phases on the oscilloscope.

---

<div class="post-metadata">

### Author: ![konoe-akitoshi](https://community.simplefoc.com/user_avatar/community.simplefoc.com/konoe-akitoshi/32/5111_2.png) [@konoe-akitoshi](https://community.simplefoc.com/u/konoe-akitoshi)
#### Post date: [June 29, 2023, 6:42pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/12 "2023-06-29T18:42:24Z")

</div>

> [@Valentine](#):
>
> FAULT light

Thank you so much.  
I have modified and implemented the changes as you suggested.  
As for the FAULT light, it is subtle.  
It still seems to be there.  
It’s sad… 😢

[![](https://img.youtube.com/vi/A6h4QzHpsew/maxresdefault.jpg "2023年6月30日") ](https://www.youtube.com/watch?v=A6h4QzHpsew)

---

<div class="post-metadata">

### Author: ![konoe-akitoshi](https://community.simplefoc.com/user_avatar/community.simplefoc.com/konoe-akitoshi/32/5111_2.png) [@konoe-akitoshi](https://community.simplefoc.com/u/konoe-akitoshi)
#### Post date: [June 29, 2023, 6:51pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/13 "2023-06-29T18:51:03Z")

</div>

> [@Valentine](#):
>
> Do you have an oscilloscope in your lab in Kyoto? It will help if you disconnect the motor, and only run the driver board without a motor and measure the output phases on the oscilloscope.

I had forgotten about it.  
I recently purchased a handheld oscilloscope so I can measure it. It’s late today so I’ll measure it tomorrow. Thanks.

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [June 29, 2023, 6:52pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/14 "2023-06-29T18:52:12Z")

</div>

> [@konoe-akitoshi](#):
>
> As for the FAULT light, it is subtle.  
> It still seems to be there.  
> It’s sad… 😢

@konoe-akitoshi

Saeki San,

Please don’t be sad.

No worry you are making really good progress, you are almost there!

Lower the voltage and speed to

```auto
float target_velocity = 1.0;
float target_voltage = 1.0;

```

And let’s try again.

We will make it work, no worry. It’s really late there, may be you are tired and need some sleep.

Do you have an oscilloscope in your lab in Kyoto? It will help if you disconnect the motor, and only run the driver board without a motor and measure the output phases on the oscilloscope.

Cheers,  
Valentine

---

<div class="post-metadata">

### Author: ![konoe-akitoshi](https://community.simplefoc.com/user_avatar/community.simplefoc.com/konoe-akitoshi/32/5111_2.png) [@konoe-akitoshi](https://community.simplefoc.com/u/konoe-akitoshi)
#### Post date: [June 29, 2023, 7:02pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/15 "2023-06-29T19:02:58Z")

</div>

@Valentine Thanks for sticking with me for so long.  
When changed to 1.0, it tries to rotate, but it moves back and forth, and does not seem to rotate.  
[https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/13?u=konoe-akitoshi](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/13?u=konoe-akitoshi)  
I will try to work on it tomorrow.  
Thanks to you for making progress today.  
Thank you very much.

Akitoshi

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [June 29, 2023, 7:05pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/16 "2023-06-29T19:05:15Z")

</div>

> [@konoe-akitoshi](#):
>
> I will try to work on it tomorrow.  
> Thanks to you for making progress today.

Saeki San,

Sure, let’s continue tomorrow.

We also have a discord, where you can real-time ask questions, we can try discord to avoid posting so many messages here, and I can see real-time what you do to help you.

おやすみなさい

Cheers,  
Valentine

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [June 29, 2023, 7:08pm UTC](https://community.simplefoc.com/t/as5600-drv8302-sunnysky-v2806-shake/3523/17 "2023-06-29T19:08:06Z")

</div>

> [@konoe-akitoshi](#):
>
> work on it tomorrow

> [@Valentine](#):
>
> We also have a discord, where you can real-time ask questions

> **[Join the SimpleFOC Discord Server!](https://discord.com/invite/JbH772tfnB)**
>
> Check out the SimpleFOC community on Discord - hang out with 1107 other members and enjoy free voice and text chat.

Cheers,  
Valentine
