DC motor on I2C Motor Driver(L298): PWM is 25Hz and can’t be changed

Hello Seraphina,
I was able to change the frequency with the help of the library:

and the Firmware source code . Is it really the last one for Grove - I2C Motor Driver (L298P)?

Here is a working example with no motor library(only wire used):

#include <Wire.h>

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Serial.println("-");
  delay(1000);
  Serial.println("default frequency start:200hz");

  //direction (no motor start without this)
  Wire.beginTransmission(0x0f);  // begin transmission
  Wire.write(0xaa);              // Direction control header
  Wire.write(0x0a);              // send direction control information BothClockWise=0x0a, BothAntiClockWise=0x05, M1CWM2ACW=0x06, M1ACWM2CW=0x09
  Wire.write(0x01);              // need to send this byte as the third byte(no meaning)
  Wire.endTransmission();

  //motor speed
  Wire.beginTransmission(0x0f);  // begin transmission
  Wire.write(0x82);              // set pwm header
  Wire.write(128);               // send speed of motor1 (full speed=255)
  Wire.write(128);               // send speed of motor2
  Wire.endTransmission();

  delay(10000);
  Serial.println("frequency: 255hz");
  //frequence
  Wire.beginTransmission(0x0f);  // begin transmission
  Wire.write(0x84);              // set frequence header
  Wire.write(255);              // send frequence
  Wire.write(0x01);              // need to send this byte as the third byte(no meaning)
  Wire.endTransmission();
  //frequency not changed yet: must set motor speed

  //motor speed
  Wire.beginTransmission(0x0f);  // begin transmission
  Wire.write(0x82);              // set pwm header
  Wire.write(128);               // send speed of motor1
  Wire.write(128);               // send speed of motor2
  Wire.endTransmission();
  //frequency changed
}

void loop() {
}

It is also possible to modify the library: edit and save the file Grove_I2C_Motor_Driver.cpp and comment line 122 & 123:

	if (_frequence < F_31372Hz || _frequence > F_30Hz) {
		//Serial.println("Not frequence error! Must be F_31372Hz, F_3921Hz, F_490Hz, F_122Hz, F_30Hz");
		//return;
	}

Then use this demo:

#include "Grove_I2C_Motor_Driver.h"
#define I2C_ADDRESS 0x0f

void setup() {
  Serial.begin(9600);
  Motor.begin(I2C_ADDRESS);
  Serial.println("run motors at default frequency=10hz");
  Motor.speed(MOTOR1, 50);
  Motor.speed(MOTOR2, 50);

  delay(2000);
  Serial.println("frequency change to 255hz");
  Motor.frequence(255);//not frequency change yet
  Motor.speed(MOTOR1, 50);//frequency change from now why:I don't know
  Motor.speed(MOTOR2, 50);
}

void loop() {
}
2 Likes