Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

learning to program uC32 which is PIC32 based Arduino compatible development board

Status
Not open for further replies.
"Before attempting to use the MPIDE to communicate with the uC32, the appropriate USB device driver must be installed." - Do I need to install the driver and where can I find it?

In my experience it does it all automatically, I've never had any driver issues.

As far as I'm aware MPIDE isn't needed any more?, the later Arduino IDE versions cover the chipKIT (and various others) - you just need to install the boards.
 
Hi,

I have a 11.1 v LiPo battery, L298N motor driver, two DC motors.

I found the following Arduino library for L298N. As I mentioned earlier that I have never worked with Arduino before, the code below doesn't make much sense to me.

info about motor controller: https://www.handsontec.com/dataspecs/L298N Motor Driver.pdf
Arduino library given below: https://www.arduinolibraries.info/libraries/l298-n

If I was working with some other compiler this is how I will proceed.

1: Set a PWM frequency for both motors, say 20 k Hz
2: Adjust the duty cycle for both motors individually in order to change speeds

Q1:
Perhaps, the library below does the same thing but how do I implement it from scratch, and do you think it'd be a good idea to implement it without using a library?

Q2:
I found a couple of other libraries for L298N in Arduino IDE as shown below; not sure if some other library is better than the one mentioned below in the code.

l298-gif.127084


Q3:
In the code below, there is this line " Serial.begin(9600)". I have seen such lines in some other sample codes as well, what's the purpose of this line? Is it used to display information?

C++:
/*
Author  : Andrea Lombardo
Site    : https://www.lombardoandrea.com
Source  : https://github.com/AndreaLombardo/L298N/

Here you can see how to work in a common configuration.

Speed range go from 0 to 255, default is 100.
Use setSpeed(speed) to change.

Sometimes at lower speed motors seems not running.
It's normal, may depends by motor and power supply.

Wiring schema in file "L298N - Schema_with_EN_pin.png"
*/

// Include the library
#include <L298N.h>

// Pin definition
const unsigned int IN1 = 7;
const unsigned int IN2 = 8;
const unsigned int EN = 9;

// Create one motor instance
L298N motor(EN, IN1, IN2);

void setup()
{
  // Used to display information
  Serial.begin(9600);

  // Wait for Serial Monitor to be opened
  while (!Serial)
  {
    //do nothing
  }

  // Set initial speed
  motor.setSpeed(70);
}

void loop()
{

  // Tell the motor to go forward (may depend by your wiring)
  motor.forward();

  // Alternative method:
  // motor.run(L298N::FORWARD);

  //print the motor satus in the serial monitor
  printSomeInfo();

  delay(3000);

  // Stop
  motor.stop();

  // Alternative method:
  // motor.run(L298N::STOP);

  printSomeInfo();

  // Change speed
  motor.setSpeed(255);

  delay(3000);

  // Tell the motor to go back (may depend by your wiring)
  motor.backward();

  // Alternative method:
  // motor.run(L298N::BACKWARD);

  printSomeInfo();

  motor.setSpeed(120);

  delay(3000);

  // Stop
  motor.stop();

  printSomeInfo();

  delay(3000);
}

/*
Print some informations in Serial Monitor
*/
void printSomeInfo()
{
  Serial.print("Motor is moving = ");
  Serial.print(motor.isMoving());
  Serial.print(" at speed = ");
  Serial.println(motor.getSpeed());
}
 

Attachments

  • l298.gif
    l298.gif
    5.1 MB · Views: 489
Be wary... Although the chipkit32 works in the Arduino environment.. Not all libraries will work... Be prepared to tweak the libraries if necessary ..

ie... Some programmers can be a tad lazy, I count myself in this category.. Some will use definitive registers within the code so they may not work outside the AVR family.. I would find a PIC32 library and call it from the Arduino IDE..
 
Be wary... Although the chipkit32 works in the Arduino environment.. Not all libraries will work... Be prepared to tweak the libraries if necessary ..

Agreed! I think some code lines work directly with specific registers of a microcontroller and this is what causes issues.

That's why I have a Arduino Uno clone with me as well. I have decided to test the first on Uno then migrate it to uC32.

If possible, please give my questions a look. Thanks,
 
Q1 and Q2 are as is.... These are answered... A library for the pic32 is needed..

Q3... Serialbegin() is always present because the Arduino IDE uses the same USB interface to serial debug...

To use serial debugging just throw someting into the serial port so it can be seen in the arduino serial debugging screen.

If you place serial out here and there, you can see your programs continuity..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top