trying to use l298n module in the bbai64

Hello! I’ve really tried everything but there doesn’t seem to be much documentation on how to change the p8 and p9 pin modes to use it for different purposes. What I would like to do is run a simple program that moves two motors for positioning through the l298n module, but I cannot call the corresponding pins. DOES ANYONE know of any python libraries? Or what should I do? I’m already out of ideas…

1 Like

Do you need only GPIO?


Do you need GPIO and PWM?

I once had some L298 drivers but some person, not naming names since I was not home, confiscated them for their own. Blah… I know, not your problem.

I think trying every way I tried may prove valuable.

So, with gpiod.h in C/C++, you could do something like:

// This is a C File for Promoting Movement via GPIO Pins on the BBAI-64

#include <gpiod.h>

// Most likely more files to recount like <stdio.h> and so on...



Here is some source I transferred from some older source into the current spec. if it is still around. It is hard to say what and when at times right now (at least from my perspective).

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define PWM_PERIOD 20000 
#define DUTY_MIN 1000
#define DUTY_MAX 2000

void writeToFile(const char* path, int value) {
        FILE* file = fopen(path, "w");
        if(file == NULL) {
                perror("Error opening file");
                printf("My integer is: %d\n", value);
        fprintf(file, "%d", value);
int main(){
        writeToFile("/dev/bone/pwm/1/a/enable", 1);
        writeToFile("/dev/bone/pwm/1/a/period", PWM_PERIOD);
                // Move the servo to the left (minimum position)
                writeToFile("/dev/bone/pwm/1/a/duty_cycle", DUTY_MIN);

                // Move the servo to the right (maximum position)
                writeToFile("/dev/bone/pwm/1/a/duty_cycle", DUTY_MAX);

                // Move the servo to the center position 
                writeToFile("/dev/bone/pwm/1/a/duty_cycle", (DUTY_MIN + DUTY_MAX) / 2);
        writeToFile("/dev/bone/pwm/1/a/enable", 0);

        return 0;

One could try to rehearse that into more legible source. I could probably have a go at it but…

  1. We would not show off the course of time with source and progress.
  2. I am a selfish person when it comes to working with others, e.g. I totally and only work with others.
  3. The Spec. may be a bit older than current.


P.S. Oh! Here is some GPIO source I ruffled up.

// for GPIO events...

#include <gpiod.h>
#include <stdio.h>
#include <unistd.h>

#ifndef	CONSUMER
#define	CONSUMER	"Consumer"

int main(int argc, char **argv)
	char *chipname = "gpiochip0";
	unsigned int line_num = 25;	// GPIO Pin #25
	struct timespec ts = { 1, 0 };
	struct gpiod_line_event event;
	struct gpiod_chip *chip;
	struct gpiod_line *line;
	int i, ret;

	chip = gpiod_chip_open_by_name(chipname);
	if (!chip) {
		perror("Open chip failed\n");
		ret = -1;
		goto end;

	line = gpiod_chip_get_line(chip, line_num);
	if (!line) {
		perror("Get line failed\n");
		ret = -1;
		goto close_chip;

	ret = gpiod_line_request_rising_edge_events(line, CONSUMER);
	if (ret < 0) {
		perror("Request event notification failed\n");
		ret = -1;
		goto release_line;

	/* Notify event up to 20 times */
	i = 0;
	while (i <= 20) {
		ret = gpiod_line_event_wait(line, &ts);
		if (ret < 0) {
			perror("Wait event notification failed\n");
			ret = -1;
			goto release_line;
		} else if (ret == 0) {
			printf("Wait event notification on line #%u timeout\n", line_num);

		ret = gpiod_line_event_read(line, &event);
		printf("Get event notification on line #%u %d times\n", line_num, i);
		if (ret < 0) {
			perror("Read last event notification failed\n");
			ret = -1;
			goto release_line;


	ret = 0;

	return ret;

I am not sure exactly where this source is derived from now. It has lack of notes…I am sorry.

But…when in doubt, test, retest, read, and proclaim satisfaction. That may not even be the updated versioning of the libgpiod-dev source that used to come on the BBB and/or BBAI-64. Installing it via a port is available but I have not done that in some time…

I think there were some repos and files I lost in some notes years ago about the prerequisites for the building of libgpiod-dev from git and/or kernel pages.

yep i want to use pwm and also gpio! i was trying to use it in a code with python… im gonna try with libgpiod

1 Like


1. There was a Motor Cape

  • This cape had two L298 drivers on it for motor movement and other two wire PWR/GND modules.
  • I would actually insult myself to see it come back!

2. Porting a L298 driver is not severely difficult but has it ups and downs…

  • I think making another Cape for motors would be beneficial for people like me who cannot get enough of motors (as most people will tell you).
  • Writing kernel drivers is out of my league because I am not practicing it right now.

3. Write the source and use the Specification

  • I think the spec. should have a space in the .org.
  • I want my GPIO and PWM powers back. It was so cool…

All for now…


I cannot give you a definite on yay or nay.

It really depends on your kernel and image…

You know already probably…

What is on it? Does it have the correct configuration and so on? Where are my files? Things like these ideas make or break me.

I am always hunting down fd and fd like builds.

well now i have and update, am trying to do an dts to change and use MUX_MODE for one of the pins that i want to change to use it like pwm… in this case im using the p9.14 in the mode 4 that is supposed to be pwm… in any case im not sure about every muxmode of every pin… there is no much information and im really new at this… im gonna try to make it and see what happen

1 Like

There are some recommended ways online on the pages under the spec. category and BBAI-64.

Also, I saw some DTS files already made that are available.

I could not get them to work for about five months. I have not tried recently.


P.S. In /boot/firmware/extlinux/extlinux.conf, try to add your overlay on the required line…


May or may not work, depending on image, kernel, and firmware… I am not too sure if they will keep the spec. as is or if it will change. Who knows? I will try again. Good luck!