Hardware interface for Raspberry pi 4 GPio

I am using ROS 2 Humble on Raspberry Pi 4(Ubuntu 22.04 OS).

I am trying to build 2-wheeled diff-drive mobile robot and using ros2_control for controlling.

I am trying to control movement through Raspberry Pi GPIO pins using ros2_control. I have found many examples but with Raspberry Pi and Arduino serial connection not with only Raspberry Pi GPIO pins and L298N motor driver.

Here my setup (rpi4, l298n, 2 dc motors with attatched encoders)

I tried also to build a hardware interface using the wirringpi.h library , however I’m having an issue. When launching the launch file the on activate function does pop up an error saying “undefined symbol: wiringPiSetup”. Or PinMode

I used the demo example_2 given by ros2_control_demo.

Is it possible to do it with GPio without having any problem or do you suggest a serial communication is much better,?

Thank you in advance for any advice.

Hi @aitameuradlan2adcde5de6574041 ,

Firstly, I would like to tell you to get to know your electronics first.
L298N Motor Driver operates at input voltage 5V to 7V and output voltage 5V to 35 V.
Raspberry Pi (1/2/3/4/0) has GPIOs that operate at max 3.3V.

Only a RasPi + Arduino setup can enable a L298N motor driver. If you connect L298N directly to a RasPi - chances are you will kill your RasPi - not the motor driver.

You can try to use Logic converters to convert 3.3V to 5V, but that will not work for a connection with motor driver. It only works with low power 5V electronics like LED or Photodiode or some Transistors.

Instead of WiringPi, try some other library like PiGPIO.

Anyways, you CANNOT control L298N with just a RasPi. You need another board that uses 5V GPIOs.
Usually, RasPi+Arduino is the most favored combination.

And yes, serial communication from RasPi to Arduino is better for several reasons - just 2 data wires and 2 power wires - so not a lot of wires used. You can send a whole bunch of data within a 255 bytes string, if you properly format your data bytes. More like using a bytestring data as opposed to using “grammatically correct long English sentences”, that is, don’t send a string like “enable front left motor” through the serial interface just because it helps you understand what is going on.

I hope this helps.

Regards,
Girish

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.